I’m  creating a Windows 10 Universal Phone App that talks to a Web Service to post an entity (object) in Microsoft SQL Server running on the same machine as the Web Service. Initially did all including the app on my laptop using localhost as the network target. Solved the SQL Server credentials .. OK. But when I switch to using the laptop’s system name or its IP address (all still running on same machine) got Network Access Required error.

 

At the point of calling the Web Service things fail:

Exception thrown: 'System.UnauthorizedAccessException' in MyApp.exe
WinRT information: A network capability is required to access this network resource
Error: Access is denied.

A network capability is required to access this network resource ErrorMessage

 

I spent time adding authentication to the Web Service call thinking (obviously not clearly) that it was an authentication at the web service issue:

  • I first tried by setting the web config to <authentication mode="None" />
  • That didn’t solve things so I tried adding authentication at the app end:
            httpClient = new HttpClient();
            string username = "name@biz.com.au";
            string password = "p@ssw0rd”
            var buffer = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary
(username + ":" + password, Windows.Security.Cryptography.BinaryStringEncoding.Utf16LE); string base64token = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(buffer); httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("Basic", base64token);

Ref: https://msdn.microsoft.com/en-us/library/windows/apps/windows.web.http.headers.httpcredentialsheadervalue.aspx

 

Still no joy when I tried this ..same. Then it occurred to me its a UWP Capabilities issue. Need to edit Package.appxmanifest file.
So I enabled:

[ ] Internet (Client) and

[ ] Internet (Client & Server)

 

Still no joy!

 

What was needed was to enable

[ ] Private Networks (Client & Server)

as my latop is running on a Private network

 

Wala ..that worked Smile

 

image

 

I’ll leave the authentication and the Public Network capabilities as they will probably be needed when I do a complete remote installation

 

AND IT ALL WORKS WHEN THE APP RUNS ON MY PHONE OVER WiFi! Smile 
(Web Service and SQL Server on Laptop)

 

Cheers, hope this helps someone,

 

Also read (next blog) : Microsoft SQL Server Credentials for a Remote Web Service