locked
calling custom webservice from Onchange using XMLHTTP RRS feed

  • Question

  • Hi.

    We are calling custom webserice from Onchange event using the below code.
    The use of webserice is to call the pick list value from other db.
    when we are executing the websercive deployed in local i.e our machine its working fine i.e picklist is getting populated but when we have deployed it in the production server its doesnt work i.e pick list is comming empty.
    please let us know where we are going wrong or any alternate method of calling custom webservice from CRM

    function GetLeadSourceInfo() {
        var SERVER_URL=
             "http://serverurl/ORG/ISV/SampleWebService/Service1.asmx";
        var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        xmlhttp.open("GET", SERVER_URL , false);

        xmlhttp.setRequestHeader ("SOAPAction", "http://tempuri.org/GetLeadSourceData");
        xmlhttp.setRequestHeader ("Content-Type", "text/xml");

            var xmlToSend = "<?xml version='1.0' encoding='utf-8'?>";
            xmlToSend += "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' ";
            xmlToSend += "xmlns:xsd='http://www.w3.org/2001/XMLSchema' ";
            xmlToSend += "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
            xmlToSend += GenerateAuthenticationHeader();
            xmlToSend += "<soap:Body><GetLeadSourceData xmlns='http://tempuri.org/' />";
            xmlToSend += "</soap:Body></soap:Envelope>";
            xmlhttp.send(xmlToSend);

        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        xmlDoc.loadXML(xmlhttp.responseXML.xml);
    alert(xmlhttp.responseXML.xml);
    alert(xmlhttp.responseText);
        return xmlDoc.documentElement.childNodes[0].nodeValue;
    }
    ////Get Lead Scource from Ext DB
    var leadStr = GetLeadSourceInfo();
    var leadArr = leadStr.split('~');

    //Erase the pick list
    var pick = crmForm.all.stei_leadsource;
    var ctName = pick.name;
    var ctId = pick.id + '_lst';
    var ctClass = "ms-crm-SelectBox";
    var pVal = pick.DataValue;
    var parent = pick.parentElement;
    pick.style.display = 'none';

    var picklistControl = document.createElement("SELECT");
    ////Copy the Text field properties to the picklist 
    picklistControl.id = ctId;
    //  picklistControl.req = textControl.req;
    picklistControl.name = ctName;
    //// Set Required Style 
    picklistControl.className = ctClass;

    for (x = 0; x < leadArr.length; x++) {
        var leadSrc = leadArr[x];

        //Create a new Option 
        var option = document.createElement("OPTION");
        option.value = x;
        option.innerText = leadSrc;
        option.selected = (leadSrc == pVal);

        //Add the option to the picklist   
        picklistControl.appendChild(option);

        ////crmForm.all.stei_mysource.options.add(new Option(Account,count++));
        ///crmForm.all.stei_leadsource.value = Account;

    }

    //append the picklist to the document 
    parent.appendChild(picklistControl);

    Monday, December 21, 2009 5:19 AM

Answers

  • Hi,

    we are finally able to resolve the problem by putting the below tag in the web.config file

    <configuration>
        <system.web>
        <webServices>
            <protocols>
                <add name="HttpGet"/>
                <add name="HttpPost"/>
            </protocols>
        </webServices>
        </system.web>
    </configuration>
    • Marked as answer by v pavan rao Monday, December 21, 2009 11:10 AM
    Monday, December 21, 2009 11:10 AM

All replies

  • Hi,

    If your code is working in the dev environment then there should be nothing wrong with the code. I suspect the security settings on the production server might be causing the problem.

    Here are a few tips to debug / understand the problem.

    1- Are you able to access the custom webservice "http://serverurl/ORG/ISV/SampleWebService/Service1.asmx" on the prod. server? My gut feeling is that the problem is with the deployment of your custom webservice and not with the code.
    2- Did you change the server URL in the code when you deployed the code on the Prod. server?
    3- Did you see any script error messages on the page? If an error occurs you should see a Yellow warning triangle on the left corner of your screen. Double click on the warning message and you will get more details about the problem.
    4- Are there any error messages logged on the Event Viewer on the server? Again you will get more details of the problem.

    Hassan.


    Hassan Hussain | http://hassanhussain.wordpress.com/ | http://www.mscrmvirtualusergroup.com/
    • Proposed as answer by Hassan Hussain Monday, December 21, 2009 9:15 AM
    Monday, December 21, 2009 9:15 AM



  • Hi Hassan,

    when we are trying the below URL in the prod server it is working fine but when we give the server name in place of localhost it is giving  error "Request format is unrecognized for URL unexpectedly ending in '/GetLeadSourceData' ".   GetLeadSourceData is mehtod in the webserice.
    We are thinking whetheter we are missing something in  the URL  or somewhere but we are not able to figure it out.


    http://localhost/ISV/SampleWebService/Service1.asmx/GetLeadSourceData
    Monday, December 21, 2009 9:48 AM
  • Ok. This is a good start to solving the problem. Try typing in the IP address of the CRM server in place of the server name in the URL. Does that fix the problem? Update your code with the new URL (ip address) and test again.

    Try adding a host header to the CRM site. That should also fix the problem.

    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/ | http://www.mscrmvirtualusergroup.com/
    Monday, December 21, 2009 10:06 AM
  • Hi,

    we are finally able to resolve the problem by putting the below tag in the web.config file

    <configuration>
        <system.web>
        <webServices>
            <protocols>
                <add name="HttpGet"/>
                <add name="HttpPost"/>
            </protocols>
        </webServices>
        </system.web>
    </configuration>
    • Marked as answer by v pavan rao Monday, December 21, 2009 11:10 AM
    Monday, December 21, 2009 11:10 AM