Amit Soni
Amit Soni

Reputation: 41

KSoap2 is not returning valid 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>

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

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

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?

Upvotes: 1

Views: 129

Answers (1)

Amit Soni
Amit Soni

Reputation: 41

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.

Upvotes: 2

Related Questions