[英]Passing string array to c# web service (Android Ksoap2)
嗨,我一直在搜索google一段时间,但是似乎没有一个可靠的例子。 最近几天,我一直在使用android进行网络服务,并且我可以成功地从android传递参数并使用ksoap将其使用回去,而不会出现任何问题。 但是现在我需要将数组传递给Web服务。 因此,这是我的示例Web服务:
[WebMethod]
public string Sample(string[] logs)
{
return array[0];
}
这是我需要生成的XML:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Sample xmlns="http://MTKAndroidService.org/">
<array>
<string>string</string>
<string>string</string>
</array>
</Sample>
</soap:Body>
</soap:Envelope>
我已经坚持了一段时间,希望有人能帮助我。
终于明白了。。。。
public String Sample()
{
String SOAP_ACTION = "http://MTKAndroidService.org/Sample";
String METHOD_NAME = "Sample";
// URL = "http://10.0.2.2:49923/Service1.asmx"; // to be adjusted to the URL above once this code is added into WebService;
String IP_LIST="";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
List<String> logs = new ArrayList<String>();
logs.add("hello");
logs.add("world");
SoapObject soapLogs = new SoapObject(NAMESPACE, "logs");
for (String i : logs){
soapLogs.addProperty("string", i);
}
request.addSoapObject(soapLogs);
SoapSerializationEnvelope IPenvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
IPenvelope.dotNet = true;
IPenvelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, IPenvelope);
SoapPrimitive response = (SoapPrimitive)IPenvelope.getResponse();
Log.i("myApp", response.toString());
IP_LIST= response.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return IP_LIST;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.