Notifications
Announcements
No record found.
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
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
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.
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.
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
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.
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/'>" +
"<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);
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2