android中的KSOAP2双ID异常

android中的KSOAP2双ID异常,android,android-ksoap2,runtimeexception,Android,Android Ksoap2,Runtimeexception,我在android应用程序中使用KSOAP2,当我尝试执行特定的webservice请求时,我得到了这个“双ID”异常。我错在哪里?请帮帮我 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); Http

我在android应用程序中使用KSOAP2,当我尝试执行特定的webservice请求时,我得到了这个“双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();
        }

这里有一个很好的例子可以帮助您:

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

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);
<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>
SoapSerializationEnvelope soapEnvelope=新的SoapSerializationEnvelope(
第11版);
SoapObject请求=新的SoapObject(名称空间、方法名称);
setOutputSoapObject(请求);
soapEnvelope.dotNet=true;
上市公司=新ArrayList();
增加(65);
增加(66);
增加(67);
请求。添加属性(“名称”、“测试1”);
SoapObject soapcompanys=新的SoapObject(名称空间,“companys”);
适用于(整数i:公司){
soapCompanies.addProperty(“int”,i);
}
Request.addSoapObject(soapcompanys);
输出XML:

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);
<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>

65
66
67
测试1

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

在我的例子中,是因为Webservice(C#)返回一个数据集,但是,我改变了一些列,然后返回,因此,我有两个具有相同Id的表,带有diffgr:before标记

因此,在处理数据集时,只需将代码放在Web服务返回对象之前:

ds.AcceptChanges()


:-)

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

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

e、 g:
一个表有“表”、“表1”(如果您的数据集选择了更多表)
如果“A”有11条记录并显示到XML,则为
、………

如果B有10条记录并向XML显示,则为
、………

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

解决方案

更改数据集表名称

SqlDataAdapter.Fill(数据集)
DataSet.Tables[0].TableName=“Table_”
DataSet.Tables[1].TableName=“Table1_”

AcceptChanges()

你找到解决办法了吗?我也面临同样的问题,这不是解决办法。问题不在代码中,而在WCF响应中,示例链接也死了,请用英语书写