求问如何调用web service
小白问问题:
知道webservice地址 http://XXX/axis2/XXX.jws?wsdl
方法名:send
<part name="userName" type="xsd:string"/> XXX
<part name="password" type="xsd:string"/> XXX
<part name="srcid" type="xsd:string"/> XXX
<part name="msg" type="xsd:string"/> XXX
<part name="phone" type="xsd:string"/> XXX
用eclispe生成了webservice client,求问怎么调用?
------解决方案--------------------在生成 的 webServiceClient 中,找一个*Client.java 的文件
IUsersClient client = new IUsersClient();
//create a default service endpoint
IUsersPortType service = client.getIUsersHttpPort();
Client client2 = ((XFireProxy)Proxy.getInvocationHandler(service)).getClient();
client2.addOutHandler(new DOMOutHandler());
Properties properties = new Properties();
properties.setProperty(WSHandlerConstants.ACTION,WSHandlerConstants.USERNAME_TOKEN);
properties.setProperty(WSHandlerConstants.USER, "liangmin");
properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordCallback.class.getName());
client2.addOutHandler(new WSS4JOutHandler(properties));
//TODO: Add custom client code here
//
//service.yourServiceOperationHere();
System.out.println(service.example("梁敏"));
System.out.println("test client completed");
System.exit(0);
这是我的代码,你看看能明白不
------解决方案--------------------要看你是用哪种协议生成的代码,Axis2生成的类里面,有一个***SoapBindingStub和****ServiceLocator结尾的类,像下面这样调用:
URL url = new URL("http://192.168.1.1:8080/services/UserRingManage");
UserRingManage
SoapBindingStub binding = (UserRingManage
SoapBindingStub) new UserRingManage
ServiceLocator()
.getUserRingManage(url);
binding.setTimeout(60000);
Response res = binding.buyTone("param");--buyTone是你要调用的方法;