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