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

  • akselsoft Profile Picture
    10 on at
    RE: Testing WebAPI via RedirectURL

    Any luck? Or can I give you anything further?

  • akselsoft Profile Picture
    10 on at
    RE: Testing WebAPI via RedirectURL

    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
    RE: Testing WebAPI via RedirectURL

    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.

  • Community Member Profile Picture
    on at
    RE: Testing WebAPI via RedirectURL

    Hi akselsoft,

    Could you provide the code you used?

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans