public class TestClient{
public static void main(String[] args) throws AxisFault{
execute();
}
public static void execute() throws AxisFault {
String url = "http://127.0.0.1:8080/projectName/services/webService";
String ns = "http://service.soft.cn";
String methodName = "webserviceMethod";
String paramValue = "d:/ftpdata";
//指定调用WebService的URL
EndpointReference targetEPR = new EndpointReference(url);
Options opt = new Options();
opt.setTo(targetEPR);
opt.setAction("urn:getFileByWebService");
//命名空间
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace(ns, methodName);
//方法
OMElement method = fac.createOMElement(methodName, omNs);
OMElement param = fac.createOMElement("paramName", omNs);
OMText param_value = fac.createOMText(param, paramValue);
param.addChild(param_value);
method.addChild(param);
method.build();
//发送请求
ServiceClient sender = new ServiceClient();
sender.setOptions(opt);
OMElement result = sender.sendReceive(method);
System.out.println("result = " + result);
Iterator iter = result.getChildElements();
while(iter.hasNext()){
String str = ((Element)iter.next()).getText();
System.out.println("str = " + str);
}
}
}
Axis2 WebService Client
最新推荐文章于 2021-12-31 14:39:54 发布