package web.test;
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 Test3 {
public static void main(String[] args) {
String webServiceNameSpace="http://WebXml.com.cn/";
String endpoint = "http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL";
Service service=new Service();
try {
Call call=(Call) service.createCall();
call.setTimeout(new Integer(20000));
call.addParameter(new QName(webServiceNameSpace, "mobileCode"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter(new QName(webServiceNameSpace, "userID"), XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI(webServiceNameSpace+"getMobileCodeInfo");
Object[] object=new Object[]{"13652065489",""};
String result=(String) call.invoke(object);
System.out.println(result);
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
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 Test3 {
public static void main(String[] args) {
String webServiceNameSpace="http://WebXml.com.cn/";
String endpoint = "http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL";
Service service=new Service();
try {
Call call=(Call) service.createCall();
call.setTimeout(new Integer(20000));
call.setTargetEndpointAddress(endpoint);
//传入wsdl中的接口文件
call.setOperationName(new QName(webServiceNameSpace, "getMobileCodeInfo"));call.addParameter(new QName(webServiceNameSpace, "mobileCode"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter(new QName(webServiceNameSpace, "userID"), XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI(webServiceNameSpace+"getMobileCodeInfo");
Object[] object=new Object[]{"13652065489",""};
String result=(String) call.invoke(object);
System.out.println(result);
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
实测可用。
遇到的坑:
1:webServiceNameSpace中的数据写错成“http://WebXml.com.cn”,导致在incoke方法中找不到出入的值(或者说传入的值为空)。
深层原因可能是造成call.setSOAPActionURI(webServiceNameSpace+"getMobileCodeInfo")方法中参数值出错。纠结了半天总算是解决了。
附带jar:http://download.csdn.net/download/java_leo_f/10146577
只是菜鸟,不足之处,请大神指正。