【问题标题】:KSoap2-Android XMLPullParserException - SOAP web service client on AndroidKSoap2-Android XMLPullParserException - Android 上的 SOAP Web 服务客户端
【发布时间】:2014-03-20 07:17:21
【问题描述】:

请问我有通过 kSoap 发送 XML 的问题。我想通过 SOAP 以 XML 格式发送一些个人数据。我收到此错误:

03-03 11:01:07.464: W/System.err(7366): org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:1 in java.io.InputStreamReader@412a6410) 
03-03 11:01:07.464: W/System.err(7366):     at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:2035)
03-03 11:01:07.464: W/System.err(7366):     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:126)
03-03 11:01:07.464: W/System.err(7366):     at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
03-03 11:01:07.464: W/System.err(7366):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
03-03 11:01:07.464: W/System.err(7366):     at dp.fedorko.client.soapClient.Upload2(soapClient.java:79)
03-03 11:01:07.464: W/System.err(7366):     at dp.fedorko.client.soapClient.doInBackground(soapClient.java:181)
03-03 11:01:07.474: W/System.err(7366):     at dp.fedorko.client.soapClient.doInBackground(soapClient.java:1)*
...

这是我的代码

public String Upload2(String xml) {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1); 
        PropertyInfo pi1 = new PropertyInfo();
        pi1.setName("Xml");
        pi1.setValue(xml);
        pi1.setType(String.class);
        request.addProperty(pi1);
        Log.i("TAG", "XML: " + xml);    
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);

        envelope.setOutputSoapObject(request);
        Log.i("TAG", "Envelope: " + envelope.toString());       
        HttpTransportSE ht = new HttpTransportSE(URL);
        try {
            ht.call(SOAP_ACTION1, envelope);
            SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
            String s = response.toString();
            return s;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
     }

这是我要发送的 xml(作为肥皂操作的参数):

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><Upload><Person><Name value="mobile6" /><Active value="1" /><Datas><Data>25:255:1:0:1:1:0:0:3:1:0:2:1:5:0:0:0:8:0:0:1:0:3:0:4:0:0:0:0:0:0:0:0</Data></Datas></Person></Upload>

请任何人提供建议,可能是哪里出了问题?

这里也是在服务器端生成的wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:recognitionwsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" targetNamespace="urn:recognitionwsdl">
   <types>
      <xsd:schema targetNamespace="urn:recognitionwsdl">
         <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
         <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
      </xsd:schema>
   </types>
   <message name="uploadAndTestRequest">
      <part name="xmlfile" type="xsd:string" />
   </message>
   <message name="uploadAndTestResponse">
      <part name="return" type="xsd:string" />
   </message>
   <message name="udfRecognitionTestRequest">
      <part name="xmlfile" type="xsd:string" />
   </message>
   <message name="udfRecognitionTestResponse">
      <part name="return" type="xsd:string" />
   </message>
   <message name="udfRecognitionTest2Request">
      <part name="xmlfile" type="xsd:string" />
   </message>
   <message name="udfRecognitionTest2Response">
      <part name="return" type="xsd:string" />
   </message>
   <message name="webServiceTestRequest" />
   <message name="webServiceTestResponse">
      <part name="return" type="xsd:string" />
   </message>
   <portType name="recognitionwsdlPortType">
      <operation name="uploadAndTest">
         <documentation>Upload new person and train vectors</documentation>
         <input message="tns:uploadAndTestRequest" />
         <output message="tns:uploadAndTestResponse" />
      </operation>
      <operation name="udfRecognitionTest">
         <documentation>Test for peson with udf</documentation>
         <input message="tns:udfRecognitionTestRequest" />
         <output message="tns:udfRecognitionTestResponse" />
      </operation>
      <operation name="udfRecognitionTest2">
         <documentation>Test for peson with udf</documentation>
         <input message="tns:udfRecognitionTest2Request" />
         <output message="tns:udfRecognitionTest2Response" />
      </operation>
      <operation name="webServiceTest">
         <documentation>Test web service</documentation>
         <input message="tns:webServiceTestRequest" />
         <output message="tns:webServiceTestResponse" />
      </operation>
   </portType>
   <binding name="recognitionwsdlBinding" type="tns:recognitionwsdlPortType">
      <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
      <operation name="uploadAndTest">
         <soap:operation soapAction="urn:recognitionwsdl#connectAndTest" style="rpc" />
         <input>
            <soap:body use="encoded" namespace="urn:recognitionwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
         </input>
         <output>
            <soap:body use="encoded" namespace="urn:recognitionwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
         </output>
      </operation>
      <operation name="udfRecognitionTest">
         <soap:operation soapAction="urn:recognitionwsdl#udfRecognitionTest" style="rpc" />
         <input>
            <soap:body use="encoded" namespace="urn:recognitionwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
         </input>
         <output>
            <soap:body use="encoded" namespace="urn:recognitionwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
         </output>
      </operation>
      <operation name="udfRecognitionTest2">
         <soap:operation soapAction="urn:recognitionwsdl#udfRecognitionTest2" style="rpc" />
         <input>
            <soap:body use="encoded" namespace="urn:recognitionwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
         </input>
         <output>
            <soap:body use="encoded" namespace="urn:recognitionwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
         </output>
      </operation>
      <operation name="webServiceTest">
         <soap:operation soapAction="urn:recognitionwsdl#webServiceTest" style="rpc" />
         <input>
            <soap:body use="encoded" namespace="urn:recognitionwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
         </input>
         <output>
            <soap:body use="encoded" namespace="urn:recognitionwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
         </output>
      </operation>
   </binding>
   <service name="recognitionwsdl">
      <port name="recognitionwsdlPort" binding="tns:recognitionwsdlBinding">
         <soap:address location="http://[address]/server.php" />
      </port>
   </service>
</definitions>

下面是一起运行所有内容的代码:

public String uploadFaceToServer(String name, String LBP){
            xmlParser xparser = new xmlParser();
            soapClient client = new soapClient();
            String xml = xparser.writeUploadXml(name, "25:255:1:0:1:1:0:0:3:1:0:2:1:5:0:0:0:8:0:0:1:0:3:0:4:0:0:0:0:0:0:0:0");

            try {
                        return client.execute(1, xml).get();
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        return "Chyba";
                } catch (ExecutionException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        return "Chyba";
                }

        }

请我在几周内遇到此错误。我需要一些支持。请帮忙!

谢谢

马丁·费多科 斯洛伐克技术大学

【问题讨论】:

  • 嗨,您是否在构建路径中正确添加了 ksoap 库!也请访问stackoverflow.com/questions/17816871/…
  • 嗨,这似乎很好,因为当我从我的 Web 服务调用更简单的函数(没有参数并且只返回文本 "Webservice is reachable" )时,这在我的 android 应用程序中运行良好。
  • 哦,好吧,我会再次尝试检查,如果我有更好和有效的答案,我会回来!!
  • 这将是完美的,因为我被困在这两个星期,我找不到任何解决方案。如果你需要,我可以上传洞源代码。
  • 这是我的完整代码:sendspace.com/file/e35ldq

标签: android web-services soap ksoap2 android-ksoap2


【解决方案1】:

这是服务器端的错误。我有错误的 php mysql 设置和其他一些错误

【讨论】:

    【解决方案2】:

    我在许多将参数从 android 传递到 c# web 服务的示例中都看到了这一点: PropertyInfo pi1 = new PropertyInfo(); pi1.setName("Xml"); pi1.setValue(xml); pi1.setType(String.class); request.addProperty(pi1);

    我猜这就是旧版本的 ksoap 的工作方式?几周前我遇到的任何情况。几天来,这让我觉得我搞砸了我的 c# web 服务,这是不正确的。我以与您相同的方式传递参数,后来我发现这是错误!

    这是如何将参数从 Android 中的 Ksoap 正确传递到 c# Web 服务: request.addProperty("c# webservice方法中的参数名称", xml);

    【讨论】:

    • 我试图把 request.addProperty("xmlfile", xml);但这没有帮助。
    • 而我的客户端不是c#写的,而是java,是android客户端
    • 奇怪的是应该工作。我的设置是这样的,它工作得很好。您能否发布您想从您的网络服务调用的方法?
    • 我要调用 UploadAndTest 方法
    • 好吧,您可以很好地传递参数值。我再次浏览了您的代码,我看到的唯一区别是我正在使用:SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);而您使用的 SoapSerializationEnvelope 信封 = new SoapSerializationEnvelope(SoapEnvelope.VER12);尝试将其更改为 VER11
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 2011-10-11
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    相关资源
    最近更新 更多