将复杂对象列表/数组从Android发送到vb.net web服务
我正在尝试使用ksoap将一个复杂对象的数组/列表从android发送到vb.NETWebService。我可以发送复杂的对象,但列表给我带来了麻烦 这是android代码将复杂对象列表/数组从Android发送到vb.net web服务,android,vb.net,web-services,android-ksoap2,Android,Vb.net,Web Services,Android Ksoap2,我正在尝试使用ksoap将一个复杂对象的数组/列表从android发送到vb.NETWebService。我可以发送复杂的对象,但列表给我带来了麻烦 这是android代码 private class SampleTask extends AsyncTask<String, Void, String> { @Override protected void onPreExecute() { // if you want, sta
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);
}
}
私有类SampleTask扩展了AsyncTask{
@凌驾
受保护的void onPreExecute(){
//如果需要,请在此处启动“进度”对话框
}
@凌驾
受保护的字符串doInBackground(字符串…URL){
字符串webResponse=“”;
试一试{
最终字符串名称空间=”http://sample.org/";
最终字符串URL=”http://192.168.1.103:8081/MySampleService.asmx";
最后一个字符串SOAP_ACTION=”http://sample.org/SampleWS";
最终字符串方法\u NAME=“SampleWS”;
SoapObject请求=新的SoapObject(名称空间、方法名称);
列表日志=新的ArrayList();
MediSenseLog log1=新MediSenseLog();
log1.setID(Integer.parseInt(“1”));
日志1.设置日志日期(“2014-05-13”);
MediSenseLog log2=新MediSenseLog();
log1.setID(Integer.parseInt(“2”));
日志1.设置日志日期(“2014-05-14”);
logs.add(log1);
logs.add(log2);
SoapObject soapLogs=新的SoapObject(名称空间,“日志”);
用于(MediSenseLog i:日志){
soapLogs.addProperty(“MediSenseLog”,i);
}
addSoapObject(soapLogs);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
addMapping(名称空间,“MediSenseLog”,新的MediSenseLog().getClass());
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL);
androidHttpTransport.debug=true;
调用(SOAP_操作,信封);
Log.d(“HTTP请求”,androidHttpTransport.requestDump);
Log.d(“HTTP响应”,androidHttpTransport.responseDump);
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
Log.d(“ComplexWS”,response.toString());
webResponse=response.toString();
}捕获(例外e){
}
返回webResponse;
}
@凌驾
受保护的void onPostExecute(字符串结果){
Toast.makeText(getApplicationContext(),“同步完成…”,Toast.LENGTH\u LONG.show();
Log.d(“ComplexWS”,“返回值为”+结果);
}
}
这是.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
公共类MediSenseLog
作为整数的公共ID
公共日志日期作为字符串
末级
_
公共函数SampleWS(ByVal作为MediSenseLog()记录)作为字符串
返回日志(1).LogDate.ToString()
端函数
这是使用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>
2.
2014-05-14
0
这是使用响应转储的响应
<?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");