【问题标题】:Error with kSOAP2kSOAP2 错误
【发布时间】:2015-06-09 07:47:05
【问题描述】:

我正在尝试将手机的用户名和设备 ID 提交到我的服务器,但我不断收到以下错误:

W/System.err:SoapFault - 故障代码:'soap:Client' 故障字符串:'解组错误:意外元素(uri:“http://eventmanagement.management.de/”,本地:“用户名”)。预期元素是 , ' faultactor: 'null' detail: null

这是我的代码:

       PropertyInfo pi = new PropertyInfo();
       pi.setNamespace(NAMESPACE);
       pi.setName("username");
       pi.setValue(userName.getText().toString());
       pi.setType(PropertyInfo.STRING_CLASS);
       request.addProperty(pi); 
       pi.setNamespace(NAMESPACE);
       pi.setName("deviceID");

       pi.setValue(android.provider.Settings.Secure.getString(
       getContentResolver(), 
       android.provider.Settings.Secure.ANDROID_ID));
       pi.setType(PropertyInfo.STRING_CLASS);
       request.addProperty(pi);

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

这是 wsdl 文件:

 <xs:complexType name="addUser">
   <xs:sequence>
    <xs:element minOccurs="0" name="username" type="xs:string"/>
    <xs:element minOccurs="0" name="deviceID" type="xs:string"/>
   </xs:sequence>
  </xs:complexType>

有人可以帮我吗? 我已经搜索了 2 个小时,没有找到任何东西。

编辑2: http-Request 转储的左上角 右上角的 SoapUI 生成的请求有效 http://www.directupload.net/file/d/4013/5iwbvowk_png.htm

【问题讨论】:

  • 我的问题中不能打招呼有什么原因吗?:D
  • 尝试使用String.class 而不是PropertyInfo.STRING_CLASS
  • 以前试过。也没有用。

标签: android web-services wsdl ksoap2


【解决方案1】:

您是否尝试过使用addProperty 的以下风格简单地添加属性

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("username", username);
request.addProperty("deviceID", deviceID);

此外,您可以确保您有一个有效值,并且在访问 userName.getText().toString() 时没有点击任何 NPE

【讨论】:

  • 耶。那个也试过。没有变化。
  • 您是否尝试过使用 SoapUI 制作 request/response 并确认您的 web servicewsdl 没有问题?
  • 为了更好的调试,在调用androidHttpTransport.call(...)之前尝试设置androidHttpTransport.debug = true。您应该能够看到requestresponse 转储。根据您在SoapUI中看到的内容,看看您的请求是否正确(或者您已经有了清晰的图片)
  • directupload.net/file/d/4013/5iwbvowk_png.htm 左上角是请求转储,左上角是 SoapUi 请求。但我不知道我必须改变什么
  • 能否请您提供请求转储的屏幕截图,在我的答案中有所更改,您不会明确提及名称空间或属性类型
【解决方案2】:

您应该记得在添加第一个属性后将您的属性声明为新属性。

pi = new PropertyInfo();

   PropertyInfo pi = new PropertyInfo();
   pi.setNamespace(NAMESPACE);
   pi.setName("username");
   pi.setValue(userName.getText().toString());
   pi.setType(PropertyInfo.STRING_CLASS);
   request.addProperty(pi); 

   // here
   pi = new PropertyInfo();  
   pi.setNamespace(NAMESPACE);
   pi.setName("deviceID");
   pi.setValue(android.provider.Settings.Secure.getString(
   getContentResolver(), 
   android.provider.Settings.Secure.ANDROID_ID));
   pi.setType(PropertyInfo.STRING_CLASS);
   request.addProperty(pi);

还有一件事,记得调用你的 androidHttpTransport

androidHttpTransport.call(SOAP_ACTION,envelope,null);
SoapPrimitive respond = (SoapPrimitive) envelope.getResponse();

更新: 您的请求是否传递了您想要的确切参数?调试的时候可以看到webservice的名字,还有你传入的值名和参数。

ConnectionString{用户名=经理;密码=密码123; }

【讨论】:

  • 是的,抱歉,我确实调用了 androidHttpTransport。那是发生错误的行。试过你的代码。可惜没用。
  • 你传入的参数呢?我看到您的错误提到预期的元素设备 ID 出现在用户名之前。
  • 现在它更改为:SoapFault - 故障代码:'soap:Client' 故障字符串:'解组错误:意外元素(uri:“eventmanagement.management.de”,本地:“deviceID”)。预期元素是 , ' faultactor: 'null' detail: null
  • 您是否调试并检查过该参数是否成功传递到您的请求中?
  • 是的。调试告诉我一切都很好,直到调用 androidHttpTransport
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-10
  • 2012-09-07
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
相关资源
最近更新 更多