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

服务端代码
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class WebserviceServer {
	@WebMethod
	public void doSomething() {
		System.out.println("hello");
	}

	public static void main(String[] args) {
		WebserviceServer server = new WebserviceServer();
		Endpoint.publish("http://172.16.160.67:8888/login", server);
	}
}


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

<?xml version="1.0" encoding="UTF-8"?>

<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. -->

<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. -->
-<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>



客户端调用代码

String endPoint = "http://172.16.160.67:8888/login";
		Service service = new Service();
		try {
			Call call = (Call) service.createCall();
			call.setTargetEndpointAddress(new URL(endPoint));
			call.setOperation("doSomething");
			call.invoke(new Object[] {});
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (AxisFault e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}

调用时出现的了错误:
AxisFault 
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client 
 faultSubcode: 
 faultString: Cannot find dispatch method for {}doSomething
 faultActor: 
 faultNode: 
 faultDetail: 
   {http://xml.apache.org/axis/}stackTrace:Cannot find dispatch method for {}doSomething

原因:

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



修改方法:

修改客户端调用代码

String endPoint = "http://172.16.160.67:8888/login";
		Service service = new Service();
		try {
			Call call = (Call) service.createCall();
			call.setTargetEndpointAddress(new URL(endPoint));
			call.setOperationName(new QName("http://test.kedacom.com/", "doSomething"));
			call.invoke(new Object[] {});
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (AxisFault e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值