0

can anybody guide me to a tutorial or a working example of connecting android to a php web service using ksoap2 or something else?

Jesper
  • 202,709
  • 46
  • 318
  • 350
user1157662
  • 3
  • 2
  • 3
  • possible duplicate of [REST and SOAP webservice in android](http://stackoverflow.com/questions/6929180/rest-and-soap-webservice-in-android) – Mark B Jan 19 '12 at 15:39

1 Answers1

0

Im using my PHP-Webservice this way:

Java:

// params => "?action=getInfos"
private JSONObject getJSONObject(String params)
{
    try
    {
        String url = path2webservicephp + params;

        System.out.println("Call URL: " + url);

        HttpGet request = new HttpGet(url);

        request.setHeader("Content-Type", "text/xml;charset=UTF-8");

        DefaultHttpClient httpclient2 = new DefaultHttpClient();

        HttpResponse response = httpclient2.execute(request);

        if (response.getStatusLine().getStatusCode() != 200)
            throw new ConnectionException("Status Code is " + response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase());

        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String line = reader.readLine();

        MyConstants.RECEIVEDBYTES += line.length();

        reader.close();
        if ("[]".equals(line))
            return null;
        return new JSONObject(line);
    }
    catch (Exception e)
    {
        LLog.e(Webservice.class, "Exception! params: " + params);
        LLog.e(e, Webservice.class);
    }
    return null;
}

// LLog.e is from my own class. It logs to Log.e and into a file

PHP:

$array = array('status' => 'ok', 'message' => 'your action was: '.$_GET['action']);
echo json_encode($array);
PKeidel
  • 2,559
  • 1
  • 21
  • 29
  • this returns the wsdl , does not call the method and get back the results. – user1157662 Jan 20 '12 at 02:46
  • My webservice does what I had written in PHP and gives me a response for his "work". I tried it with ksoap2 but writing an own with JSON was simpler for me. (Because I hate XML...) And it made a lot of fun combined with a big "learn effect". – PKeidel Jan 20 '12 at 18:26
  • dude, i know you are right. but the thing is that , the method isn't getting called at all. for me the response is a xml string but it just returns the wsdl instead, also to note my web service is written with help of Yii php framework...i am even ready for JSON , if it works for the call. – user1157662 Jan 20 '12 at 19:29
  • finally got hold of it `You require TCP MON and port 8080->80 to be mapped and you can see the response private static final String NAMESPACE = "urn:MobileAppControllerwsdl"; private static final String URL = "http://10.0.2.2:8080/eventorbit/eo/mobileapp/mobile?ws=1"; private static final String SOAP_ACTION = "urn:MobileAppControllerwsdl#getQuote"; private static final String METHOD_NAME = "getQuote";` rest is pretty much the same....without the port mapping it hangs in runtime – user1157662 Jan 21 '12 at 21:26