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.exeWinRT information: A network capability is required to access this network resourceError: 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:
httpClient = new HttpClient();
string username = "email@example.com";
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);
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
I’ll leave the authentication and the Public Network capabilities as they will probably be needed when I do a complete remote installation
Cheers, hope this helps someone,
Also read (next blog) : Microsoft SQL Server Credentials for a Remote Web Service