- 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" });
- }
- }
Java调用带SoapHeader头验证的.net Webservice示例代码
最新推荐文章于 2024-07-09 20:05:23 发布