java soapheader验证_Java调用带SoapHeader头验证的.net Webservice示例代码 | 学步园
private final static String endpoint = "http://172.29.12.125:101/AxionPosService.asmx";public static void main(String[] args) throws MalformedURLException,ServiceException, RemoteException {Service se
private final static String endpoint = "http://172.29.12.125:101/AxionPosService.asmx";
public static void main(String[] args) throws MalformedURLException,
ServiceException, RemoteException {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://AxionPosService.net/QueryResidualAmount");
call.setOperationName(new QName("http://AxionPosService.net/","QueryResidualAmount"));
call.addParameter(new QName("http://AxionPosService.net/","account"), org.apache.axis.encoding.XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName("http://AxionPosService.net/","orderNo"), org.apache.axis.encoding.XMLType.XSD_STRING,ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
//由于需要认证,故需要设置调用的用户名和密码。
SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("http://AxionPosService.net/", "AuthHeader");
soapHeaderElement.setNamespaceURI("http://AxionPosService.net/");
try{
soapHeaderElement.addChildElement("IdentifyingCode").setValue("12345");
call.addHeader(soapHeaderElement);
}catch (SOAPException e) {
e.printStackTrace();
}
call.addHeader(soapHeaderElement);
String res = (String) call.invoke(new Object[] { "mike.wang", "10" });
}
}
更多推荐
所有评论(0)