伴車星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();
}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章