I got this error while using Accessing Microsoft Dynamics CRM Web Services from onload of lead entity.
I used the sample given in SDK which calls the WhoAmI message with the Execute method to retrieve the ID of the current user.
Resolved the error by replacing the url
xmlhttp.open(‘POST’, SERVER_URL +’/mscrmservices/2007/crmservice.asmx’, false);
to
xmlhttp.open(“POST”, “http://myServerName:Port/MSCrmServices/2007/CrmService.asmx”, false);
SERVER_URL global variable actually returns
http://myServerName:Port/organizationname because of which we got the error.
Here is the final code that I used
//Define the soapBody for the WhoAmI request.
var soapBody = “<soap:Body><Execute xmlns=’http://schemas.microsoft.com/crm/2007/WebServices’><Request xsi:type=’WhoAmIRequest’ /></Execute></soap:Body>”;
//Wrap the Soap Body in a soap:Envelope.
var soapXml = “<soap:Envelope xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/’ xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance’ xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>”;
soapXml += GenerateAuthenticationHeader();
soapXml += soapBody;
soapXml += “</soap:Envelope>”;
// Create the XMLHTTP object for the execute method.
var xmlhttp = new ActiveXObject(“Msxml2.XMLHTTP”);
xmlhttp.open(“POST”, “http://d-3638:5555/MSCrmServices/2007/CrmService.asmx”, false);
xmlhttp.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
xmlhttp.setRequestHeader(“SOAPAction”, “http://schemas.microsoft.com/crm/2007/WebServices/Execute”);
//Send the XMLHTTP object.
xmlhttp.send(soapXml);
// Create an XML object to parse the results.
xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.async=false;
xmlDoc.loadXML(xmlhttp.responseXML.xml);
// Get the user’s ID.
var userid = xmlDoc.getElementsByTagName(“UserId”)[0].childNodes[0].nodeValue;
Bye..
Thanks. It helped me !!
LikeLike