I have problem consuming a WCF REST service in my android application.
The client keeps throwing UnknownHostException.
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet("http://windows");
ResponseHandler<String> handler = new BasicResponseHandler();
String result = httpclient.execute(request, handler);
WCF service is hosted on IISExpress (http://windows:80) and it works localy in the browser as well as in remote box in same LAN (where I am developing ANDROID client).
Android permissions are OK in the manifest and I have tried HttpGet on google.com and it works OK.
Can some one please explain, why android cant open connection to (http://windows:80) thats hosted on remote computer in LAN over IISExpress, while the browser opens it (on both computers) with no problem?
Thank you.
If you’re on Windows, most likely your desktop can access http://windows because it has a default domain postfix / search scope which is returning the fully qualified domain name “windows.x.x”, where x.x = your internal domain. Alternatively it might be resolving the host using WINS.
The android or android emulator likely doesn’t have the same DNS search scope / postfix, so you’d have to supply the FQDN (fully qualified domain name, i.e. windows.yourdomain.com).
Use a DNS query tool like “nslookup” (windows) or “dig” / “host” (linux) to verify that the DNS server the android or android emulator is trying to use:
Example for Windows
Use “ipconfig /all” to find your DNS server and DNS domain postfix…
From above, we can see that our DNS domain is “mydomain.com” and our primary DNS server is “192.168.42.6”. The DNS server should be able to resolve “windows.mydomain.com” (or whatever your domain is in this case).
Verify your server can resolve the fully qualified hostname:
(replace 192.168.42.6 with your DNS server)
You should get something like this (assuming in my case that windows registered with the DHCP and DNS server(s) as 192.168.42.106:
If you get an invalid response like…
*** dns01.mydomain.com can't find windows: Non-existent domainThen the host you’re looking for isn’t in the DNS domain that you supplied, so there might be a mismatch between default DNS domain and DHCP for your android / emulator.
Alternatively you could just use the IP address directly, as mentioned above.