前段时间完成了一个小项目,给一个C/S消费系统写Webservice供调用.
由于客户方用的是Java开发业务系统.所以需要在接口说明文档里给出不同平台下的调用示例代码,供参考:

 Java平台下调用示例代码
Java平台下调用示例代码
 1 private final static String endpoint = "http://172.29.12.125:101/AxionPosService.asmx";
private final static String endpoint = "http://172.29.12.125:101/AxionPosService.asmx";
 2 public static void main(String[] args) throws MalformedURLException,
    public static void main(String[] args) throws MalformedURLException,
 3
 ServiceException, RemoteException
            ServiceException, RemoteException  {
{
 4 Service service = new Service();
            Service service = new Service();
 5 Call call = (Call) service.createCall();
            Call call = (Call) service.createCall();
 6 call.setTargetEndpointAddress(new java.net.URL(endpoint));
            call.setTargetEndpointAddress(new java.net.URL(endpoint));
 7 call.setUseSOAPAction(true);
            call.setUseSOAPAction(true);
 8 call.setSOAPActionURI("http://AxionPosService.net/QueryResidualAmount");
            call.setSOAPActionURI("http://AxionPosService.net/QueryResidualAmount");
 9 call.setOperationName(new QName("http://AxionPosService.net/","QueryResidualAmount"));
            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);
            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);
            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);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
13 //由于需要认证,故需要设置调用的用户名和密码。
            //由于需要认证,故需要设置调用的用户名和密码。  
14 SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("http://AxionPosService.net/", "AuthHeader");
            SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("http://AxionPosService.net/", "AuthHeader");   
15 soapHeaderElement.setNamespaceURI("http://AxionPosService.net/");
            soapHeaderElement.setNamespaceURI("http://AxionPosService.net/");   
16 try
            try  
17
 
             {
{   
18 soapHeaderElement.addChildElement("IdentifyingCode").setValue("12345");
                soapHeaderElement.addChildElement("IdentifyingCode").setValue("12345");   
19 call.addHeader(soapHeaderElement);
                call.addHeader(soapHeaderElement);
20 }
            }   
21 catch (SOAPException e)
            catch (SOAPException e)   
22
 
             {
{   
23 e.printStackTrace();
                e.printStackTrace();   
24 }
            }   
25 call.addHeader(soapHeaderElement);
            call.addHeader(soapHeaderElement);  
26
 String res = (String) call.invoke(new Object[]
        String res = (String) call.invoke(new Object[]  { "mike.wang", "10" });
{ "mike.wang", "10" });
27 }
    }
28