CXF WEBserbice报错

对java有感觉 2015-10-27 06:32:18
---系统生成的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.
...全文
143 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
64行是什么
渭水飞熊 2015-10-28
  • 打赏
  • 举报
回复
http://pangsir.iteye.com/blog/1492508,看看这帖子,或者你用:No operation was found with the name关键字百度搜索下,你这个不是大问题。
今天的角色00 2015-10-28
  • 打赏
  • 举报
回复
你的portType是helloPortType··方法是testHD啊···
心随自在飞 2015-10-28
  • 打赏
  • 举报
回复
引用 2 楼 cs123456789dn 的回复:
[quote=引用 1 楼 shijing266 的回复:] at testWebService.main(testWebService.java:64) NullPointerException 看下64行 另:你的名字我很喜欢
先不管名字啊 。现在就不知道怎么报错啊[/quote] 把这部分代码贴出来啊!
对java有感觉 2015-10-27
  • 打赏
  • 举报
回复
引用 1 楼 shijing266 的回复:
at testWebService.main(testWebService.java:64) NullPointerException 看下64行 另:你的名字我很喜欢
先不管名字啊 。现在就不知道怎么报错啊
  • 打赏
  • 举报
回复
at testWebService.main(testWebService.java:64) NullPointerException 看下64行 另:你的名字我很喜欢

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧