android中的KSOAP2双ID异常

时间:2012-08-08 09:26:24

标签: android android-ksoap2 runtimeexception

我在我的Android应用程序中使用KSOAP2,当我尝试执行特定的Web服务请求时,我得到了这个“双ID”异常。哪里出错了?请帮帮我。

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(SOAP_ADDRESS);

        SoapPrimitive response = null;
        try {   
          androidHttpTransport.call(SOAP_ACTION, envelope); //<<--- Getting exception here
          response = (SoapPrimitive)envelope.getResponse();

        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), e+"", Toast.LENGTH_LONG).show();
        }

StackTrace:

java.lang.RuntimeException: double ID
at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:407)
at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
 at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
 at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
 at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
 at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:151)
 at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
 at org.ksoap2.transport.Transport.parseResponse(Transport.java:116)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:235)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
at com.menthatech.soap_login_test.SampleSoapTest_LoginActivity.onClick(SampleSoapTest_LoginActivity.java:94)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

3 个答案:

答案 0 :(得分:1)

今天我有这个例外......我不知道你的情况是否相同......

在我的情况下是因为Webservice(C#)返回一个数据集,但是,我正在改变一些列然后返回,因此,我有2个具有相同Id的表。使用diffgr:在标记之前。

因此,当您处理数据集时,只需将代码放在Webservice之前返回对象:

<强> ds.AcceptChanges();

: - )

答案 1 :(得分:0)

以下是可以帮助您的好例子:Click Here

以下是我对此问题的快速解决方法:

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);

SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
soapEnvelope.setOutputSoapObject(Request);
soapEnvelope.dotNet = true;


List<Integer> companies =  new ArrayList<Integer>();
companies.add(65);
companies.add(66);
companies.add(67);

Request.addProperty("name", "test1");
SoapObject soapCompanies = new SoapObject(NAMESPACE, "companies");
for (Integer i : companies){
    soapCompanies.addProperty("int", i);
}
Request.addSoapObject(soapCompanies);

输出XML:

<n0:companies xmlns:n0 = "http://tempuri.org/">
            <int i:type = "d:int">65</int>
            <int i:type = "d:int">66</int>
            <int i:type = "d:int">67</int>
</n0:companies>
<name i:type = "d:string">test1</name>

答案 2 :(得分:-1)

我想为遇到此问题的人记录不同的解决方案。...

因为使用“ diffgram”将DataSet数据回调回XML。 “双重ID”错误是重复,具有相同的ID

例如:
一个表具有“表”,“表1”(如果您的数据集选择更多表)
如果“ A”有11条记录,并且显示到XML是

.........


如果B有10条记录并显示到XML是
.........

SO。 您可以看到diffgr:id =“ Table11”重复。这就是为什么有“双ID”错误

解决方案

更改数据集表名称

SqlDataAdapter.Fill(DataSet);
DataSet.Tables [0] .TableName =“ Table_”;
DataSet.Tables [1] .TableName =“ Table1_”;
DataSet.AcceptChanges();