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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Dynamics 365 BC -SOAP service OAuth Authentication

(0) ShareShare
ReportReport
Posted on by 18

Hello,

Today, I am using SOAP service to Integrate expense reports to Dynamics 365 BC Purchase Invoice.

I have used basic authentication like below

ICredentials credentials = new NetworkCredential(userName,password);

bcService.Credentials = credentials;

bcService.Create(ref purchaseInvoice);

Now I want to use OAuth Authentication while creating a purchase invoice.

Please suggest how can I use OAuth Authentication for the SOAP service to integrate data to Dynamics 365 BC.

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,786 Moderator on at

    Hi Narayan,

    Please use below link to learn how to generate and use OAuth.

    navwithnav.blogspot.com/.../oauth20-token-authentication-with-al.html

    Thanks.

  • Miscrosoft Dynamcis GP Profile Picture
    18 on at

    Hello Nitin,

    Thanks for the reply.

    I am using the below code to integrate to Purchase Invoice using SOAP web service and auth authentication. AuthTocket  tocken return successfully from my another function and I am passing Purchase Invoice object and Tocken to the below code.

    var myContent = JsonConvert.SerializeObject(purchaseInvoice);

                   var buffer = System.Text.Encoding.UTF8.GetBytes(myContent);

                   var byteContent = new System.Net.Http.ByteArrayContent(buffer);

                   byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                   using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())

                   {

                       client.DefaultRequestHeaders.Add("Authorization", "Bearer " + AuthToken);

                       var result = client.PostAsync(dynamicsWebServiceURL, byteContent).Result;

                       if (result.IsSuccessStatusCode)

                       {

                           Console.WriteLine(result.Content.ReadAsStringAsync().Result);

                       }

                   }

    But, for the highlighted line, I am getting error as below.

    {StatusCode: 415, ReasonPhrase: 'Unsupported Media Type', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
    {
    Transfer-Encoding: chunked
    Access-Control-Allow-Headers: Origin, X-Requested-With, Authorization
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Credentials: true
    ms-correlation-x: e46003d6-1968-4e51-88e2-92e01abde14b
    x-content-type-options: nosniff
    Strict-Transport-Security: max-age=31536000; includeSubDomains
    Access-Control-Expose-Headers: ms-correlation-x
    Date: Mon, 09 May 2022 11:25:18 GMT
    Server: Microsoft-HTTPAPI/2.0
    }}

    Could you please help to resolve this error?

  • Suggested answer
    Nitin Verma Profile Picture
    21,786 Moderator on at

    Hi,

    Please go through the below link, I think it will solve your problem. there is an easy steps been demonstrated.

    navwithnav.blogspot.com/.../oauth20-token-authentication-with-al.html

  • Miscrosoft Dynamcis GP Profile Picture
    18 on at

    Hi,

    Thanks.

    I have checked the code in the video and I am able to get records from BC successfully, but I have a issue in the post method.

    Do we have demo where we can check the Post method code of OAuth authentication using SOAP web service.

  • Suggested answer
    Nitin Verma Profile Picture
    21,786 Moderator on at

    Hi,

    Can you please re-use as per below?

     gbodyContent := StrSubstNo('access_token_url=%1&client_id=%2&client_secret=%3&grant_type=%4&scope=%5', AadTenantId, ClientIdTxt, ClientSecretTxt, 'client_credentials', ScopeId);

           gHttpcontent.WriteFrom(gbodyContent);

           gHttpcontent.GetHeaders(gHttpheaders);

           gHttpheaders.Remove('Content-Type');

           gHttpHeaders.Add('Content-Type', 'application/x-www-form-urlencoded');

           if gHttpclient.Post('login.microsoftonline.com/' + AadTenantId + '/oauth2/v2.0/token', gHttpcontent, ghttpResponseMessage) then begin

               ghttpResponseMessage.Content.ReadAs(gresponseText);

               gJSONToken.ReadFrom(gresponseText);

               gJSONObject := gJSONToken.AsObject();

               AccessToken := GetJSONToken(gJSONObject, 'access_token').AsValue().AsText();

           end else

               Error(FORMAT(ghttpResponseMessage.Content));

  • Steven Renders Profile Picture
    5,682 Moderator on at

    Suggestion: don't use SOAP, use the Rest API's instead.

  • Suggested answer
    YUN ZHU Profile Picture
    98,064 Super User 2026 Season 1 on at

    Hi, just adding Steven's reply.

    The capability of exposing SOAP endpoints will be removed in a later release.

    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/upgrade/deprecated-features-platform#soap-endpoints-warning

    pastedimage1652142310017v1.png

    Hope this also helps.

    Thanks.

    ZHU

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,032 Super User 2026 Season 1

#2
Dhiren Nagar Profile Picture

Dhiren Nagar 1,049 Super User 2026 Season 1

#3
YUN ZHU Profile Picture

YUN ZHU 1,029 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans