KSoap2没有返回有效的XML? [英] KSoap2 is not returning valid xml?

查看:322
本文介绍了KSoap2没有返回有效的XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Web服务的XML数据。 XML数据是这样的。

I am trying to get an xml data from web service. The xml data is like this

<Result>
<ErrorCode>0</ErrorCode>
<ErrorMessage>Login was succesful.</ErrorMessage>
<AuthCode>maneen90234</AuthCode>
</Result>

但我从KSOAP 2获得我是以下字符串

But what i am getting from KSoap 2 is the following String

anyType{Result=anyType{ErrorCode=1; ErrorMessage=Incorrect Username or Password; };

这是怎么了调用Web服务

These is how I am calling web service

private String callAPI(String user, String password) {
        request = new SoapObject(NAME_SPACE, "UserLogin");
        PropertyInfo pi = new PropertyInfo();
        addProperty(pi, request, "UserId", user, String.class);
        addProperty(pi, request, "Password", password, String.class);
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);

        androidHttpTransport = new HttpTransportSE(url);

        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            response = envelope.getResponse().toString();
        } catch (Exception exception) {
            response = exception.toString();

        }
        return response;
    }

    private void addProperty(PropertyInfo pi, SoapObject request, String UserId, String value, Object type) {
        pi = new PropertyInfo();
        pi.setName(UserId);
        pi.setValue(value);
        pi.setType(type);
        request.addProperty(pi);
    }

我曾尝试对苏提供的各种答案,都无济于事。任何想法,我究竟做错了什么?

I have tried various answers available on SO, to no avail. Any idea what am I doing wrong here?

推荐答案

它看起来像ksoap2是解析数据本身并返回数据的属性。我提取数据,如如下: -

It looks like that ksoap2 is parsing the data itself and returning the properties of the data. I am extracting the data like as follows -

SoapObject response = (SoapObject) ((SoapObject)envelope.getResponse()).getProperty(0);
 if(response.getProperty("ErrorCode").equals(1))
        {
            Toast.makeText(context,"Login sucessful",Toast.LENGTH_LONG).show();
            Log.d(TAG, String.valueOf(response));
        }
        else {
            Toast.makeText(context,"ErrorCode",Toast.LENGTH_LONG).show();
            Log.d(TAG, String.valueOf(response));
        }

虽然我仍然遇到了传递参数的一个问题,但我会后单独的问题,对于相同的。

Although I am still experiencing an issue over passing parameters, but I'll post separate question for the same.

这篇关于KSoap2没有返回有效的XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆