ksoap2 Android unexpected type in response
Asked Answered
S

1

6

Im trying to make a call to a java web service using ksoap2. I am using the ksoap2-android-assembly-2.6.5-jar-with-dependencies.jar and Android API level 8.

Activity Code:

private static final String SECURITY_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
private static final String USERNAME_TOKEN_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
private static final String PASSWORD_TYPE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    Element usernameElement = new Element().createElement(SECURITY_NAMESPACE, "Username");
    usernameElement.addChild(Node.TEXT, "username");
    Element passwordElement = new Element().createElement(SECURITY_NAMESPACE, "Password");
    passwordElement.setAttribute(null, "Type", PASSWORD_TYPE);
    passwordElement.addChild(Node.TEXT, "password");

    Element usernameTokenElement = new Element().createElement(USERNAME_TOKEN_NAMESPACE, "UsernameToken");
    usernameTokenElement.addChild(Node.ELEMENT, usernameElement);
    usernameTokenElement.addChild(Node.ELEMENT, passwordElement);

    Element securityElement = new Element().createElement(SECURITY_NAMESPACE, "Security");
    securityElement.setAttribute(null, "mustUnderstand", "1");
    securityElement.setPrefix(null, SECURITY_NAMESPACE);
    securityElement.addChild(Node.ELEMENT, usernameTokenElement);

    Element[] header = new Element[]{securityElement};

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.headerOut = header;
    envelope.setOutputSoapObject(request);

    HttpTransportSE httpTransport = new HttpTransportSE(URL);
    httpTransport.debug = true;

    try{
        httpTransport.call(SOAP_ACTION, envelope);
        SoapObject response = (SoapObject) envelope.getResponse();
    }catch (Exception e) {
        Log.e("Soap", e.getMessage(), e);
    }

When i make the call i get the following exception:

06-12 13:01:51.563: E/Soap(471): unexpected type (position:TEXT ������������U��n� ...@3:97 in java.io.InputStreamReader@44f5de78) 

06-12 13:01:51.563: E/Soap(471): org.xmlpull.v1.XmlPullParserException: unexpected type (position:TEXT ������������U��n� ...@3:97 in java.io.InputStreamReader@44f5de78)

Any ideas what could be causing this? Could it be something to do with character encoding, GZIP or incorrect soap version?

Any help would be greatly appreciated.

Thanks David

Swope answered 12/6, 2012 at 12:24 Comment(1)
Try to switch to SoapEnvelope.VER12 (instead of VER11).Jerold
P
1

I had same problem when i'm using ksoap2 2.6.5. I fixed that with ver. 2.5.4

Here : http://code.google.com/p/ksoap2-android/source/browse/m2-repo/com/google/code/ksoap2-android/ksoap2-android-assembly/#ksoap2-android-assembly%2F2.5.4

Partlow answered 3/7, 2012 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.