AXIS调用jws发布的webservice出现Cannot find dispatch method for

服务端代码
[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. @WebService  
  2. @SOAPBinding(style = SOAPBinding.Style.RPC)  
  3. public class WebserviceServer {  
  4.     @WebMethod  
  5.     public void doSomething() {  
  6.         System.out.println("hello");  
  7.     }  
  8.   
  9.     public static void main(String[] args) {  
  10.         WebserviceServer server = new WebserviceServer();  
  11.         Endpoint.publish("http://172.16.160.67:8888/login", server);  
  12.     }  
  13. }  


服务端发布成功时的wsdl文件内容

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. -->  
  4.   
  5. <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. -->  
  6. -<definitions name="WebserviceServerService" targetNamespace="http://test.kedacom.com/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://test.kedacom.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> -<types> -<xsd:schema> <xsd:import schemaLocation="http://172.16.160.67:8888/login?xsd=1" namespace="http://test.kedacom.com/"/> </xsd:schema> </types> -<message name="doSomething"> <part name="parameters" element="tns:doSomething"/> </message> -<message name="doSomethingResponse"> <part name="parameters" element="tns:doSomethingResponse"/> </message> -<portType name="WebserviceServer"> -<operation name="doSomething"> <input message="tns:doSomething" wsam:Action="http://test.kedacom.com/WebserviceServer/doSomethingRequest"/> <output message="tns:doSomethingResponse" wsam:Action="http://test.kedacom.com/WebserviceServer/doSomethingResponse"/> </operation> </portType> -<binding name="WebserviceServerPortBinding" type="tns:WebserviceServer"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> -<operation name="doSomething"> <soap:operation soapAction=""/> -<input> <soap:body use="literal"/> </input> -<output> <soap:body use="literal"/> </output> </operation> </binding> -<service name="WebserviceServerService"> -<port name="WebserviceServerPort" binding="tns:WebserviceServerPortBinding"> <soap:address location="http://172.16.160.67:8888/login"/> </port> </service> </definitions>  



客户端调用代码

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. String endPoint = "http://172.16.160.67:8888/login";  
  2.         Service service = new Service();  
  3.         try {  
  4.             Call call = (Call) service.createCall();  
  5.             call.setTargetEndpointAddress(new URL(endPoint));  
  6.             call.setOperation("doSomething");  
  7.             call.invoke(new Object[] {});  
  8.         } catch (ServiceException e) {  
  9.             e.printStackTrace();  
  10.         } catch (AxisFault e) {  
  11.             e.printStackTrace();  
  12.         } catch (RemoteException e) {  
  13.             e.printStackTrace();  
  14.         } catch (MalformedURLException e) {  
  15.             e.printStackTrace();  
  16.         }  

调用时出现的了错误:
[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. AxisFault   
  2.  faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client   
  3.  faultSubcode:   
  4.  faultString: Cannot find dispatch method for {}doSomething  
  5.  faultActor:   
  6.  faultNode:   
  7.  faultDetail:   
  8.    {http://xml.apache.org/axis/}stackTrace:Cannot find dispatch method for {}doSomething  

原因:

可以通过wsdl文件看到,利用jws发布时,namespace="http://test.kedacom.com/",而在客户端访问时没有指定命名空间。



修改方法:

修改客户端调用代码

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. String endPoint = "http://172.16.160.67:8888/login";  
  2.         Service service = new Service();  
  3.         try {  
  4.             Call call = (Call) service.createCall();  
  5.             call.setTargetEndpointAddress(new URL(endPoint));  
  6.             call.setOperationName(new QName("http://test.kedacom.com/""doSomething"));  
  7.             call.invoke(new Object[] {});  
  8.         } catch (ServiceException e) {  
  9.             e.printStackTrace();  
  10.         } catch (AxisFault e) {  
  11.             e.printStackTrace();  
  12.         } catch (RemoteException e) {  
  13.             e.printStackTrace();  
  14.         } catch (MalformedURLException e) {  
  15.             e.printStackTrace();  
  16.         }  
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值