当前位置: 代码迷 >> Java Web开发 >> CXF WEBserbice出错
  详细解决方案

CXF WEBserbice出错

热度:1114   发布时间:2016-04-13 22:12:27.0
CXF WEBserbice报错
---系统生成的wsdl文件
  <?xml version="1.0" encoding="UTF-8" ?> 
- <wsdl:definitions targetNamespace="http://test.webservice.com" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://test.webservice.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
- <wsdl:types>
- <schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://test.webservice.com" xmlns="http://www.w3.org/2001/XMLSchema">
- <element name="example" nillable="false">
- <complexType>
- <sequence>
  <element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="string" /> 
  </sequence>
  </complexType>
  </element>
- <element name="exampleResponse" nillable="false">
- <complexType>
- <sequence>
  <element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="string" /> 
  </sequence>
  </complexType>
  </element>
  </schema>
  </wsdl:types>
- <wsdl:message name="exampleResponse">
  <wsdl:part name="parameters" element="tns:exampleResponse" /> 
  </wsdl:message>
- <wsdl:message name="exampleRequest">
  <wsdl:part name="parameters" element="tns:example" /> 
  </wsdl:message>
- <wsdl:portType name="helloPortType">
- <wsdl:operation name="testHD">
  <wsdl:input name="exampleRequest" message="tns:exampleRequest" /> 
  <wsdl:output name="exampleResponse" message="tns:exampleResponse" /> 
  </wsdl:operation>
  </wsdl:portType>
- <wsdl:binding name="helloHttpBinding" type="tns:helloPortType">
  <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="testHD">
  <wsdlsoap:operation soapAction="" /> 
- <wsdl:input>
  <wsdlsoap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <wsdlsoap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="testHD_srv">
- <wsdl:port name="helloHttpPort" binding="tns:helloHttpBinding">
  <wsdlsoap:address location="http://localhost:8080/servicegate/entry/services/serviceTarget/call/testHD" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>
CXF调用方法
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
 
Client client = clientFactory.createClient("http://localhost:8080/servicegate/entry/services/serviceTarget/wsdl/testHD?wsdl");
// 下面一段处理 WebService接口和实现类namespace不同的情况   
// CXF动态客户端在处理此问题时,会报No operation was found with the name的异常   
Endpoint endpoint = client.getEndpoint();   
QName opName = new QName(endpoint.getService().getName().getNamespaceURI(),"example");   
BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();   
if (bindingInfo.getOperation(opName) == null) {   
    for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {   
        if ("example".equals(operationInfo.getName().getLocalPart())) {   
            opName = operationInfo.getName();   
            break;   
        }   
    }   
}   
Object[] res=null;
try {
res = client.invoke("example", "你好HELLO");
} catch (Exception e) {
System.out.println(e.getMessage());
}  

报错异常 求解决
2015-10-27 18:30:41 org.apache.cxf.common.jaxb.JAXBUtils logGeneratedClassNames
信息: Created classes: com.webservice.test.Example, com.webservice.test.ExampleResponse, com.webservice.test.ObjectFactory
Exception in thread "main" java.lang.NullPointerException
at testWebService.main(testWebService.java:64)
No operation was found with the name {http://test.webservice.com}example.

------解决思路----------------------
http://pangsir.iteye.com/blog/1492508,看看这帖子,或者你用:No operation was found with the name关键字百度搜索下,你这个不是大问题。
  相关解决方案