2

Hello Friends i am using soap web services very first time in my code. but i am not getting how to handle nested soap objects. this is my code

private final String URL = "http://192.168.0.20/BookingEngineService/HotelBookingService.asmx";
    private final String SOAP_ACTION = "http://tempuri.org/AndroidTestRequest";
    private final String METHOD_NAME = "AndroidTestRequest";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("User", "abcd@xyz.com");
        request.addProperty("Password", "abcd@123");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.headerOut = new Element[1];
        envelope.headerOut[0] = buildAuthHeader();
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            Log.i("myAppEnvelope", envelope.toString());

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

        // here i am trying to get values from response which is soap object 

            for (int i = 0; i < response.getPropertyCount(); i++) {

                SoapObject con = (SoapObject) response.getProperty(i);

                Log.e("Continent", con.toString());
            }


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

i am getting soap object as a response and which is very complex so i am not getting how to parse it. this is my response this is very small part of my response.

I am not getting how to get values from SoapObject -> Properties -> elementData -> value-> property -> elementData and so on ... its too complex please help me.

4

2 回答 2

1

您可以将肥皂对象转换为字符串。检查下面的示例代码例如:

     final  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
     final String str = response.toString();
于 2013-04-25T14:22:54.183 回答
0

这是一个简单的 XML 解析。通过链接了解更多详细信息。

您可以将响应作为输入流获取并将其转换为字符串,然后使用该字符串,您可以创建一个 XML 对象。请参阅链接以获取更多信息。

于 2013-04-24T10:45:21.693 回答