android访问.net发布的webservcie返回的List
android部分代码:
public List<String> WebList()
{
List<String> Lists = new ArrayList<String>();
String nameSpace = "http://tempuri.org/";//命名空间
String methodName = "PatientList";//方法
String soapAction = "http://tempuri.org/PatientList";//命名空间/方法
String serviceURL="http://192.168.1.22/androidweb/Service1.asmx"; //自己发布的webservcie的地址
org.ksoap2.transport.HttpTransportSE httpTranstation = new HttpTransportSE(serviceURL);
httpTranstation.debug = true;//是否是调试模式
SoapObject soapObject=new SoapObject(nameSpace,methodName);
soapObject.addProperty("str","123");
soapObject.addProperty("remark",":是中国人");
//soapObject.addProperty("参数", "参数值");调用的方法参数与参数值(根据具体需要可选可不选)
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;//注意:这个属性是对dotnetwebservice协议的支持,如果dotnet的webservice 不指定rpc方式则用true否则要用false
envelope.bodyOut = httpTranstation;
envelope.setOutputSoapObject(soapObject);//envelope.bodyOut=request;
try {
httpTranstation.call(soapAction, envelope);
SoapObject result = (SoapObject)envelope.bodyIn;//服务器返回的对象存在envelope的bodyIn中
//下面对结果进行解析,结构类似json对象
int count=result.getPropertyCount();
for(int index=0;index<count;index++){
Lists.add(result.getProperty(index).toString());
}
} catch (IOException e) { // TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) { // TODO Auto-generated catch block
e.printStackTrace();
}
return Lists;
}
.net部分代码:
[SoapRpcMethod, WebMethod]//具体方法中也要指定rpc方式
public List<string> PatientList(string str,string remark)
{
List<string> List = new List<string>();
List.Add(str + "王二" + remark);
List.Add(str + "张三" + remark);
List.Add(str + "李四" + remark);
return List;
}
效果:
更多相关文章
- 浅谈Java中Collections.sort对List排序的两种方法
- mybatisplus的坑 insert标签insert into select无参数问题的解决
- Python技巧匿名函数、回调函数和高阶函数
- Python list sort方法的具体使用
- python list.sort()根据多个关键字排序的方法实现
- android上一些方法的区别和用法的注意事项
- android实现字体闪烁动画的方法
- Android中dispatchDraw分析
- Android四大基本组件介绍与生命周期