java+axis客户端调用.net服务端webservice

package com.aic.client;


import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;


import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;


public class HelloClientDotNet {


public String userValid(String username, String pwd){
//String url="http://XXX.com/Svc.asmx"; //
String url="http://XXX.com/Service1.asmx";
String namespace = "http://tempuri.org/";
String methodName = "CheckUserPasswd";
String soapActionURI = "http://tempuri.org/CheckUserPasswd";
Service service = new Service();
Call call = null;
try {
call = (Call) service.createCall();
} catch (ServiceException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
call.setTargetEndpointAddress(new java.net.URL(url));
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
call.setUseSOAPAction(true);
//这个地方没设对就会出现Server was unable to read request的错误
call.setSOAPActionURI(soapActionURI);
call.setOperationName(new QName(namespace, methodName));
/*这里如果设置成call.addParameter(new QName(namespace,"s"), XMLType.XSD_STRING,
ParameterMode.IN);就是调用document风格的.net服务端
如果设反了,.net服务端就接不到参数,接到的是null
*/
call.addParameter("username", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("passwd", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_INT);
Integer ret = new Integer(99);
try {
ret = (Integer)call.invoke(new Object[] { username, pwd });
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println("返回结果---> " + ret);
return null;

}

public static void main(String[] args) {
String result = new HelloClientDotNet().userValid("test", "111");//测试报备 177104204123224
System.out.println(result);
}
}

你可能感兴趣的:(webservice)