android部分代码: 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;
}
web
.net部分代码: json
[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;
}
服务器
效果: .net