伴车星webservice调用例子

目前使用的是axis作为webservice客户端调用工具。以下是测试例子代码,代码例子都比较简单

package com;
  
import javax.xml.namespace.QName;  
  
import org.apache.axis.client.Call;  
import org.apache.axis.client.Service;  
import org.apache.axis.encoding.XMLType;
import org.apache.axis.message.MessageElement;
import org.apache.axis.types.Schema;
  
public class PutWeather   
{  
     private String url="http://apiweb.dkwgps.com/SNService.asmx ";//提供接口的地址  
     private String soapaction="http://tempuri.org/";   //域名,这是在server定义的  
      
     public PutWeather()  
     {           
         Service service=new Service();  
         try{  
             Call call=(Call)service.createCall();              
             call.setTargetEndpointAddress(url);              
             call.setOperationName(new QName(soapaction,"InfobySN")); //设置要调用哪个方法  
             call.addParameter(new QName(soapaction,"IMEI"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);   //设置要传递的参数  
             call.addParameter(new QName(soapaction,"Key"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);   //设置要传递的参数   
             String [] str = {"391215072347926","dd"};  //设置要传递的参数值
             call.setReturnType(XMLType.XSD_SCHEMA);//(标准的类型)  
             call.setUseSOAPAction(true);  
             call.setSOAPActionURI(soapaction + "InfobySN");      
                          
             Object o = call.invoke(str);//调用方法并传递参数          
             Schema schema = (Schema) o;  //获取schema
             MessageElement[] messageElements = schema.get_any();  
             StringBuffer str2 = new StringBuffer("");  
             for (MessageElement m : messageElements) {  
                 str2.append(m.toString());  
             }              
             System.out.println(str2);
         }catch(Exception ex)  
         {  
         ex.printStackTrace();  
         }          
     }  
      
     public static void main(String args[])  
     {  
         PutWeather pw=new PutWeather();  
     }  
}


你可能感兴趣的:(webservice)