本文章来源于https://blog.csdn.net/rao1212125/article/details/70143292?locationNum=8&fps=1,如有不当之处,请告知,立即删除!
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();
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
asmx:
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();
}
}