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,
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
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);
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.
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
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.
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,
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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156