{"id":554,"date":"2011-08-24T07:45:50","date_gmt":"2011-08-24T07:45:50","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=554"},"modified":"2011-08-24T07:45:50","modified_gmt":"2011-08-24T07:45:50","slug":"calling-external-webservice-from-ms-crm-2011-asynchronously-javascript","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=554","title":{"rendered":"Calling External Webservice from MS CRM 2011 Asynchronously &#8211; Javascript"},"content":{"rendered":"<p>If you are looking for the code to call external webservice from MS CRM 2011, you can create a webresource in MS CRM 2011 and call use\u00a0below code<\/p>\n<p>function CallCustomWebService(FunctionName, ParameterNameList, ParameterValueList,ProxyURL)<\/p>\n<p>{\/\/FunctionName-Nameof the function to call<\/p>\n<p>\/\/ParameterNameList-Array of Parameter names in your proxy function<\/p>\n<p>\/\/ParameterValueList-Array of Parameter value<\/p>\n<p>\/\/ProxyURL-URL of your proxy<\/p>\n<p>var CallingFunctionURL = \u201chttp:\/\/tempuri.org\/\u201d +FunctionName;<\/p>\n<p>var xml = \u201c&lt;?xml version=\u20191.0\u2032 encoding=\u2019utf-8\u2032?&gt;\u201d +<\/p>\n<p>\u201c&lt;soap:Envelope xmlns:soap=\u2019http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\u2019\u201d+<\/p>\n<p>\u201d xmlns:xsi=\u2019http:\/\/www.w3.org\/2001\/XMLSchema-instance\u2019\u201d +<\/p>\n<p>\u201d xmlns:xsd=\u2019http:\/\/www.w3.org\/2001\/XMLSchema\u2019&gt;\u201d+<\/p>\n<p>\u201c&lt;soap:Body&gt;\u201d +<\/p>\n<p>\u201c&lt;\u201d + FunctionName + \u201d xmlns=\u2019http:\/\/tempuri.org\/\u2019&gt;\u201d;<\/p>\n<p>for (i = 0; i&lt; ParameterNameList.length; i++) {<\/p>\n<p>xml = xml + \u201c&lt;\u201d +ParameterNameList[i] + \u201c&gt;\u201d + ParameterValueList[i] + \u201c&lt;\/\u201d +ParameterNameList[i] + \u201c&gt;\u201d;<\/p>\n<p>}<\/p>\n<p>xml = xml + \u201c&lt;\/\u201d +FunctionName + \u201c&gt;\u201d;<\/p>\n<p>xml = xml +\u201c&lt;\/soap:Body&gt;&lt;\/soap:Envelope&gt;\u201d;<\/p>\n<p>xmlHttp = new ActiveXObject(\u201cMsxml2.XMLHTTP\u201d);<\/p>\n<p>xmlHttp.open(\u201cPOST\u201d,ProxyURL, <strong>true<\/strong>);<\/p>\n<p>xmlHttp.setRequestHeader(\u201cContent-Type\u201d,\u201ctext\/xml; charset=utf-8\u2033);<\/p>\n<p>xmlHttp.setRequestHeader(\u201cContent-Length\u201d,xml.length);<\/p>\n<p>xmlHttp.setRequestHeader(\u201cSOAPAction\u201d,CallingFunctionURL);<\/p>\n<p>xmlHttp.onreadystatechange =function() {<\/p>\n<p>ParseResult(xmlhttp);<\/p>\n<p>};<\/p>\n<p>xmlHttp.send(xml);<\/p>\n<p>}<\/p>\n<p>function ParseResult(XmlRequest)<\/p>\n<p>{<\/p>\n<p>if(XmlRequest.readyState == 4) {<\/p>\n<p>if(XmlRequest.status == 200) {<br \/>\nalert(XmlRequest.responseXML.text);<\/p>\n<p>\/\/Fetch your result from response xml here<\/p>\n<p>}<\/p>\n<p>else {<\/p>\n<p>alert(&#8220;Request Failed\u00a0&#8220;);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>Enjoy !!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are looking for the code to call external webservice from MS CRM 2011, you can create a webresource in MS CRM 2011 and call use\u00a0below code function CallCustomWebService(FunctionName, ParameterNameList, ParameterValueList,ProxyURL) {\/\/FunctionName-Nameof the function to call \/\/ParameterNameList-Array of Parameter names in your proxy function \/\/ParameterValueList-Array of Parameter value \/\/ProxyURL-URL of your proxy var CallingFunctionURL = \u201chttp:\/\/tempuri.org\/\u201d +FunctionName; var xml&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=554\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/554"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=554"}],"version-history":[{"count":0,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/554\/revisions"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}