'System.AggregateException' when attempting to connect to my Common Data Service web api

0

Here is my code:

string url = "https://myOrg.api.crm.dynamics.com";
string apiVersion = "9.1";
string webApiUrl = $"{url}/api/data/v{apiVersion}/";
var authParameters = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(webApiUrl)).Result;

My last line of code is failing with: enter image description here

The ouput is:

MyAPITest.vshost.exe Error: 0 : 11/05/2019 19:20:17: - AuthenticationParameters: System.ArgumentException: Unauthorized Http Status Code (401) was expected in the response Parameter name: response Exception thrown: 'System.AggregateException' in mscorlib.dll The program '[5556] MyAPITest.vshost.exe' has exited with code -1 (0xffffffff).

For reference, I am attempting to use the Quick Start Guide to connect to the Common Data Service.

EDIT: In looking at the details I am seeing: enter image description here

Error

The underlying connection was closed: An unexpected error occured on a send.

More detail beneath that error:

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

c#
api
cds
asked on Stack Overflow Nov 5, 2019 by B-Rad • edited Nov 6, 2019 by B-Rad

2 Answers

0

AuthenticationParameters: System.ArgumentException: Unauthorized Http Status Code (401) was expected in the response

The error is typically because it's lacking valid authentication credentials and the request has not been applied for the target resource.

Also if you don't know, the AuthenticationParameters.CreateFromResourceUrlAsync API is obsolete, read more there.

With this in mind, I would look into using AuthenticationParameters.CreateFromUrlAsync(Uri) Method in which should be used. It sends a GET request to the url provided with no Authenticate header. If a 401 Unauthorized is received, this helper will parse the WWW-Authenticate header to retrieve the authority and resource.

answered on Stack Overflow Nov 5, 2019 by zaggler
0

Here was the problem, found in the guide:

enter image description here

I am running VS 2015. Once I unchecked this, it worked perfectly.

answered on Stack Overflow Nov 18, 2019 by B-Rad

User contributions licensed under CC BY-SA 3.0