gpt4 book ai didi

android - 将复杂对象的列表/数组从 Android 发送到 vb.net web 服务

转载 作者:行者123 更新时间:2023-11-30 02:53:52 26 4
gpt4 key购买 nike

我正在尝试使用 ksoap 从 android 向 vb.net web 服务发送复杂对象的数组/列表。我可以发送复杂的对象,但列表给我带来了麻烦。

这是安卓代码

private class SampleTask extends AsyncTask<String, Void, String> {

@Override
protected void onPreExecute() {
// if you want, start progress dialog here
}

@Override
protected String doInBackground(String... urls) {
String webResponse = "";
try {
final String NAMESPACE = "http://sample.org/";
final String URL = "http://192.168.1.103:8081/MySampleService.asmx";
final String SOAP_ACTION = "http://sample.org/SampleWS";
final String METHOD_NAME = "SampleWS";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
List<MediSenseLog> logs = new ArrayList<MediSenseLog>();

MediSenseLog log1 = new MediSenseLog();
log1.setID(Integer.parseInt("1"));
log1.setLogDate("2014-05-13");

MediSenseLog log2 = new MediSenseLog();
log1.setID(Integer.parseInt("2"));
log1.setLogDate("2014-05-14");

logs.add(log1);
logs.add(log2);

SoapObject soapLogs = new SoapObject(NAMESPACE, "logs");

for (MediSenseLog i : logs){
soapLogs.addProperty("MediSenseLog", i);
}
request.addSoapObject(soapLogs);


SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE, "MediSenseLog",new MediSenseLog().getClass());

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.d("HTTP REQUEST ",androidHttpTransport.requestDump);
Log.d("HTTP RESPONSE", androidHttpTransport.responseDump);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
Log.d("ComplexWS", response.toString());
webResponse = response.toString();

} catch (Exception e) {
}

return webResponse;
}

@Override
protected void onPostExecute(String result) {

Toast.makeText(getApplicationContext(), "Synchonization Completed...",Toast.LENGTH_LONG).show();
Log.d("ComplexWS","return val is "+result);

}
}

这是.net代码

 Public Class MediSenseLog
Public ID As Integer
Public LogDate As String

End Class

<WebMethod()> _
Public Function SampleWS(ByVal logs As MediSenseLog()) As String
Return logs(1).LogDate.ToString()
End Function

这是使用requestdump的请求

 <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<Sample xmlns="http://sample.org/" id="o0" c:root="1">
<n0:logs i:type="n0:logs" xmlns:n0="http://sample.org/">
<MediSenseLog i:type="n0:MediSenseLog">
<ID i:type="d:int">2</ID>
<LogDate i:type="d:string">2014-05-14</LogDate>
</MediSenseLog>
<MediSenseLog i:type="n0:MediSenseLog">
<ID i:type="d:int">0</ID>
<LogDate i:null="true" />
</MediSenseLog>
</n0:logs>
</Sample>
</v:Body>
</v:Envelope>

这是使用响应转储的响应

 <?xml version="1.0" encoding="utf-8"?><soap:Envelope        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SampleResponse xmlns="http://sample.org/">
<SampleResult />
</SampleResponse>
</soap:Body>
</soap:Envelope>

返回值为空。

有人可以帮忙吗?

最佳答案

发现错误

只是改变这个

 log1.setID(Integer.parseInt("2"));
log1.setLogDate("2014-05-14");

log2.setID(Integer.parseInt("2"));
log2.setLogDate("2014-05-14");

关于android - 将复杂对象的列表/数组从 Android 发送到 vb.net web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23667294/

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