Android using ksoap calling PHP SOAP webservice fails: 'procedure 'CheckLogin' not found

Posted by AmazingDreams on Stack Overflow See other posts from Stack Overflow or by AmazingDreams
Published on 2012-11-04T13:29:27Z Indexed on 2012/11/04 17:01 UTC
Read the original article Hit count: 620

Filed under:
|
|
|
|

I'm trying to call a PHP SOAP webservice. I know my webservice functions correctly because I use it in a WPF project succesfully. I'm also building an app in android, using the same webservice.

The WSDL file can be found here: http://www.wegotcha.nl/servicehandler/service.wsdl

This is my code in the android app:

String SOAP_ACTION = "http://www.wegotcha.nl/servicehandler/CheckLogin";
        String NAMESPACE = "http://www.wegotcha.nl/servicehandler";
        String METHOD_NAME = "CheckLogin";
        String URL = "http://www.wegotcha.nl/servicehandler/servicehandler.php";
        String resultData = "";

        SoapSerializationEnvelope soapEnv = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        SoapObject UserCredentials = new SoapObject("Types", "UserCredentials6");
        UserCredentials.addProperty("mail", params[0]);
        UserCredentials.addProperty("password", md5(params[1]));

        request.addSoapObject(UserCredentials);
        soapEnv.setOutputSoapObject(request);

        HttpTransportSE http = new HttpTransportSE(URL);
        http.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        http.debug = true;

        try {
            http.call(SOAP_ACTION, soapEnv);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }

        SoapObject results = null;
        results = (SoapObject)soapEnv.bodyOut;

        if(results != null)
            resultData = results.getProperty(0).toString();

        return resultData;

Using fiddler I got the following: Android request:

<?xml version="1.0" encoding="utf-8"?>
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header />
<v:Body>
<n0:CheckLogin id="o0" c:root="1" xmlns:n0="http://www.wegotcha.nl/servicehandler">
<n1:UserCredentials6 i:type="n1:UserCredentials6" xmlns:n1="Types">
    <mail i:type="d:string">myemail</mail>
    <password i:type="d:string">myhashedpass</password>
</n1:UserCredentials6>
</n0:CheckLogin>
</v:Body>
</v:Envelope>

Getting the following response:

 Procedure 'CheckLogin' not present

My request produced by my WPF app looks completely different:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UserCredentials6 xmlns="Types">
    <mail>mymail</mail>
    <password>mypassword</password>
</UserCredentials6>
</s:Body>
</s:Envelope>

After googling my ass off I was not able to solve this problem by myself. It may be possible there are some weird things in my Java code because I changed a lot since. I hope you guys will be able to help me, thanks.

EDIT:

My webservice is of document/literal encoding style, after doing some research I found I should be able to use SoepEnvelope Instead of SoapSerializationEnvelope Though when I replace this I get an error before the try cache block, causing my app to crash.

Error:

11-04 16:23:26.786: E/AndroidRuntime(26447): Caused by: java.lang.ClassCastException: org.ksoap2.serialization.SoapObject cannot be cast to org.kxml2.kdom.Node

Which is caused by these lines:

request.addSoapObject(UserCredentials);
soapEnv.setOutputSoapObject(request);

This may be a solution though, how do I go about this? I found nothing about using a SoapEnvelope instead of a SoapSerializationEnvelope except for this awesome tutorial:

http://ksoap.objectweb.org/project/mailingLists/ksoap/msg00849.html

© Stack Overflow or respective owner

Related posts about php

Related posts about android