1.下载axis-bin-1_4.zip、axis2-1.5.5-bin.zip。
2.新建java project,然后在java build path 的libraries中add external jars,将axis-bin-1_4与axis2-1.5.5-bin解压缩后的lib目录中的jar添加进项目
3.编码调用webservice
import java.lang.reflect.Array;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
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.axiom.soap.soAP11Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
private static EndpointReference targetEPR = new EndpointReference("http://www.test.com:967/Test.asmx?WSDL");//接口WebService地址
try{
OMFactory fac = OMAbstractFactory.getoMFactory();
OMNamespace omNs = fac.createOMNamespace("http://www.testnamespace.net/","tns");//命名空间
OMElement method = fac.createOMElement("methodname",omNs);//方法名称
//请求参数设置
Options options = new Options();
options.setTo(targetEPR);//设定webservice地址
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);//设定传输协议
options.setSoapVersionURI(SOAP12Constants.soAP_ENVELOPE_NAMESPACE_URI);//设定SOAP版本soap1.2
//客户端绑定参数设置
ServiceClient sender = new ServiceClient();
sender.setoptions(options);
//设定访问的接口方法
OMElement method2 = fac.createOMElement("calledmethodname",omNs);//要调用的接口方法名称
OMElement value1 = fac.createOMElement("Enterargument",omNs);//方法的第一个参数名称
value1.addChild(fac.createOMText(value1,"参数值1"));//设定参数的值
method2.addChild(value1);//方法设置参数//设定其他方法参数,针对参数是数组的情况如何处理?可以考虑为参数添加child,
//............
OMElement result2 = sender.sendReceive(method2);//调用接口方法
System.out.println(result2);//打印接口返回结果//处理result2
}
catch (Exception e) { e.printstacktrace(); }版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。