android中webservice接口,android 中简单搞定 webservice 接口访问,以及 webservice 简析...
我实例中使用的是getSupportCity方法以下代码是我直接从android studio上面拷贝的,第一次写这个,不太会搞。Stringnamespace="http://WebXml.com.cn/";StringtransUrl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";Stringmethod...
我实例中使用的是getSupportCity方法
以下代码是我直接从android studio上面拷贝的,第一次写这个,不太会搞。
String namespace ="http://WebXml.com.cn/";
String transUrl = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";
String method = "getSupportCity";
//注意版本使用,这个需要跟后台询问或者从wsdl文档或者服务说明中查看
intenvolopeVersion = SoapEnvelope.VER12;
//可能是namspace+method拼接
String soapAction = "http://WebXml.com.cn/getSupportCity";
SoapObject request = newSoapObject(namespace, method);
//参数一定注意要有序,尽管是addProperty(),不要当作HttpUrl可以使用LinkedHashMap封装
request.addProperty("byProvinceName","湖北");
// SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
SoapSerializationEnvelope envelope = newSoapSerializationEnvelope(envolopeVersion);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE se = newHttpTransportSE(transUrl);
try{
// se.call(soapAction, envelope); //ver11,第一个参数不能为空
se.call(null, envelope);//envolopeVersion为ver12第一个参数可以为空,必须接口支持ver12才行
SoapObject response = (SoapObject) envelope.bodyIn;
//response的处理需要根据返回的具体情况,基本都要进行下面一步
SoapObject o = (SoapObject) response.getProperty(0);
//当前方法返回的结果为一个数组
Log.e("zjy","MainActivity.java->run(): size="+ o.getPropertyCount());
for(inti =0; i
Log.e("zjy","MainActivity.java->run(): =="+ o.getPropertyAsString(i));
}
} catch(IOException e) {
e.printStackTrace();
} catch(XmlPullParserException e) {
e.printStackTrace();
}
String namespace = "http://WebXml.com.cn/";
String transUrl = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";
String method = "getSupportCity";
//注意版本使用,这个需要跟后台询问或者从wsdl文档或者服务说明中查看
int envolopeVersion = SoapEnvelope.VER12;
//可能是namspace+method拼接
String soapAction = "http://WebXml.com.cn/getSupportCity";
SoapObject request = new SoapObject(namespace, method);
//参数一定注意要有序,尽管是addProperty(),不要当作HttpUrl可以使用LinkedHashMap封装
request.addProperty("byProvinceName", "湖北");
// SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(envolopeVersion);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE se = new HttpTransportSE(transUrl);
try {
// se.call(soapAction, envelope); //ver11,第一个参数不能为空
se.call(null, envelope);//envolopeVersion为ver12第一个参数可以为空,必须接口支持ver12才行
SoapObject response = (SoapObject) envelope.bodyIn;
//response的处理需要根据返回的具体情况,基本都要进行下面一步
SoapObject o = (SoapObject) response.getProperty(0);
//当前方法返回的结果为一个数组
Log.e("zjy", "MainActivity.java->run(): size=" + o.getPropertyCount());
for (int i = 0; i < o.getPropertyCount(); i++) {
Log.e("zjy", "MainActivity.java->run(): ==" + o.getPropertyAsString(i));
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
更多推荐
所有评论(0)