参考:Andorid调用WebService详解
http://blog.youkuaiyun.com/lyq8479/article/details/6428288
代码如下:
private String getHolidayType() {
// 命名空间
String nameSpace = "http://tempuri.org/";
// 调用的方法名称
String methodName = "GetHolidayTypes";
// EndPoint
String endPoint = "http://192.168.123.7:8900/holiday.asmx";
// SOAP Action
String soapAction = "http://tempuri.org/GetHolidayTypes";
// 指定WebService的命名空间和调用的方法名
SoapObject rpc = new SoapObject(nameSpace, methodName);
// 设置需调用WebService接口需要传入的参数
// rpc.addProperty("xml", xml);
// 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.bodyOut = rpc;
// 设置是否调用的是dotNet开发的WebService
envelope.dotNet = true;
// 等价于envelope.bodyOut = rpc;
envelope.setOutputSoapObject(rpc);
HttpTransportSE transport = new HttpTransportSE(endPoint);
try {
// 调用WebService
transport.call(soapAction, envelope);
} catch (Exception e) {
e.printStackTrace();
}
// 获取返回的数据
SoapObject object = (SoapObject) envelope.bodyIn;
// 获取返回的结果
String xml = object.getProperty(0).toString();
return xml;
}
本文介绍了一个具体的Android应用程序如何调用WebService的方法。通过示例代码详细展示了如何设置命名空间、方法名称、SOAPAction以及EndPoint,并解释了如何创建SOAP请求、设置参数、调用WebService以及解析返回的数据。

2万+

被折叠的 条评论
为什么被折叠?



