Android SOAP信封修改

时间:2014-06-26 20:38:53

标签: android xml soap

应用程序创建以下请求XML:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
  <v:Header />
  <v:Body>
   some body...
  </v:Body>
</v:Envelope>

需要来准备这种请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header/>
  <soapenv:Body>
    some body...
  </soapenv:Body>
</soapenv:Envelope>

最重要的是在第一个字符串中,它应该以{{1​​}}开头,而不是xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

如何更改:

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

这是一个logcat跟踪:

try {

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            request.addProperty("entity", "persona");
            request.addProperty("last_update_date", "20140101");
            request.addProperty("country", "UA");
            request.addProperty("user", "someuser");

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        Log.i(TAG, "Envelope to String: \n" + String.valueOf(envelope));
        Log.i(TAG, "request to String: \n" + String.valueOf(request));

            envelope.implicitTypes = true;
            envelope.setAddAdornments(false);
            envelope.dotNet = true;

            envelope.bodyOut = request;
            envelope.setOutputSoapObject(request);

            HttpTransportBasicAuth androidHttpTransport = null;

            try 
            {

                androidHttpTransport = new HttpTransportBasicAuth(URL, null, null);
                androidHttpTransport.debug = true;

                androidHttpTransport.call(SOAP_ACTION, envelope);

                SoapObject result = (SoapObject) envelope.getResponse();

                } 
        catch (SoapFault e)
        {
            e.printStackTrace();
            Log.d(TAG, "2 HTTP REQUEST:\n" + androidHttpTransport.requestDump);
            Log.d(TAG, "2 HTTP RESPONSE:\n" + androidHttpTransport.responseDump);
        }
        catch (Exception e) 
        {

            e.printStackTrace();
            SoapObject resultsRequestSOAP = (SoapObject)envelope.bodyIn;
            Log.d(TAG, "Exception REQUEST:\n" + androidHttpTransport.requestDump);
            Log.d(TAG, "BodyIn #2 \n" + resultsRequestSOAP);
            Log.d(TAG, "Exception RESPONSE:\n" + androidHttpTransport.responseDump);

        }

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

    }

}

信封构造后记录:

06-25 12:50:58.955: I/ENVELOPE_BODY(24323): XMLDataGet{property1=value1; property2=value2; property3=value3; property4=value4; }

06-25 12:50:59.630: D/GetInfo(24323): Exception REQUEST:
06-25 12:50:59.630: D/GetInfo(24323): <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body><XMLDataGet xmlns="http://tempuri.org/"><property1>value1</property1><property2>value2</property2><property3>value3</property3><property4>value4</property4></XMLDataGet></v:Body></v:Envelope>


06-25 12:50:59.635: D/GetInfo(24323): BodyIn 
06-25 12:50:59.635: D/GetInfo(24323): null


06-25 12:50:59.635: D/GetInfo(24323): Exception RESPONSE:
06-25 12:50:59.635: D/GetInfo(24323): <s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/"><s:Body xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema"><XMLDataGetResponse xmlns="https://tempuri.org/"><XMLDataGetResult><ItemList xmlns="">....the whole data structure...</ItemList></XMLDataGetResult></XMLDataGetResponse></s:Body></s:Envelope>

06-25 12:57:26.500: W/System.err(25523): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <{https://schemas.xmlsoap.org/soap/envelope/}s:Envelope>@1:66 in java.io.InputStreamReader@42832a90)

0 个答案:

没有答案