locked
Calling External Webservice RRS feed

  • 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.
    Monday, April 14, 2014 4:00 PM

All replies