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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Call web service from new Web API Javascript

(0) ShareShare
ReportReport
Posted on by 510

Hi guys.

Is there any different new way to call an external web service from a web resource javascript file using the new web api?

Regards.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    You can call external web servisce using jQuery Ajax (api.jquery.com/jquery.ajax) or directly XmlHttp request (www.w3schools.com/.../xml_http.asp or developer.mozilla.org/.../XMLHttpRequest), it's not related Dynamics CRM Web API

  • HenriquePalomo Profile Picture
    510 on at

    Ok, thanks Emre.

    Actually I'm using XmlHttp, but I thought that something could be broken or deprecated because of the update to V9, but I didn't found any articles about that as well.

    So thanks for the answer.

    Regards.

  • Suggested answer
    Emre GULCAN Profile Picture
    2,379 on at

    Hi Henrique,

    D365 v9 has some changes and deprecated methods on Xrm client API, but not related how can you use / call external webservices.

    If you get any exception when using XmlHttp please inform me about your exception maybe I can help you.

  • HenriquePalomo Profile Picture
    510 on at

    Hi Emre. Thanks for the repsonse.

    Im getting bad request, but actually i tried to call the web service from SOAPUI and it worked like a charm, the problem is to call the WS inside the JavaScript

  • Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    Please share your code. If you get "bad request" it's Http 400 and probably you try to wrong method to call your external webservice (for exp: GET or POST) or your request object (payload) is not correct or not serialized correctly.

  • HenriquePalomo Profile Picture
    510 on at

    var url = "xxxxxxxx.azurewebsites.net/.../xxxxxxx.svc;;

           var xhr = new XMLHttpRequest();

           xhr.open("POST", url, true);

           //var xhr = createCORSRequest('POST', url);

           if (!xhr) {

               throw new Error('CORS not supported');

           }

           else {

               var text =

                   "<s:Envelope xmlns:s='schemas.xmlsoap.org/.../&;>" +

                   "<s:Header>" +

                       "<Action s:mustUnderstand='1' xmlns='schemas.microsoft.com/.../none&;> tempuri.org/.../SearchAddress </Action>" +

                   "</s:Header>" +

                   "<s:Body>" +

                       "<SearchAddress xmlns='http://tempuri.org/&#39;>" +

                   "<searchAddress>asd</searchAddress>" +

                       "</SearchAddress>" +

                   "</s:Body>" +

                   "</s:Envelope>";

               //parser = new DOMParser();

               //var xmlDoc = parser.parseFromString(text, "text/xml");

               xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

               xhr.setRequestHeader('SOAPAction', 'tempuri.org/.../SearchAddress&;);

               xhr.onload = function (response_) {

                   var responseText = xhr.responseText;

                   console.log(responseText);

                   alert('Got Results');

               };

               xhr.onerror = function () {

                   console.log('There was an error!');

                   alert('Bad request');

               };

               xhr.send(text);

  • Emre GULCAN Profile Picture
    2,379 on at

    Hi,

    Your first/main problem is you don't get exception details on your request "onerror", maybe your url is not reachable or your payload is not correct.

    Please look at this pages

    https://stackoverflow.com/questions/124269/simplest-soap-example 

    https://thycotic.force.com/support/s/article/Using-Web-Services-with-SOAP-Javascript

    and important point is here;

    if (this.status === 204) {
       //success
    } else {
       //exception
       var exceptionDetails = this.statusText;
    }


    "this.statusText" gives you more details

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans