0

I have a device on Windows Mobile. The device have an access to the internet via WI-FI. I've tried to make a code to get response via Internet with WebHttpRequest and WebHttResponse.

string url = "http://172.20.24.83:80/ProductRESTService.svc/GetProductList/";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Method = "GET";
        req.ContentType = "application/xml; charset=utf-8";
        req.Timeout = 300000000;
        req.Headers.Add("SOAPAction", url);

        HttpWebResponse response = (HttpWebResponse)req.GetResponse();

It works fine on Emulator. Unfortunately I have an exception:

Could not establish connection to network on the device only

The device can get an access to the internet via browser, but I can't do it via code.

Do you have any ideas?

Eugene Rotar
  • 83
  • 1
  • 2
  • 9

1 Answers1

0

Although you say you can access the internet, is that the same private internet as the IP 172.20.24.83 is part of a private internet:

Private Internet Addresses:
10.0.0.0/8 IP addresses: 10.0.0.0 -- 10.255.255.255
172.16.0.0/12 IP addresses: 172.16.0.0 -- 172.31.255.255
192.168.0.0/16 IP addresses: 192.168.0.0 – 192.168.255.255

The question is, can your device's browser connect to 172.20.24.83?

I assume your PC is on the 172.16.0.0/12 network too, so the emulator is part of your PC and is also connected to this network. But to which network is your device connected to when using the WiFi connection?

This may be a routing (different subnets) or switch/firewall issue.

Take a look at Start>Settings>Connections>WiFi and select the active WiFi adapter. This will show details about the IP address, subent etc of the WiFi connections. You may also use my NetStatCF to find out the details of the connection.

josef
  • 5,951
  • 1
  • 13
  • 24
  • I can connect to the 172.20.24.83 via Internet Explorer Browser. Entering the http://172.20.24.83:80/ProductRESTService.svc/GetProductList/ gives me the response on browser. Unfortunately I can't do it via code. To be honest I have no ideas how to solve that – Eugene Rotar Apr 21 '16 at 08:05
  • Then try with a simple webrequest without req.ContentType = "application/xml; charset=utf-8"; req.Timeout = 300000000; req.Headers.Add("SOAPAction", url); That is what the Internet Explorer does – josef Apr 23 '16 at 06:02
  • The same error. May my application(or an access to the internet) be blocked by something? – Eugene Rotar Apr 25 '16 at 12:36
  • You may run MS NetAnalyzer (https://www.microsoft.com/en-us/download/details.aspx?id=19484) on the device and compare the network traces when entering the URL in 'Internet Explorer Mobile' and running your code. You may post the network traces as attachment, if you can not read them. – josef Apr 26 '16 at 06:14