XmlPullParserException:在ksoap2上预计START_TAG,但结果显示正常

时间:2015-01-05 13:57:35

标签: android xml soap android-ksoap2

我收到了标题中提到的错误。搜索此站点和其他站点表明它是由于错误的NAMESPACE或URL值,但它们都很好。此外,当我使用调试模式并转储服务器返回的xml时,响应很好,看起来与SoapUI中的结果完全一样。代码粘贴在下面;这是一个很长的时间。

它使用两个不同的Soap调用,因为第一个只返回一个ID,第二个将转换为用户名。

public Object doInBackground(String... params)
    {
        String email = params[0];
        String password = params[1];

        //Soap variabelen voor de visitList
        SoapObject request = new SoapObject(NAMESPACE, "getVisitList");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.dotNet = false; 
        envelope.setOutputSoapObject(request);
        HttpTransportSE transport = new HttpTransportSE(URL); 

        //Soap variabelen klaarzetten voor de username
        SoapObject usernameRequest = new SoapObject(NAMESPACE, "getUser");
        SoapSerializationEnvelope usernameEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        usernameEnvelope.dotNet = false;

        HttpTransportSE usernameTransport = new HttpTransportSE(URL);
        usernameTransport.debug = true;
        try{
            List<HeaderProperty> headerlist = new ArrayList<HeaderProperty>();
            headerlist.add(new HeaderProperty("Authorization", "Basic " + org.kobjects.base64.Base64.encode((email+":"+password).getBytes())));

            transport.call(SOAP_ACTION1, envelope, headerlist);

            Vector<SoapObject> response = (Vector<SoapObject>)envelope.getResponse();

            for(int i = 0; i<response.size(); i++)
            {
                SoapObject tempObject = response.get(i);
                if(tempObject != null)
                {
                    Visit tempVisit = new Visit();
                    tempVisit.setId(Integer.parseInt(tempObject.getProperty("ID").toString()));
                    tempVisit.setArrival(tempObject.getProperty("Arrival").toString());
                    tempVisit.setDuration(Integer.parseInt(tempObject.getProperty("Duration").toString()));
                    tempVisit.setReason(tempObject.getProperty("Reason").toString());

                    //Haal de username op met een soap request
                    PropertyInfo userid_pi = new PropertyInfo();
                    userid_pi.setName("ID");
                    userid_pi.setValue(tempObject.getProperty("UserID"));
                    userid_pi.setType(Integer.class);

                    usernameRequest.addProperty(userid_pi);
                    usernameEnvelope.setOutputSoapObject(usernameRequest);
                    usernameTransport.call(SOAP_ACTION2, usernameEnvelope, headerlist);
                    SoapObject usernameResponse = (SoapObject)usernameEnvelope.getResponse();

                    tempVisit.setUser(usernameResponse.getProperty("Name").toString());

                    result.add(tempVisit);
                }
            }

            return result;

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

这是服务器返回的xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:tns="urn:DuocastAPI">
<SOAP-ENV:Body>
    <ns1:getUserResponse xmlns:ns1="DuocastAPI/">
        <User xsi:type="tns:User">
            <ID xsi:type="xsd:int">2208</ID>
            <Name xsi:type="xsd:string">Lorem</Name>
            <CompanyName xsi:type="xsd:string">Ipsum</CompanyName>
            <Email xsi:type="xsd:string">lorem@ipsum.net</Email>
            <PassPort xsi:type="xsd:string"></PassPort>
            <IDCard xsi:type="xsd:string">#number here#</IDCard>
            <DriversLicense xsi:type="xsd:string"></DriversLicense>
            <Phone xsi:type="xsd:string">+12345678</Phone>
            <StorageArea xsi:type="xsd:boolean">true</StorageArea>
            <GuidedAccess xsi:type="xsd:boolean">true</GuidedAccess>
        </User>
    </ns1:getUserResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

此处显示错误消息:

01-05 12:38:21.437: W/System.err(2324): org.xmlpull.v1.XmlPullParserException: expected:
   START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG (empty)
<br>@1:7 in     java.io.InputStreamReader@41f94798) 

0 个答案:

没有答案