Answered by:
Calling External Webservice

Question
-
Hi,
I am calling a webservice hosted on the same server as ms crm 2013 server by using javascript. below is the code. But, it fails giving bad request error.
Any help could be highly appreciated. Please.
function Callwebservice()
{
var serviceurl = "asd0098.qwe.zxc.local/.../Service.svc"; var functionname=" CreateRecord()";
var attributenames = ["time", "id"]; var attrValue = [period, sid];
var CallingFunctionURL = serviceurl +"/"+ functionname; var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='schemas.xmlsoap.org/.../&"xmlns:xsi='www.w3.org/.../XMLSchema-instance& +
"xmlns:xsd='www.w3.org/.../XMLSchema&"<soap:Body>" + "<" + functionname + " xmlns=\'"+ serviceurl +"'>";
alert(attributenames.length); for (i = 0; i< attributenames.length; i++) {
xml = xml + "<" +attributenames[i] + ">" + attrValue[i] + "</" +attributenames[i] +">";
}
xml = xml + "</" +functionname + ">";xml = xml +"</soap:Body></soap:Envelope>";
try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { xmlHttp= new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { try { xmlHttp = new XMLHttpRequest(); }
catch (e) { xmlhttp = false; }}}
if (!xmlHttp) return null;
xmlHttp.open("POST", serviceurl, true);
xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
xmlHttp.setRequestHeader("Content-Length",xml.length);
xmlHttp.setRequestHeader("SOAPAction",uri);
xmlHttp.onreadystatechange =function() {
ParseResult(xmlHttp);};
xmlHttp.send(xml);
}
- Edited by Averil Monday, April 14, 2014 4:04 PM
Tuesday, April 8, 2014 1:39 PM
Answers
-
The issue was in the xml request that I was sending, fixed it. Thanks to those to took time to help.
- Marked as answer by HIMBAPModerator Tuesday, April 15, 2014 8:42 AM
Monday, April 14, 2014 4:00 PM
All replies
-
Hi,
You are most likely experiencing a cross domain issue where the browser prevents you from calling Webservices on a different domain to that of the current page (presumably a CRM server domain).
See http://stackoverflow.com/questions/17874730/how-to-make-cross-domain-request
If you can't use the JSONP approach then you will need to make a call to CRM (via setting an attribute and saving a record or using Custom Actions in CRM2013) then make the call server side.
See http://blog.sonomapartners.com/2013/11/crm-2013-custom-actions-the-end-of-configuration-entities.html
Hope this helps,
ScottScott Durow
Blog www.develop1.netFollow Me
Rockstar365
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"- Proposed as answer by Scott Durow (MVP)MVP, Editor Wednesday, April 9, 2014 1:41 AM
Wednesday, April 9, 2014 1:41 AMAnswerer -
The issue was in the xml request that I was sending, fixed it. Thanks to those to took time to help.
- Marked as answer by HIMBAPModerator Tuesday, April 15, 2014 8:42 AM
Monday, April 14, 2014 4:00 PM