My Android program has to scan 255 LAN addresses to find if an OData service (WCF Data Service) is available.
The service runs on 1 or 2 computers, there are about 20 devices on the LAN but when my code "scans" an IP address that is in use BUT not hosting the service it doesn't throw exception immediatley instead it waits for a long time so finding 2 addresses took 10 minutes.
Here is the code:
try
{
String url = String.format("http://%s/InformationService/InformationService.svc/", ip);
ODataConsumer consumer = ODataJerseyConsumer.create(url);
Enumerable<OObject> result= consumer.callFunction("CheckInformation")
.execute();
Log.i("DEBUG", "Service available: " + ip);
}
catch (Throwable e)
{
//e.printStackTrace();
Log.i("DEBUG", "No service: " + ip);
}
Why does it wait at the reserved IPs if the service is not hosted there?
How can I detect immediately if there is no service there?
First thing i would say is that just to check url's availability, you need not make a call to service method.
And then from your post it's not clear that,
whether you ONLY want to check if svc(wcf) exists on the given url(on specific IP)
OR
you also want to check that if wcf exits there, is it available to take calls?
In any case, if you refer these 2 links on SO itself, i feel you would certainly get what you are looking for.
Note: I have not done this kind of checks on android anytime, but in general when you want to check if a wcf (or any web url is valid one like check if svc exits there on a url), then you can simply make a web get request for the web url(not just wcf svc ones) and if you get response with valid http status, then it's valid url.