2012-08-08 59 views
3

我在我的android應用程序中使用KSOAP2,當我嘗試執行特定的Web服務請求時,我得到了這個「雙ID」異常。哪裏出錯了?請幫幫我。KSOAP2 Android中的雙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(); 
     } 

堆棧跟蹤:

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) 
+0

您是否找到解決方案? 我正面臨同樣的問題 – kinghomer 2012-08-26 21:50:38

回答

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

這不是一個解決方案。問題不在代碼中,而是在WCF響應 – kinghomer 2012-08-26 22:07:40

+1

示例鏈接也是死的 – amitav13 2015-05-12 20:22:12

1

我今天有這個例外......我不知道你的情況是一樣的...

在我的情況是,因爲web服務(C#)回報一個數據集,但是,我工作,改變一些列,然後返回,所以,我有2個表具有相同的ID。與diffgr:在標籤之前。

所以,當你的工作數據集只是把你的代碼之前的Webservice返回對象:

ds.AcceptChanges();

:-)