前段时间完成了一个小项目,给一个C/S消费系统写Webservice供调用.
由于客户方用的是Java开发业务系统.所以需要在接口说明文档里给出不同平台下的调用示例代码,供参考:
Java平台下调用示例代码
1
private final static String endpoint = "http://172.29.12.125:101/AxionPosService.asmx";
2
public static void main(String[] args) throws MalformedURLException,
3![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
ServiceException, RemoteException
{
4
Service service = new Service();
5
Call call = (Call) service.createCall();
6
call.setTargetEndpointAddress(new java.net.URL(endpoint));
7
call.setUseSOAPAction(true);
8
call.setSOAPActionURI("http://AxionPosService.net/QueryResidualAmount");
9
call.setOperationName(new QName("http://AxionPosService.net/","QueryResidualAmount"));
10
call.addParameter(new QName("http://AxionPosService.net/","account"), org.apache.axis.encoding.XMLType.XSD_STRING,ParameterMode.IN);
11
call.addParameter(new QName("http://AxionPosService.net/","orderNo"), org.apache.axis.encoding.XMLType.XSD_STRING,ParameterMode.IN);
12
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
13
//由于需要认证,故需要设置调用的用户名和密码。
14
SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("http://AxionPosService.net/", "AuthHeader");
15
soapHeaderElement.setNamespaceURI("http://AxionPosService.net/");
16
try
17![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
18
soapHeaderElement.addChildElement("IdentifyingCode").setValue("12345");
19
call.addHeader(soapHeaderElement);
20
}
21
catch (SOAPException e)
22![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
23
e.printStackTrace();
24
}
25
call.addHeader(soapHeaderElement);
26![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
String res = (String) call.invoke(new Object[]
{ "mike.wang", "10" });
27
}
28