使用axis调用
1.所需jra
2.Java代码
import javax.xml.namespace.QName;
import org.apache.axis.Constants;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class One {
public static void main(String[] args) {
Textaxis();
}
//通过axis方式调用webservice接口
public static void Textaxis() {
try {
// 指出service所在完整的URL
String endpoint = "http://xxx/WebService1.asmx";
//调用接口的targetNamespace
//targetNamespace 就是你用浏览器打开endpoint 路径加上?wsdl,即http://xxx/WebService1.asmx?wsdl 中的targetNamespace属性值
String targetNamespace = "http://tempuri.org/";
//所调用接口的方法method
String method = "PostImsPartymemberManagement";
// 创建一个服务(service)调用(call)
Service service = new Service();
Call call = (Call) service.createCall();// 通过service创建call对象
// 设置service所在URL
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName(targetNamespace, method));
call.setUseSOAPAction(true);
//变量最好只是用String类型,其他类型会报错
call.addParameter(new QName(targetNamespace, "Cid"),
Constants.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);//设置参数名 state 第二个参数表示String类型,第三个参数表示入参
call.setReturnType(Constants.XSD_STRING);// 设置返回类型
String jsonString = (String) call.invoke(new Object[] {"225552222"});//此处为数组,有几个变量传几个变量
System.out.println(jsonString);
} catch (Exception e) {
System.err.println(e.toString());
//e.printStackTrace();
}
}
3.注意:请确认.NET的WebService类(即.asmx文件下的类)是否有
[SoapDocumentService(RoutingStyle=SoapServiceRoutingStyle.RequestElement)]属性值,没有需要添加