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


Ask by : AmazingDreams November 04, 2012 16:57

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

View original question

Answer by : AmazingDreamsNovember 04, 2012 16:57

Some weird stuff just happened. I simply removed the a line (which I did thousands of times) tweaked the rest a little bit since I got some new errors and I got the following code working:

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 UserCredentials = new SoapObject("Types", "UserCredentials6");
UserCredentials.addProperty("mail", params[0]);
UserCredentials.addProperty("password", md5(params[1]));

// changed these lines
// request.addSoapObject(UserCredentials);
// soapEnv.setOutputSoapObject(request);
// into:
soapEnv.setOutputSoapObject(UserCredentials);

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

// little tweak here        
String results = null;
try {
    http.call(SOAP_ACTION, soapEnv);
    //another tweak here
results = soapEnv.bodyIn.toString();
} catch (IOException e) {
    e.printStackTrace();
} catch (XmlPullParserException e) {
    e.printStackTrace();
}

if(results != null)
    resultData = results;

return resultData;

And now I am able to login correctly :) They are not very functional workarounds as this is the only place where I'll get back a yes or a no. Think array's of complextypes and the like. But that's another story.

View original answer