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文件内容






- - -    -   -   - -     -  -  -   -     - -    



客户端调用代码

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();
		}


你可能感兴趣的:(java,webservice,jws,axis)