package util;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import java.rmi.RemoteException;
import java.util.Iterator;
public class webServiceTest
{
public static String test() throws AxisFault {
//在.NET接口中打开asmx相关的cs文件,代码最上边会有[WebService(Namespace = "http://tempuri.org/")]字样
//不知道命名空间的的,在此资料中有个“命名空间.png”图片,可以看下
try {
String url = "http://xxxx.com/xxx.asmx?WSDL";//接口地址
Options options = new Options();
EndpointReference targetEPR = new EndpointReference(url);
options.setTo(targetEPR);
options.setAction("http://tempuri.org/Add");//命名空间+方法名
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
OMFactory fac = OMAbstractFactory.getOMFactory();
String tns = "http://tempuri.org/";//命名空间
OMNamespace omNs = fac.createOMNamespace(tns, "");
OMElement method = fac.createOMElement("Add", omNs);//Add为方法名
OMElement symbol = fac.createOMElement("qqortel", omNs);//参数名称,如接口上面方法Add(String qqortel),我这里写的和上面一至,没测试不一样是什么结果
symbol.addChild(fac.createOMText(symbol, "13081545944"));//参数值
method.addChild(symbol);
method.build();
OMElement result = sender.sendReceive(method);
return result.toString();
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}
return "ERROR";
}
}