Hi,
I'm developing a web service that will connect to my Dynamics 365 instance. I've set up localhost as a valid web redirect URI, yet when I call my web service, I am still getting
No connection could be made because the target machine actively refused it 52.xxx.xxx.xx:443
Am I missing something obvious or do I need to publish this onto a server instead of localhost - despite what the docs say.
Specifically, I believe I'm referring to the Azure AD redirect but so that it works with the Dynamics CRM.
https://docs.microsoft.com/en-us/azure/active-directory/develop/reply-url
I want a separate Web service to communicate with my Dynamics 365 instance.
TIA
Any luck? Or can I give you anything further?
This is a screen shot of the AD page where our admins have added localhost for testing purposes.
I've done it two ways but the most recent version looks like this:
Get Token Code
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("resource", Resource),
new KeyValuePair<string, string>("client_id", ClientId),
new KeyValuePair<string, string>("client_secret", ClientSecret),
new KeyValuePair<string, string>("grant_type", "client_credentials")
});
HttpResponseMessage response = await httpClient.PostAsync(Authority, formContent);
return !response.IsSuccessStatusCode ? null
: response.Content.ReadAsStringAsync().Result;
Web Service Call
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(Resource);
httpClient.Timeout = new TimeSpan(0, 2, 0);
httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", _accessToken);
//Retrieve
HttpResponseMessage retrieveResponse =
await httpClient.GetAsync($"api/data/v8.2/entityName?$select=fieldName&$filter=contains(fieldName,'{sParameter}')");
if (retrieveResponse.IsSuccessStatusCode)
{
JObject jRetrieveResponse =
JObject.Parse(retrieveResponse.Content.ReadAsStringAsync().Result);
JObject row = (JObject)JArray.Parse(jRetrieveResponse["value"].ToString())[0];
string sGuid = row["core_fc_profileid"].ToString();
sURL = string.Format("{0}/main.aspx?etn={1}&pagetype=entityrecord&id=%7B{2}%7D",
"CRM URL", "core_fc_profile", sGuid);
}
else
{
var result = await retrieveResponse.Content.ReadAsStringAsync();
}
return sURL;
}
The original code was more like:
DataCollection<Entity> retrievedFile =
CRMCommonTools.OrgConnection.RetrieveMultiple(queryQueuePrivileges).Entities;
if (retrievedFile.Count == 1)
{
sCaseFileID = retrievedFile[0].Id.ToString();
return sCaseFileID;
}
else
throw new Exception(String.Format("Cannot find unique File for ID = {0}", sCaseFileName));
}
All of them cause the same problem but all WORK when called from a Windows/desktop app.
Hi akselsoft,
Could you provide the code you used?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,522 Super User 2024 Season 2
Martin Dráb 228,441 Most Valuable Professional
nmaenpaa 101,148