wsdl
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class Test {
private static String endPoint="http://localhost:8080/WebServiceDemo/services/myService";
/**
* @param args
* @throws ServiceException
* @throws RemoteException
*/
public static void main(String[] args) throws ServiceException, RemoteException
{
Service service = new Service();
try {
//创建服务方法的调用者对象call,设置call对象的属性
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endPoint);//设置服务终端地址
QName opAddEntry = new QName("http://service", "sayHello");//设置NameSpace和方法
call.setOperationName(opAddEntry);//请求对象设置QName对象,这个英文应该是QuestionName
String result = (String) call.invoke(new Object[] {"RYL"});//请求对象注入返回结果参数
System.out.println("result is "+result);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
asmx:这个可蛋疼死我了,两个参数的搞了好久,一开始还以为是”A,B”这种格式,最后发现是再次addParameter
import java.util.List;
import java.util.Map;
import java.util.Vector;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class GetAdmOrgUnitByUpdateTime
{
private String url="http://xx.xxx.xx.xx:8055/WebService/AdmOrgUnitWSforHR.asmx";//提供接口的地址
private String soapaction="http://hr.xxxx.com/"; //域名,这是在server定义的
public GetAdmOrgUnitByUpdateTime()
{
Service service=new Service();
try{
Call call=(Call)service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(soapaction,"GetAdmOrgUnitByUpdateTime")); //设置要调用哪个方法
call.addParameter(new QName(soapaction,"BeginDate"), //设置要传递的参数
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName(soapaction,"EndDate"), //设置要传递的参数
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(new QName(soapaction,"GetAdmOrgUnitByUpdateTime"),Vector.class); //要返回的数据类型(自定义类型)
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//(标准的类型)
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapaction + "GetAdmOrgUnitByUpdateTime");
String v=(String)call.invoke(new Object[]{"2015-01-01","2016-03-02"});//调用方法并传递参数
System.out.println("result is "+v);
}catch(Exception ex)
{
ex.printStackTrace();
}
}
public static void main(String args[])
{
GetAdmOrgUnitByUpdateTime pw=new GetAdmOrgUnitByUpdateTime();
}
}