locked
Connecting to CRM4 WebServices over the internet RRS feed

  • Question

  • Hi all,

     

    I'm trying to access the CRM Web services on a hosted installation over the internet.

     

    The senario is this: I have a web page with a form that when submitted, should call the web service and create a lead record.

     

    I've written the web app as I have many times on an active directory network. But this does not work in this situation as this server is hosted and I think uses forms authentication. When navigating to the domain, I first get the sign in page on the browser prior to getting access to the data.

     

    I've tried connecting with

        discoveryService.UseDefaultCredentials = true;

    and

        discoveryService.Credentials = new NetworkCredential("UserName", "Password", "domain");

     

    But I get the same response every time:

    When using /MSCRMServices/2007/AD/CrmDiscoveryService.asmx I get "401 - Unauthorized"

    When using /MSCRMServices/2007/SPLA/CrmDiscoveryService.asmx I get "An error occurred while attempting to authenticate"

     

    Is there something special I need to do when accessing CRM web service over the internet?

     

    Here's the full code I'm using:

    ==========================

    CrmDiscoveryService discoveryService = new CrmDiscoveryService();

    //discoveryService.Credentials = new NetworkCredential("UserName", "Password", "Domain");

    discoveryService.UseDefaultCredentials = true;

    discoveryService.Url = "http://kidsco.crm.etopia.com.au/MSCRMServices/2007/SPLA/CrmDiscoveryService.asmx";

    RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();

    RetrieveOrganizationsResponse orgResponse = (RetrieveOrganizationsResponse)discoveryService.Execute(orgRequest);

     

    Error encountered on execution of last line.

     

    Thanks heaps for any help.

    Kia

    Wednesday, September 10, 2008 2:55 PM

Answers

  • Here's what you are missing:

    orgRequest.UserId = domain + "\\" + username;
    orgRequest.Password = password;

     

    You can find the complete code snippet at:

    http://msdn.microsoft.com/en-us/library/cc151010.aspx

     

    Hope this helps.

     

    Thursday, September 11, 2008 8:59 AM
  • Hi,

     

    You can use cade as below:

     

     CrmSdk.CrmService myCrm = new CrmSdk.CrmService();
            CrmSdk.CrmAuthenticationToken myToken = new CrmSdk.CrmAuthenticationToken();
            myToken.AuthenticationType = 0;
            myToken.OrganizationName = "WilcomInternationalPtyLtd";
            myCrm.CrmAuthenticationTokenValue = myToken;
            myCrm.PreAuthenticate = true;
            CredentialCache credential = new System.Net.CredentialCache();
            NetworkCredential netCred = new NetworkCredential("username", "password", "domainname");
            credential.Add(new Uri("http://yourservername"), "NTLM", netCred);
            myCrm.Credentials = credential;

            WhoAmIRequest userRequest = new WhoAmIRequest();
            WhoAmIResponse user = (WhoAmIResponse)myCrm.Execute(userRequest);

            CrmSdk.lead newLead = new CrmSdk.lead();
            newLead.subject = "TEST1";
            newLead.firstname = "TEST1";
            newLead.lastname = "TEST1";
            newLead.emailaddress1 = "TEST1";

            TargetCreateLead targetCreate = new TargetCreateLead();
            targetCreate.Lead = newLead;
            CreateRequest create = new CreateRequest();
            create.Target = targetCreate;
            CreateResponse created = (CreateResponse)myCrm.Execute(create);

    You have to also add CRM webservices as webreferences to your website.

    Thursday, September 18, 2008 5:11 AM

All replies

  • Here's what you are missing:

    orgRequest.UserId = domain + "\\" + username;
    orgRequest.Password = password;

     

    You can find the complete code snippet at:

    http://msdn.microsoft.com/en-us/library/cc151010.aspx

     

    Hope this helps.

     

    Thursday, September 11, 2008 8:59 AM
  • Hi,

     

    You can use cade as below:

     

     CrmSdk.CrmService myCrm = new CrmSdk.CrmService();
            CrmSdk.CrmAuthenticationToken myToken = new CrmSdk.CrmAuthenticationToken();
            myToken.AuthenticationType = 0;
            myToken.OrganizationName = "WilcomInternationalPtyLtd";
            myCrm.CrmAuthenticationTokenValue = myToken;
            myCrm.PreAuthenticate = true;
            CredentialCache credential = new System.Net.CredentialCache();
            NetworkCredential netCred = new NetworkCredential("username", "password", "domainname");
            credential.Add(new Uri("http://yourservername"), "NTLM", netCred);
            myCrm.Credentials = credential;

            WhoAmIRequest userRequest = new WhoAmIRequest();
            WhoAmIResponse user = (WhoAmIResponse)myCrm.Execute(userRequest);

            CrmSdk.lead newLead = new CrmSdk.lead();
            newLead.subject = "TEST1";
            newLead.firstname = "TEST1";
            newLead.lastname = "TEST1";
            newLead.emailaddress1 = "TEST1";

            TargetCreateLead targetCreate = new TargetCreateLead();
            targetCreate.Lead = newLead;
            CreateRequest create = new CreateRequest();
            create.Target = targetCreate;
            CreateResponse created = (CreateResponse)myCrm.Execute(create);

    You have to also add CRM webservices as webreferences to your website.

    Thursday, September 18, 2008 5:11 AM