System.Net.WebException: Unable to connect to Remote Server - Server in LAN only

13,816

I'm assuming that this is a store app. Bearing this in mind, it looks like your app doesn't have permission to access the network.

If you take a read of App capability declarations (Windows Runtime apps), you'll see:

While you’re developing and testing your Windows Phone Store app app in Visual Studio, you get the networking capability (Internet (Client & Server)) when you run the app, even if you haven’t specified this capability in the app manifest file. When you publish your app, however, your app does not automatically get the networking capability. Make sure you check the Internet (Client & Server) capability on the Capabilities page of Manifest Designer if your app requires network connectivity.

You'll need to add one of the network permissions to the app Capabilities in the app manifest.

Share:
13,816
danielP
Author by

danielP

Updated on June 04, 2022

Comments

  • danielP
    danielP almost 2 years

    In order to develop a Windows Universal App for my company, I need to connect to our local webserver. To test this, I have a xampp installation on my dev machine, which I used to develop around 5 applications for some Windows CE devices with no problems so far. Now we want to use Tablets too, for very specific Usecases.

    My first ModernUI app's only purpose is to send a WebRequest to the Server and display the response in a TextBox with this Code I'm using:

        public async Task<string> Request(string uri)
        {
            WebRequest request = WebRequest.Create(uri);
            request.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string responseFromServer = reader.ReadToEnd();
            return responseFromServer;
        }
    

    If I run this app locally on my machine (with webserver being localhost), everythings works fine. But if I run it on the tablet, I get the following Exception:

    System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: Der Zugriff auf einen Socket war aufgrund der Zugriffsrechte des Sockets unzulässig 10.0.0.146:80 (Translation: Access to a socket was forbidden by its access permissions for the socket)

    at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)\r\n at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)\r\n --- End of inner exception stack trace ---\r\n at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\r\n at WaWiDemoWin8.ServerRequest.<Request>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\r\n at WaWiDemoWin8.MainPage.d__0.MoveNext()"

    Please be aware, that the access to the webserver by browser is possible and if I download an online webpage like google.com it works just fine (from the tablet). I even installed a new webserver on a different machine to test this, but only get the same Exception, when I try to access this webserver in our LAN.

    I hope, someone can give a solution or a hint at least, because I really have no clue, what the problem is causing. If you need further information, just tell me and I will provide them asap.

    Thank you, Daniel