以下演示在J2SE 1.4.2 版本下访问Web
Service 的2 种方式。
Axis
需要下载axis, 地址为:
http://apache.linuxforum.net/dist/ws/axis/1_1/axis-1_1-src.zip代码如下:
import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
public class t2 {
public static void main(String[] args) {
long time=System.currentTimeMillis();
try {
String endpoint="
http://localhost/UserX/biz.asmx";
Service service = new Service();
Call call = (Call)service.createCall();
8848.com Web Service 说明文档
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new
QName("
http://localhost/UserX/bizinfo","get_count"));
call.addParameter("ID", org.apache.axis.Constants.XSD_STRING,
ParameterMode.IN);
call.addParameter("pwd",org.apache.axis.Constants.XSD_STRING,
ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI("
http://localhost/UserX/bizinfo/get_count");
String day = (String)call.invoke(new Object[] {"111", "s111"});
System.out.println(day);
} catch (Exception e) {
System.err.println(e.toString());
}
System.out.println("Total time is: "+(System.currentTimeMillis()-time));
}
}