
Hi All,
I am trying to send a Soap request via Javascript in Dynamics CRM 2016 online.
here is my JS:
var xmlhttp = new XMLHttpRequest();
//replace second argument with the path to your Secret Server webservices
xmlhttp.open('POST', 'www.test.com/.../testservice2.asmx', true);
var soapData = '<soapenv:Envelope xmlns:soapenv="schemas.xmlsoap.org/.../envelope" xmlns:hs="www.holidaywebservice.com/HolidayService_v2">'
+ '<soapenv:Body>'
+ '<hs:GetHolidaysAvailable>'
+ '<hs:countryCode>Canada</hs:countryCode>'
+ '</hs:GetHolidaysAvailable>'
+ '</soapenv:Body>'
+ '</soapenv:Envelope>';
xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xmlhttp.setRequestHeader('SOAPAction', 'http://www.testwebservice.com');
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
alert(xmlhttp.responseText);
}
};
//send the SOAP request
xmlhttp.send(soapData);
Response is always null for me. I tried the same in Postman i am able to get the response. But when I try the same via CRM Javascript i get NULL as reponse.
Regards,
Rahul
*This post is locked for comments
I have the same question (0)Hi,
First check your Soap XML string is valid or not. If its valid try using sending request using jQuery Ajax, refer below snippet.
var myServiceUrl = 'www.someurl.com/service.svc';
var mySoapXml = "mysoapxml";
$.ajax({
type: "POST",
url: myServiceUrl ,
contentType: "text/xml",
dataType: "xml",
data: mySoapXml,
success:function(data, status, req) {
if (status == "success")
alert(req.responseText);
},
error: function(data, status, req) {
alert(req.responseText + " " + status);
}
});