Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Unanswered

Calling BC Web Service from D365 CRM Online Plugin

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
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    RE: Calling BC Web Service from D365 CRM Online Plugin

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans