JAVA 用axis1 调用.NET的web service

时间:2021-07-13 21:12:38

1.去官网下载axis的jar包,我下的是1.4版本的

http://axis.apache.org/axis/java/releases.html

2.JAVA 代码:

public void myWebService() throws Exception {
Service service = new Service();
Call call = null;
try {
call = (Call) service.createCall();
//http://10.107.56.11/test/wsValidateAccount.asmx 是Web Service的URL地址
call.setTargetEndpointAddress(new URL("http://10.107.56.11/test/wsValidateAccount.asmx"));
//http://tempuri.org/ 是Web Service的命名空间,validate 是函数名,下面类同
call.setOperationName(new QName("http://tempuri.org/","validate"));
//添加参数,account是函数的参数名
call.addParameter(new QName("http://tempuri.org/","account"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

//添加参数,pwd是函数的参数名
call.addParameter(new QName("http://tempuri.org/","pwd"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); //设置函数返回类型
       call.setReturnType(org.apache.axis.encoding.XMLType.XSD_BOOLEAN);
       call.setUseSOAPAction(true);
        call.setSOAPActionURI("http://tempuri.org/validate"); 

//给WebService的函数传参
       System.out.println(call.invoke(new Object[]{"数值","数值"}));
}
catch (Exception e)
{ e.printStackTrace(); }
}