Sending HTTP Post CRM webservice RRS feed

  • Question

  • Hi,
    I'm sending HTTP Post to the MSCRMservices/2007/crmservice.asmx in the crm setup in our environment. I'm sending the POST request from c#. I'm sending the following request xml. The response I get is "Unauthorized". Can anybody help me in pointing out the error. I'm sending the following xml as the body.

    <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:Header> <CrmAuthenticationToken xmlns='http://schemas.microsoft.com/crm/2007/WebServices'> <AuthenticationType xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>0</AuthenticationType><OrganizationName xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>xxxxx</OrganizationName><CallerId xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'> 00000000-0000-0000-0000-000000000000</CallerId></CrmAuthenticationToken></soap:Header><soap:Body><Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'><Request xsi:type='WhoAmIRequest' /></Execute></soap:Body></soap:Envelope>

    Also I'm sendign the following headers:

    Content-Type:text/xml; charset=utf-8;

    I'm getting the 401 error as "UnAuthorized". Any Idea??Can anybody tell me whether I'm doing correctly??Because the same code when requested from javascript(ajax request) works without any problem.

    Monday, December 14, 2009 5:43 PM


All replies

  • well there are more than one reasons for this  error

    1. firstly, check your proxy server and make sure they are not blocking this request.
    2. if you are using AD Authentication (Hosted Envrionment) then make sure you are provining correct domain name,username and password
    3. make sure the relevant user have  got security role in the crm system.

    if you could post code over here then someone can surely point you in right direction over here..
    Monday, December 14, 2009 8:39 PM
  • Thank you for the quick reply. Attached is the code..
    string soapXml = "<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:Header> " +
           "<CrmAuthenticationToken xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
           " <AuthenticationType xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" +
           "0" +
           "</AuthenticationType>" +
           "<OrganizationName xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" +
           "xxxx" +
           "</OrganizationName>" + "<CrmTicket xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'/>" +
           "<CallerId xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'> " +
           "00000000-0000-0000-0000-000000000000" +
           "</CallerId>" +
           "</CrmAuthenticationToken>" +
                soapXml = soapXml + soapBody + "</soap:Envelope>";
      _hshReqHeaders["Content-Type"] = "text/xml; charset=utf-8";
                _hshReqHeaders["SOAPAction"] = "http://schemas.microsoft.com/crm/2007/WebServices/Execute";
                      string _strRequestURL = "http://xxxx:3333/mscrmservices/2007/CrmService.asmx";

    After this I'm sending a post request to the crm server. Where do we specify the credentials to be used??AuthenticationType is set to 0. And in IIS for 2007 virtal directory I have enabled anonymous and windows authentication. Can you please help??Is it the IIS configuration or a valid credentials are not passed to the crm??

    Wednesday, December 16, 2009 10:29 AM
  • If AuthenticationType is 0, then you work with OnPremise authentication, then the web site shouldn't be set with anonymous authentication
    My blog : http://mscrmtools.blogspot.com You will find: Form Javascript Manager (export/import javascript from forms) ISV.Config Manager (graphical ISV.config edition - export/import) View Layout replicator (customize one view and replicate to others) And others (use tool tag on my blog)
    Wednesday, December 16, 2009 11:26 AM
  • please check following articles regarding this..

    Wednesday, December 16, 2009 4:00 PM