分类: 嵌入式
2011-10-15 11:17:42
页面中有以下信息:
======================================================
getWeather
获得天气预报数据
输入参数:城市/地区ID或名称,返回数据:一维字符串数组
=====================================================
点击getWeather
从上述页面可以获取以下信息:
SOAPAction: ""
其中xmlns就是NAMESPACE值
以及传送参数名theCityCode
在Action类的onCreate方法中实现连接webservice功能
下载地址:
点击View raw file 下载
然后在项目中加入第三方包
// 名空间
private static final String NAMESPACE = "";
// 网址
private static String URL = "";
// 方法名
private static final String METHOD_NAME = "getWeather";
// SOAPACTION
private static String SOAP_ACTION = "";
SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME);
rpc.addProperty("theCityCode", cityName);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject(rpc);
其中SoapEnvelope.VER11是指SOAP 1.1,
HttpTransportSE ht = new HttpTransportSE(URL);
ht.debug = true;
ht.call(SOAP_ACTION, envelope);
方法一:
detail =(SoapObject) envelope.getResponse();
方法二:
SoapObject result = (SoapObject)envelope.bodyIn;
detail = (SoapObject) result.getProperty("getWeatherbyCityNameResult");
for (int i = 0; i < detail.getPropertyCount(); i++) {
System.out.println("detail.getProperty(" + i + ")" + detail.getProperty(i));
}
在AndroidManifest.xml 文件中加入uses-permission项,如下:
…
...
…
在eclipse中,窗口—》显示视图—》其他—》android—》LogCat