微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.     void doSomething() {  
  6.         System.out.println("hello");  
  7.     }  
  8.   
  9. 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] 

派生到我的代码片

    <?xml version="1.0" encoding="UTF-8"?>  
  1. <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. -->  
  2. <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. -->  
  3. -<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"> -typesxsd:schema> xsd:import schemaLocation="http://172.16.160.67:8888/login?xsd=1" namespace="http://test.kedacom.com/"/> </message name="doSomething"part name="parameters" element="tns:doSomething"messagemessage name="doSomethingResponse"part name="parameters" element="tns:doSomethingResponse"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"operationportTypebinding name="WebserviceServerPortBinding" type="tns:WebserviceServer"soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> -soap:operation soapAction=""inputsoap:body use="literal"outputbindingservice name="WebserviceServerService"port name="WebserviceServerPort" binding="tns:WebserviceServerPortBinding"soap:address location="http://172.16.160.67:8888/login"portservicedeFinitions>  


客户端调用代码

派生到我的代码片

    String endPoint = "http://172.16.160.67:8888/login";  
  1.         Service service = new Service();  
  2.         try {  
  3.             Call call = (Call) service.createCall();  
  4.             call.setTargetEndpointAddress(new URL(endPoint));  
  5.             call.setoperation("doSomething");  
  6.             call.invoke(new Object[] {});  
  7.         } catch (ServiceException e) {  
  8.             e.printstacktrace();  
  9. catch (AxisFault e) {  
  10. catch (remoteexception e) {  
  11. catch (MalformedURLException e) {  
  12.         }  

调用时出现的了错误

派生到我的代码片

    AxisFault   
  1.  faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client   
  2.  faultSubcode:   
  3.  faultString: Cannot find dispatch method for {}doSomething  
  4.  faultActor:   
  5.  faultNode:   
  6.  faultDetail:   
  7.    {http://xml.apache.org/axis/}stackTrace:Cannot find dispatch method for {}doSomething  

原因:

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



修改方法

修改客户端调用代码

派生到我的代码片

                call.setoperationName(new QName("http://test.kedacom.com/""doSomething"));  
  1.         }  

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐