locked
Using an external webservice with javascript into CRM RRS feed

  • Question

  • Hi every body.
    Im using the plugin to integrate with an external webservice endpoint, I communicate with MSE endpoint that publish all services to CRM.
    with plugin there is no problem to call services, but I'm trying to call them using client SOAP message. The MSE tester is a tool that create the request message required to be sent to webservice and the responce also. The service that i need to use is GetCustomerBalance, this service call MINSAT API (Telco system) to get the balance of prepaid phone number.The following is the request and the responce of the SOAP message:

    this is the request :

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <GetCustomerBalance xmlns="http://www.almadar.ly/integration/prepaid/services">
          <phoneNumber>string</phoneNumber>
        </GetCustomerBalance>
      </soap:Body>
    </soap:Envelope>
     
     
    and this response:

    <?xml version="1.0" encoding="utf-16"?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Body>
        <GetCustomerBalanceResponse xmlns="http://www.almadar.ly/integration/prepaid/services">
          <GetCustomerBalanceResult>2.27</GetCustomerBalanceResult>
        </GetCustomerBalanceResponse>
      </s:Body>
    </s:Envelope>

    to use this services from client side i wrote the following code:

    var soapRequest="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                     "<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\">" +
    "<soap:Body>"+
    "<webmethodname xmlns=\'http://tempuri.org/\'>"+
    "<ParameterName>"+parameter+</ParameterName>"+
    "</webmethodname>"+
    " </soap:Body>"+
    "</soap:Envelope>";

    var xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

    xmlHttp.open("post","http://10.251.203.3/PrepaidEndpoint?wsdl", false);

    xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
    xmlHttp.setRequestHeader("Content-Length", soapRequest.length);
    xmlHttp.setRequestHeader("GetCustomerBalance","http://www.almadar.ly/integration/prepaid/services");
    xmlHttp.send(soapRequest);

    var responseXML=xmlHttp.responseXML;
    alert(responseXML);

    the alert show me an object, and when i write :
    alert(responseXML.selectSingleNode('//GetCustomerBalanceResult'));
    I reseve undefined message.

    can some one tel me what is missed !! thanks :) 

    Tuesday, June 2, 2009 1:42 PM

Answers

  • Ok. I think I understand now. You've created the WCF service and not a webservice. I guess your service file must have the extention .svc
    (Appologies in advance if i've missed something).

    If this is the case then have a read of the link below.
    http://blogs.msdn.com/alikl/archive/2008/02/18/how-to-consume-wcf-using-ajax-without-asp-net.aspx

    This post explains how you consume a WCF service in javascript. 

    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Tuesday, June 2, 2009 4:02 PM

All replies

  • Try the following changes to your code.

    XmlHttp.open("POST", "http://<Path to the ASMX file here>/YourServiceName.asmx'", false);
    XmlHttp.setRequestHeader("Content-Type", "text/xml");

    XmlHttp.setRequestHeader("SOAPAction", "<Search your WSDL file for soap:operationsoapAction and enter the value here>");
    XmlHttp.send(soapRequest);

    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Tuesday, June 2, 2009 2:12 PM
  • Hi Hassan,

    You have to use a XML object.

    var oXml = new ActiveXObject("Microsoft.XMLDOM");

    alert(xmlhttp.responseXML.xml); // This would display the xml itself.
    oXml.loadXML(xmlhttp.responseXML.xml);
    alert(oXml.selectSingleNode('//GetCustomerBalanceResult'));
    If this answers your question, please use the answer button and say so. | Anoop
    Tuesday, June 2, 2009 2:32 PM
  • I agree Anoop. I meant just change the lines I've posted. 

    H.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Tuesday, June 2, 2009 2:44 PM
  • Thank you Hassan and Anoop,

    I used alert(responseXML.xml) and I have the following return in the messagebox:

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetCustomerBalanceResponse xmlns="http://www.almadar.ly/integration/prepaid/services">
    <GetCustomerBalanceResult>Error</GetCustomerBalanceResult>
    <GetCustomerBalanceResponse></s:Body></s:Envelope>


    Tuesday, June 2, 2009 2:49 PM
  • Can you debug your webservice? 
    Can you put a breakpoint in your code and check if control is passed to the webservice.
    Is anything logged in the event viewer?

    H.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Tuesday, June 2, 2009 2:57 PM
  • The webervice is developped with WCF technolgie so the is no asmx page put it as parameter when I create the request, its just WSDl:

    xmlHttp.open("post","http://10.251.203.3/PrepaidEndpoint?wsdl", false);
    Tuesday, June 2, 2009 3:18 PM
  • Ok. I think I understand now. You've created the WCF service and not a webservice. I guess your service file must have the extention .svc
    (Appologies in advance if i've missed something).

    If this is the case then have a read of the link below.
    http://blogs.msdn.com/alikl/archive/2008/02/18/how-to-consume-wcf-using-ajax-without-asp-net.aspx

    This post explains how you consume a WCF service in javascript. 

    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Tuesday, June 2, 2009 4:02 PM