0

I'm doing a tiny code to get if it can connect or not to a database. I have several codes like this working, but I don't know why I can't figure out why is this not working.

The exception is the following:

10-24 06:09:08.362: E/Exception:(1753): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG (empty) <br>@1:7 in java.io.InputStreamReader@4176d928) 

Java code:

private final String NAMESPACE = "http://10.0.0.47/fullexample/server.php/";
private final String URL = "http://10.0.0.47/fullexample/server.php";
/*
....
*/
private class get_connectivity extends AsyncTask<String, Integer, String> {
    @Override
    protected String doInBackground(String... params) {
        try{
            SoapObject request = new SoapObject(NAMESPACE, "can_connect");  

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            androidHttpTransport.call(URL + "/can_connect", envelope);
            return "done";
        }catch (Exception e){
            Log.e("Exception:", e.toString());
        }
        return "not done";
    }

    @Override
    protected void onPostExecute(String result) {
        // got_connection = it's a global string variable
        got_connection = result;
    }
}

And the function can_connect (in PHP webservice) is just the following:

function can_connect(){ 
    $host = "localhost";
    $user = "root";
    $database = "fullexampleDB";
    $pwd = "";

    $db = new mysqli($host, $user, $pwd, $database);
    if ($db->connect_errno) {
        return false;
        exit();
    }   
    $db->close();
    return true;
}

I'm always receiving the message "not done" as well. Thanks.

1 Answer 1

1

SOAP uses XML for it's messages. So when a response is received in Android, the SoapSerializationEnvelope object tries to parse it, expecting it is XML. I'm not entirely sure what your web service returns, but it must be in correct XML format, and it's not at the moment.

Because of this exception (which occurs every time), you always get the "not done" result.

To solve this problem, either make sure your PHP service responds in a correct XML format, or don't use SOAP to call the service.

Sign up to request clarification or add additional context in comments.

2 Comments

You're not helping me much. I have like 10 functions which retrieves correctly the values from the PHP service, I just can't figure out why this one doesn't work.
Well, I'm describing exactly what's wrong. Can you post the full stacktrace so we can see where it fails exactly? Also, can you show an implementation of the other funtions that do work correctly? Maybe we can spot a difference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.