import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class ClientTest1 {
public static void main(String[] args) {
try {
Service service = new Service();
String url="http://127.0.0.1:8080/webservice/testService.asmx";//提供接口的地址
String soapaction = "http://test.com/"; // 域名,这是在server定义的
try {
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(soapaction, "methodNmae")); //方法名称
call.addParameter(new QName(soapaction, "arg1"),//方法参数1名称
org.apache.axis.encoding.XMLType.XSD_STRING,//参数类型
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName(soapaction, "arg2"),//方法参数2名称
org.apache.axis.encoding.XMLType.XSD_STRING,//参数类型
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回值类型
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapaction + "GetGovWaredict");
String str = (String) call.invoke(new Object[] { "1","2" });//调用方法并传递参数
System.out.println("返回值:"+str);
} catch (Exception ex) {
ex.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
java调用.net服务例子
最新推荐文章于 2021-03-16 11:28:56 发布