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 :
Service | Customer Service, Contact Center, Fie...
Unanswered

Calling BC Web Service from D365 CRM Online Plugin

(0) ShareShare
ReportReport
Posted on by 165

I'm trying to call a web service from a D365 CRM Online plugin and I always get "The remote server returned an error: (500) Internal Server Error."

When I don't use SOAPAction as a header, it seems I am getting a kind of response from the server (I think it's the wsdl). But I know I should use the soapaction header.

Below is my code:

string rawXml = ""
                          ""
                              ""
                                  $"{serviceReceiptNo}"
                                  $"{serialNoName}"
                                  $"{itemNoName}"
                                  $"${caseNo}"
                              ""
                          ""
                          "";
                        
                    byte[] requestInFormOfBytes = System.Text.UTF8Encoding.UTF8.GetBytes(rawXml);
                        
                    string url = "http://***/Codeunit/ServiceMgt";
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    
                    request.Headers.Add("SOAPAction", "urn:microsoft-dynamics-schemas/codeunit/ServiceMgt:UpdateTicketNumber");
                    request.Method = "POST";
                    NetworkCredential myNetworkCredential = new NetworkCredential("***@***", "***");
                    request.Credentials = myNetworkCredential;
                    request.ContentType = "text/xml;charset=utf-8";
                    request.ContentLength = requestInFormOfBytes.Length;
                    Stream requestStream = request.GetRequestStream();
                    requestStream.Write(requestInFormOfBytes, 0, requestInFormOfBytes.Length);
                    requestStream.Close();

                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    if (response.StatusCode == HttpStatusCode.OK)
                    {

                        Stream responseStream = response.GetResponseStream();
                        string responseStr = new StreamReader(responseStream).ReadToEnd();
                        
                        tracingService.Trace("RESPONSE"   responseStr);
                    }

Any help would be greatly appreciated.

  • Pradeep Rai Profile Picture
    5,489 Moderator on at

    Hi,

    Just wanted to confirm BC refers the business central.

    if Yes, then i would suggest two ways.

    1. Using Web Service as described in below link

    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/webservices/authenticate-web-services-using-oauth

    Y
    ou can start from below point in above link.

    pastedimage1630866490430v1.png

    2. Instead of plugin, if possible then please check the power automate capability because in power automate we have the multiple Actions as shown below:

    pastedimage1630866587441v2.png

    Thanks,
    Pradeep.

    Please mark this as VERIFIED if it helps. 

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

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Travis South Profile Picture

Travis South 54

#2
11manish Profile Picture

11manish 37 Super User 2026 Season 2

#3
ParthPatel249 Profile Picture

ParthPatel249 33

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans