开发者

Weird response from Android soap service call

开发者 https://www.devze.com 2023-03-23 11:27 出处:网络
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.

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");
    req开发者_运维问答uest.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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号