加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 22:42:15 所属栏目:安全 来源:网络整理
导读:服务端代码 [java] ? view plain copy @WebService ?? @SOAPBinding (style?=?SOAPBinding.Style.RPC)?? public ? class ?WebserviceServer?{?? ???? @WebMethod ?? ???? void ?doSomething()?{?? ????????System.out.println( "hello" );?? ????}?? ?? stat
服务端代码
[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. ????????}??

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读