简体   繁体   中英

Weird response from Android soap service call

We have an android application that we're trying to use for web-service communication.

We can successfully send a request and get a response with the following snippet.

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    TextView textView = new TextView(this);

    setContentView(textView);
    //textView.setText();

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    request.addProperty("foo", "bar");
    request.addProperty("foo", "bar");
    request.addProperty("foo", "bar");
    request.addProperty("foo", "bar");
    request.addProperty("foo", "bar");
    request.addProperty("foo", "bar");


    Log.w(TAG, request.toString());
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;

    envelope.setOutputSoapObject(request);
    envelope.encodingStyle = "utf-8";
    envelope.implicitTypes = false;
    AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);

    try

    {
    httpTransport.call(SOAP_ACTION, envelope);

    KvmSerializable ks = (KvmSerializable)envelope.bodyIn;
    for(int i=0;i < ks.getPropertyCount();i++)
    {
        ks.getProperty(i);
        SoapObject soap = (SoapObject)ks.getProperty(i);
        String tmp = soap.getProperty(0).toString();
        textView.setText(tmp);
        Log.w(TAG2, envelope.toString());
        Log.w(TAG3, ks.getProperty(i).toString());

    }

    }
    catch (Exception exception)
    {
        textView.setText(exception.toString());
        Log.w(TAG4, exception);
    }


 }

Now, the response from the request that gets presented in the textView.setText(tmp); presents the response as follows:

anyType{foo=bar;foo=bar;foo=bar;}

Whereas we want it to come back as foo = bar, foo = bar

Any hits and pointers would be highly appreciated. Thanks in advance.

Where you have these:

    SoapObject soap = (SoapObject)ks.getProperty(i);
    String tmp = soap.getProperty(0).toString();

You need to use these:

    SoapObject soap = (SoapObject)ks.getProperty(i);
    SoapObject tmp = soap.getProperty(0);
    String foo = tmp.getProperty(0).toString();

I see that you using complex type and you should use HttpTransportSE not AndroidHttpTransport is deprecated.

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM