Search code examples
androidweb-servicesksoap

Ksoap calling Webservice - Problem with SoapObject


I am trying to call a WSDL Webservice via Ksoap for my Android App. When I use SoapPrimitive, it works and I get the following String:

{"INGREDIENTS": [
    {
        "TEXT": "ohne Schweinefleisch",
        "KEY": "*"
    },
    {
        "TEXT": "mit Alkohol",
        "KEY": "11"
    },

......

and so on.. I would like to have only the "Text" in a ListView, but I don't know how I can realize that with SoapPrimitive.

And when I use SoapObject, I only get the following Exeption:

"java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive cannot be cast to org.ksoap2.serialization.SoapObject"

Here is my Code:

 try {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet=true;
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION, envelope);

        SoapObject response = (SoapObject)envelope.getResponse();
        }

What's wrong? I looked since hours in the web, but i didn't find an answer.


Solution

  • Your response looks like a JSONArray of JSONObjects. You can parse it with built-in json library or use gson.