KSoap2-Android XMLPullParserException - Android上的SOAP Web服务客户端

时间:2014-03-18 09:30:47

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

请问通过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,我想发送(作为soap操作的参数):

<?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";
                }

        }

请问我几周后就会遇到这个错误。我需要一些支持。请帮忙!

谢谢

Martin Fedorko 斯洛伐克技术大学

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我在很多例子中都看到了这个问题,用于将参数传递给来自android的c#web服务:     PropertyInfo pi1 = new PropertyInfo();     pi1.setName(&#34;的Xml&#34);     pi1.setValue(XML);     pi1.setType(String.class);     request.addProperty(PI1);

我想这是旧版本的ksoap如何工作?几个星期前我在你身边的任何方式。好几天它让我觉得我错了我的c#web服务,这是不正确的。我以与你相同的方式传递我的参数,后来我发现这是错误!

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