日期:2014-05-17 浏览次数:20778 次
String endpointURL = "http://.../Service.asmx";
try
{
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpointURL));
call.setSOAPActionURI("http://tempuri.org/QueryData");
call.setOperationName(new QName("http://tempuri.org/", "QueryData"));
call.addParameter(new QName("http://tempuri.org/","xmlData"),XMLType.XSD_STRING, ParameterMode.IN);// 参数的类型
call.setReturnType(XMLType.XSD_STRING);// 返回的数据类型
SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("http://tempuri.org/", "AuthorizationSoapHeader");
soapHeaderElement.setNamespaceURI("http://tempuri.org/");
try
{
soapHeaderElement.addChildElement("UserName").setValue("username");
soapHeaderElement.addChildElement("Password").setValue("password");
}
catch (SOAPException e)
{
e.printStackTrace();
}
call.addHeader(soapHeaderElement);
call.setUseSOAPAction(true);
String ret = (String) call.invoke(new Object[]{new String("<root><parameters><serviceID>Q0203001</serviceID></parameters><root>".getBytes("UTF-8"), "GB2312")});// 执行调用
System.out.println(ret);
}
catch (Exception e)
{
e.printStackTrace();
}