日期:2014-05-17 浏览次数:20689 次
String soapBindingAddress = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?WSDL";
ServiceClient sender = new ServiceClient();
EndpointReference endpointReference = new EndpointReference(
soapBindingAddress);
Options options = new Options();
options.setAction("http://WebXml.com.cn/getRegionProvince");
options.setTo(endpointReference);
sender.setOptions(options);
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/",
"getRegionProvince");
OMElement data = fac.createOMElement("getRegionProvince", omNs);
OMElement ele = sender.sendReceive(data);
System.out.println(ele.toString());
RPCServiceClient client = new RPCServiceClient();
Options options = client.getOptions();
EndpointReference target = new EndpointReference(
"http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?WSDL");
options.setTo(target);
options.setAction("http://WebXml.com.cn/getRegionProvince");
QName opName = new QName("http://WebXml.com.cn/", "getRegionProvince");
OMElement response = client.invokeBlocking(opName, new Object[] {});
System.out.println(response);
String url = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx";
String nameSpace = "http://WebXml.com.cn/";
String method = "getRegionProvince";
Service service = new Service();
Call call;
call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(url));
call.setOperationName(new QName(nameSpace, method));
call.setUseSOAPAction(true);
call.setSOAPActionURI(nameSpace + method);
call.setReturnClass(String[].class);
String[] res = (String[]) call.invoke(new Object[] { });
for (String string : res) {
System.out.println(string);
}