Webservice调用方式:axis,soap详解
调用webservice,可以首先根据wsdl文件生成客户端,或者直接根据地址调用,下面讨论直接调用地址的两种不同方式:axis和Soap,soap方式主要是用在websphere下
axis全称Apache Extensible Interaction System 即阿帕奇可扩展交互系统。Axis本质上就是一个SOAP引擎,提供创建服务器端、客户端和网关SOAP操作的基本框架。Axis目前版本是为Java编写的,不过为C++的版本正在开发中。但Axis并不完全是一个SOAP引擎,它还是一个独立的SOAP服务器和一个嵌入Servlet引擎(例如Tomcat)的服务器。(详细请查阅资料)
axis方式调用:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class caClient {
public static void main(String[] args) {
try {
String endpoint = "http://localhost:8080/ca3/services/caSynrochnized?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName("addUser");
call.addParameter("userName", org.apache.axis.encoding.XMLType.XSD_DATE,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.my.com/Rpc");
String temp = "测试人员";
String result = (String)call.invoke(new Object[]{temp});
System.out.println("result is "+result);
} catch (Exception e) {
//TODO 异常处理
System.err.println(e.toString());
}
}
}
soap方式调用:
后期补上