ksoap2 android 1c不同的xml结构

时间:2015-03-04 10:19:31

标签: android ksoap2 android-ksoap2

ksoap2像这样生成xml

<?xml
    version="1.0"
    encoding="UTF-8"
    ?>
<env:Envelope>
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <env:Body>
        <tns:GetListClient>
            xmlns:tns="http://www.spr.org"
            hello
            </tns:GetListClient>
        </env:Body>
    </env:Envelope>

但是web-service 1c,除了这样的xml结构文件外

<soap:Envelope>
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
        <soap:Header/>
        <soap:Body>
            <m:GetListClient>
                xmlns:m="http://www.spr.org"
                <m:Param/>
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                </m:GetListClient>
            </soap:Body>
        </soap:Envelope>

正如你所看到的那样,区别在于这个参数

xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Android代码

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Celsius", "23");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.implicitTypes = true;

        envelope.setOutputSoapObject(request);
        Log.e("request", request.toString());

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;

        try {
            androidHttpTransport.call(SOAP_ACTION, envelope,headerProperty);
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            resultString = response.toString();
            Log.e("requestDumpCelsius",androidHttpTransport.requestDump);
            Log.e("responseDumpCelsius",androidHttpTransport.responseDump);
        } catch (Exception e) {
            e.printStackTrace();
            resultString = null;
        }
        if(resultString!=null)
        return resultString;
}

它给了我这样的例外

03-04 12:17:53.723    3932-3945/eu.msdlab.postmobile W/System.err﹕ SoapFault - faultcode: 'soap:Client' faultstring: 'Ошибка разбора SOAP сообщения: неизвестный параметр. ' faultactor: 'null' detail: org.kxml2.kdom.Node@41bf3470
03-04 12:17:53.723    3932-3945/eu.msdlab.postmobile W/System.err﹕ at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:137)
03-04 12:17:53.723    3932-3945/eu.msdlab.postmobile W/System.err﹕ at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
03-04 12:17:53.723    3932-3945/eu.msdlab.postmobile W/System.err﹕ at org.ksoap2.transport.Transport.parseResponse(Transport.java:129)

我需要的是改变xml文件的结构 但是PropertyInfo允许我只添加一个命名空间

问题解决了 好像我使用了错误的属性

1 个答案:

答案 0 :(得分:1)

据我了解您的代码,这可能是NAMESPACE问题

尝试使用

private static String NAMESPACE = "http://tempuri.org/";

如果上面没有工作那么

private static String NAMESPACE = "xmlns:m="http://www.spr.org"";

如果以上两者都不适合您,请发布 WSDL