{"id":99,"date":"2009-12-31T07:34:51","date_gmt":"2009-12-31T07:34:51","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=99"},"modified":"2009-12-31T07:34:51","modified_gmt":"2009-12-31T07:34:51","slug":"calling-external-webservice-using-js","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=99","title":{"rendered":"Calling External WebService using JS"},"content":{"rendered":"<p>\u00a0Sometimes we need to call External webservice using JS, i have written a\u00a0function to call external webservice<\/p>\n<p>Here is the function, you can modify it according to your requirements<\/p>\n<p>function CallCustomWebService(FunctionName, ParameterNameList, ParameterValueList, ProxyURL)<\/p>\n<p>{\/\/FunctionName-Name of 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 = &#8220;http:\/\/tempuri.org\/&#8221; + FunctionName;<\/p>\n<p>var xml = &#8220;&lt;?xml version=&#8217;1.0&#8242; encoding=&#8217;utf-8&#8242;?&gt;&#8221; +<\/p>\n<p>&#8220;&lt;soap:Envelope xmlns:soap=&#8217;http:\/\/schemas.xmlsoap.org\/soap\/envelope\/'&#8221; +<\/p>\n<p>&#8221; xmlns:xsi=&#8217;http:\/\/www.w3.org\/2001\/XMLSchema-instance'&#8221; +<\/p>\n<p>&#8221; xmlns:xsd=&#8217;http:\/\/www.w3.org\/2001\/XMLSchema&#8217;&gt;&#8221;+<\/p>\n<p>&#8220;&lt;soap:Body&gt;&#8221; +<\/p>\n<p>&#8220;&lt;&#8221; + FunctionName + &#8221; xmlns=&#8217;http:\/\/tempuri.org\/&#8217;&gt;&#8221;;<\/p>\n<p>for (i = 0; i &lt; ParameterNameList.length; i++) {<\/p>\n<p>xml = xml + &#8220;&lt;&#8221; + ParameterNameList[i] + &#8220;&gt;&#8221; + ParameterValueList[i] + &#8220;&lt;\/&#8221; + ParameterNameList[i] + &#8220;&gt;&#8221;;<\/p>\n<p>}<\/p>\n<p>xml = xml + &#8220;&lt;\/&#8221; + FunctionName + &#8220;&gt;&#8221;;<\/p>\n<p>xml = xml + &#8220;&lt;\/soap:Body&gt;&lt;\/soap:Envelope&gt;&#8221;;<\/p>\n<p>xmlHttp = new ActiveXObject(&#8220;Msxml2.XMLHTTP&#8221;);<\/p>\n<p>xmlHttp.open(&#8220;POST&#8221;, ProxyURL, false);<\/p>\n<p>xmlHttp.setRequestHeader(&#8220;Content-Type&#8221;, &#8220;text\/xml; charset=utf-8&#8221;);<\/p>\n<p>xmlHttp.setRequestHeader(&#8220;Content-Length&#8221;, xml.length);<\/p>\n<p>xmlHttp.setRequestHeader(&#8220;SOAPAction&#8221;, CallingFunctionURL);<\/p>\n<p>xmlHttp.send(xml);<\/p>\n<p>var resultXml = xmlHttp.responseXML;<\/p>\n<p>if (resultXml.text == &#8220;Unable to connect to the remote server&#8221;)<\/p>\n<p>{alert(&#8220;Unable to connect to the remote server&#8221;);<\/p>\n<p>}<\/p>\n<p>var errorCount = resultXml.selectNodes(&#8216;\/\/error&#8217;).length;<\/p>\n<p>if (errorCount != 0) {<\/p>\n<p>var msg = resultXml.selectSingleNode(&#8216;\/\/description&#8217;).nodeTypedValue;<\/p>\n<p>}<\/p>\n<p>else {return resultXml;}}<\/p>\n<p>Hope it will help somebody!!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0Sometimes we need to call External webservice using JS, i have written a\u00a0function to call external webservice Here is the function, you can modify it according to your requirements function CallCustomWebService(FunctionName, ParameterNameList, ParameterValueList, ProxyURL) {\/\/FunctionName-Name of 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 = &#8220;http:\/\/tempuri.org\/&#8221;&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=99\">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":[25],"tags":[],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/99"}],"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=99"}],"version-history":[{"count":0,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}