我的 .NET Web 服务返回一个 XML。当我在 Android 中使用 ksoap2 调用 Web 服务时,我遇到了这个问题。请帮忙。
我在 Eclipse 中的 Logcat
12-19 15:58:11.951: W/dalvikvm(2041): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-19 15:58:11.961: E/AndroidRuntime(2041): FATAL EXCEPTION: main
12-19 15:58:11.961: E/AndroidRuntime(2041): java.lang.RuntimeException: double ID
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:407)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:151)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.transport.Transport.parseResponse(Transport.java:116)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:259)
12-19 15:58:11.961: E/AndroidRuntime(2041): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
12-19 15:58:11.961: E/AndroidRuntime(2041): at com.example.webservicee.MainActivity$1.onClick(MainActivity.java:133)
12-19 15:58:11.961: E/AndroidRuntime(2041): at android.view.View.performClick(View.java:2408)
12-19 15:58:11.961: E/AndroidRuntime(2041): at android.view.View$PerformClick.run(View.java:8816)
12-19 15:58:11.961: E/AndroidRuntime(2041): at android.os.Handler.handleCallback(Handler.java:587)
12-19 15:58:11.961: E/AndroidRuntime(2041): at android.os.Handler.dispatchMessage(Handler.java:92)
12-19 15:58:11.961: E/AndroidRuntime(2041): at android.os.Looper.loop(Looper.java:123)
12-19 15:58:11.961: E/AndroidRuntime(2041): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-19 15:58:11.961: E/AndroidRuntime(2041): at java.lang.reflect.Method.invokeNative(Native Method)
12-19 15:58:11.961: E/AndroidRuntime(2041): at java.lang.reflect.Method.invoke(Method.java:521)
12-19 15:58:11.961: E/AndroidRuntime(2041): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-19 15:58:11.961: E/AndroidRuntime(2041): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
MainActivity.java
package com.example.webservicee;
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
final static String NAMESPACE = "http://tempuri.org/";
final static String METHOD_NAME = "GetContent";
final static String SOAP_ACTION = "http://tempuri.org/GetContent";
final static String URL = "http://www.example.com/XMLGenerator/GenerateXML.asmx";
private Button Mybtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
deger = (EditText) findViewById(R.id.deger);
sonuc = (TextView) findViewById(R.id.flag);
Mybtn = (Button) findViewById(R.id.hesapla);
Mybtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
//My webservice paramaters
Request.addProperty("SectionsInclude","10");
Request.addProperty("DocumentCount",10);
Request.addProperty("SortBy","0");
Request.addProperty("SortOrder","ASC");
Request.addProperty("UserName","myuser");
Request.addProperty("Pass","Lsss");
/**/
/* PropertyInfo pi=new PropertyInfo();
pi.setName("arg0");
pi.setValue("10");
pi.setType(String.class);
Request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("arg1");
pi.setValue(10);
pi.setType(Integer.class);
Request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("arg2");
pi.setValue("0");
pi.setType(String.class);
Request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("arg3");
pi.setValue("ASC");
pi.setType(String.class);
Request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("arg4");
pi.setValue("myuser");
pi.setType(String.class);
Request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("arg5");
pi.setValue("Lsss");
pi.setType(String.class);
Request.addProperty(pi);
*/
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
//soapEnvelope.bodyOut = Request;
HttpTransportSE aht = new HttpTransportSE(URL);
try {
aht.call(SOAP_ACTION, soapEnvelope);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String result;
try {
result = "Fahrenheit:"+(SoapPrimitive) soapEnvelope.getResponse();
Log.d("--Result-- ", result);
//sonuc.setText(result);
} catch (SoapFault e)
{
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
这是示例响应 xml:
<?xml version="1.0" encoding="utf-8"?>
<liste>
<document id="6" titles="bestPeople" showingDate="27.09.2011 00:00:00" date="27.09.2011 00:00:00" ContentID=rbHe8zKvDTG7TLS" >
<part id="6" baslik="best" icerik="<table style="width: 188px; height: 24px;" border="tbody>
</table>" resim="">
<SecNotes><![CDATA[]]></SecNotes>
<ContNotes><![CDATA[]]></ContNotes>
</part>
<SecNotes><![CDATA[]]></SecNotes>
<ContNotes><![CDATA[]]></ContNotes>
</document>
</liste>