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.

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 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,812 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,812 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,698 Moderator on at

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

  • Suggested answer
    YUN ZHU Profile Picture
    103,811 Super User 2026 Season 2 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 768 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 541 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 324 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans