来自Android soap服务电话的奇怪回应

时间:2011-07-27 11:49:12

标签: java android return-value

我们有一个Android应用程序,我们正在尝试用于Web服务通信。

我们可以使用以下代码段成功发送请求并获得回复。

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);
    }


 }

现在,textView.setText(tmp);中显示的请求的响应显示响应如下:

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

我们希望它以foo = bar, foo = bar

的形式返回

任何点击和指针都将受到高度赞赏。提前谢谢。

1 个答案:

答案 0 :(得分:2)

你有这些:

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

你需要使用这些:

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

我发现您使用的是复杂类型,您应该使用HttpTransportSE而不是AndroidHttpTransport已被弃用。

希望有所帮助