AXIOM模式
public static String call() {
try {
String url = SvcInfo.Address;// 不是WSDL的URL
EndpointReference targetEPR = new EndpointReference(url);
ServiceClient serviceClient = new ServiceClient();
Options options = serviceClient.getOptions();
options.setTo(targetEPR);
OMFactory fac = OMAbstractFactory.getOMFactory();
// 指定命名空间,参数: uri--即为wsdl文档的targetNamespace,命名空间 perfix--可不填
OMNamespace omNs = fac.createOMNamespace(SvcInfo.NameSpace, "");
// 指定方法
OMElement method = fac.createOMElement(SvcInfo.OperateDesc, omNs);
// 参数
OMElement paraName = fac.createOMElement("name", omNs);
paraName.addChild(fac.createOMText(paraName, "BJ"));
method.addChild(paraName);
method.build();
// 远程调用web服务
// <ns:descResponse
// xmlns:ns="http://svc.jwt.com"><ns:return>首都-帝都</ns:return></ns:descResponse>
OMElement result = serviceClient.sendReceive(method);
OMElement ret = result.getFirstElement();//获取的是第一个子节点
return ret.getText();
} catch (AxisFault e) {
e.printStackTrace();
return "Fail";
}
}