web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Testing WebAPI via RedirectURL

(0) ShareShare
ReportReport
Posted on by 10

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

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi akselsoft,

    Could you provide the code you used?

  • akselsoft Profile Picture
    10 on at

    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.

  • akselsoft Profile Picture
    10 on at

    This is a screen shot of the AD page where our admins have added localhost for testing purposes.

    Dynamics-Configuration.png

  • akselsoft Profile Picture
    10 on at

    Any luck? Or can I give you anything further?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 46 Most Valuable Professional

#2
Pallavi Phade Profile Picture

Pallavi Phade 33

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 28 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans