Home Ask Login Register

Developers Planet

Your answer is one click away!

qiTsuk February 2016

Consuming Simple WCF from Android

I am writing a simple app, that needs to verify login details through a MySQL database. I specifically cannot use PHP, so I opted for the WCF service model. Now, I have the WCF working through my browser. All of the get methods are working in my browser and returns the desired JSON output, but for good order, I will post the Service Interface;

    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getUserAuthenticated/{value1}/{value2}")]
    bool GetUserAuthenticated(string value1, string value2);

    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getIsUserModel/{value}")]
    bool GetIsUserModel(string value);

    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getIsUserActive/{value}")]
    bool GetIsUserActive(string value);

As stated, this works. But when trying to consume the service from my app like so;

    public void UserAuthenticated(String email, String password) {
        try {
            URL url = new URL("" + email + "/" + password);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();

            Log.d("Response Code: ", "" + httpURLConnection.getResponseCode());
            InputStream in = new BufferedInputStream(httpURLConnection.getInputStream());
            String response = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
            Log.d("Response String: ", response);

        } catch (MalformedURLException mue) {
        } catch (IOException ioe) {



qiTsuk February 2016

So I solved it. What I did was;

  1. I opened the port I was attempting to connect on in Windows Firewall. In my case 8008. I opened it both for outgoing and ingoing traffic.
  2. I installed IIS Express, and set up a local page on the IP that my workstation has.
  3. After a lot of rumaging about on the interwebz, and here on Stack Overflow, I found other who had problems connecting to local IIS addresses through Genymotion, even using the standard IP for localhost, From another thread here on SO I found this guide;


Turns out, I had to port forward the device. And now it is working. I can now connect to my WCF service through my Genymotion emulator on my workstations IP at port 8008.

I hope this helps someone.


Post Status

Asked in February 2016
Viewed 3,324 times
Voted 12
Answered 1 times


Leave an answer

Quote of the day: live life