gpt4 book ai didi

c# - 将字符串数组传递给 c# web 服务 (Android Ksoap2)

转载 作者:搜寻专家 更新时间:2023-11-01 08:03:03 25 4
gpt4 key购买 nike

您好,我已经在 google 上搜索了一段时间,但似乎没有这方面的可靠示例。在过去的几天里,我一直在使用 webservice 使用 android,我可以成功地从 android 传递参数并使用 ksoap 毫无问题地使用它。但现在我需要将数组传递给网络服务。所以这是我的示例 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;
}

关于c# - 将字符串数组传递给 c# web 服务 (Android Ksoap2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18305265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com