Access CRM 2011 Online using Services


Steps to access CRM 2011 online data using services.

  1. Register for CRM 2011 Online using Windows Live ID.

    You can get it here: http://crm.dynamics.com/en-us/home

    Available services in CRM 2011.

    CRM can allow multiple Organizations to be created on 1 CRM installation.

    Each Organization can be for a different company/purpose. So, users may want to access one of the Organizations on CRM installation. If the user/code already knows the Organization URL OR Organization Service URL then fine he can directly use organization service.

    If not known, then he needs to write code to connect Discovery Service URL, then browse through all Organizations available and get Organization service URL for respective/required Organization.

    In short, whatever Data/Metadata operations we want to do, we will need to use Organization Service URL.

    If we want to find Organization Service URL for an Organization, then we need to do that using Discovery Service URL.

    https://dev.crm.dynamics.com/XRMServices/2011/Discovery.svc (North America)
    https://dev.crm4.dynamics.com/XRMServices/2011/Discovery.svc (EMEA)
    https://dev.crm5.dynamics.com/XRMServices/2011/Discovery.svc (APAC)

    The following URLs should be used to access the Organization service(SOAP endpoint):

    https://{Organization Name}.api.crm.dynamics.com/XrmServices/2011/Organization.svc (North America)
    https://{Organization Name}.api.crm4.dynamics.com/XrmServices/2011/Organization.svc (EMEA)
    https://{Organization Name}.api.crm5.dynamics.com/XrmServices/2011/Organization.svc (APAC)

    Where {Organization Name} refers to the Organization that you specify in the URL when accessing the Web application. For example, for Contoso.crm.dynamics.com, the {Organization Name} is Contoso.

    The following URLs should be used to access the Organization Data service(OData REST endpoint)

    https://{Organization Name}.api.crm.dynamics.com/XrmServices/2011/OrganizationData.svc (North America)
    https://{Organization Name}.api.crm4.dynamics.com/XrmServices/2011/OrganizationData.svc (EMEA)
    https://{Organization Name}.api.crm5.dynamics.com/XrmServices/2011/OrganizationData.svc (APAC)

    For CRM On-premises customers:

    http://{server}/XRMServices/2011/Discovery.svc for the Discovery service endpoint
    http://{server}/{OrgName}/XRMServices/2011/Organization.svc for the Organization Service endpoint (SOAP)
    http://{server}/{OrgName}/XRMServices/2011/OrganizationData.svc for the Organization Data Service endpoint (REST)
    http://{server}/XRMDeployment/2011/Deployment.svc for the Deployment Service endpoint
     
  2. Install Microsoft Dynamics CRM 2011 SDK.

    You can get it here: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=eb9c345f-e830-40b8-a5fe-ae7a864c4d76&displaylang=en

     
  3. Run the DeviceRegistration.exe utility to generate a device id and password.

    There are two methods to get device id and password.

    • Using DiviceMAnager class available in SDK folder. So that we can generate device id and password.
    • By Commandline.

    Once you download SDK from above given link, Inside tools, there will deviceregistration directory. Run it with command line /operation:Register.
    Then you will get device id and password. Copy these credentials for further use.
     
  4. Making context class for the organization.svc or discovery service.

    C:\Users\aravinda.sheshadri\Desktop\ToolkitGestureDemo\sdk\bin\crmsvcutil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /url:https://<>.crm5.dynamics.com/XRMServices/2011/Organization.svc /o:crm.cs /n:XXXCRM2011 /domain:<>.crm5.dynamics.com /u:<> /p:<>/serviceContextName:XXXcontext /di:116bohmbs2iupfaxp07bp5mhrp /dp:GYfG8LSo%_+3H2H+mpT~w=IG

    On run this command, class will be generated containing all entities(context). Here, I have given context name as Accenture. So I can access all entities using Accenture name.

    While running this command, make sure that time in both server and local machine will be same(Time and Timezone).
     

  5. Add this class file to your Visual Studio 2010 project.
     
  6. Add a reference to the dll's in there as necessary from SDK folder bin directory:

    Microsoft.XRM.sdk
    System.ServiceModel
    Microsoft.Crm.Sdk.Data.Services;
    System.Data.Services.Client;
    System.ServiceModel.Description;
    Microsoft.Xrm.Sdk;
    Microsoft.Xrm.Sdk.Client;
    Microsoft.Crm.Services.Utility;

     

  7. How do I access CRM 2011 online wcf service over .net client?

    If we are using organization.svc, then we have to use

    OrganizationServiceProxy _serviceProxy;
    IOrganizationService _service;
    ClientCredentials Credentials = new ClientCredentials();
    ClientCredentials devivceCredentials = new ClientCredentials();           
    CRMContext context;
     
    Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
     
    //This URL needs to be updated to match the servername and Organization for the environment.
               
               
    Uri OrganizationUri = new Uri("https://{organization name}.crm5.dynamics.com/XRMServices/2011/Organization.svc");
     
    Uri HomeRealmUri = null;
     
    //To get device id and password.
    //Online: For online version, we need to call this method to get device id.
    devivceCredentials= DeviceIdManager.LoadDeviceCredentials(); 
     
    using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials,
    devivceCredentials))
    {
          serviceProxy.ClientCredentials.UserName.UserName = "username";
          serviceProxy.ClientCredentials.UserName.Password = "password";
          serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
          IOrganizationService service = (IOrganizationService)serviceProxy;
          _service = (IOrganizationService)serviceProxy;
           context = new CRMContext(_service);
         //Getting data from Leads.
     
         var querry = context.CreateQuery("LeadSet");
         var querry1 = from itm in context.LeadSet select itm;
    }
     
  8. Odata(OrganizatationData.svc) is not supported outside the CRM application.

    Currently CRM 2011 does not support for Odata(organizationdata.svc) to do any operation from outside the CRM application. So If we make it as web resources, then we can use Odata services.

    Proof:

    http://mscrmblogger.com/2011/05/12/crm-2011-supported-vs-unsupported/
    http://msdn.microsoft.com/en-us/library/gg334279.aspx

    "The REST Endpoint for Web resources provides an alternative interface to work with Microsoft Dynamics CRM data. You can use the REST endpoint to execute HTTP requests by using a service that is based on a Uniform Resource Identifier (URI). The REST endpoint is only available for use by JScript and Silverlight Web resources."

Establishing connection with CRM 2011 on premise

There is only one difference is that, here no need to pass device id credentials while creating proxy. Also instead of passing windows live credentials, we have to pass domain login id and password.

Differences between online and on premise versions of CRM 2011.

CRM 2011

Up Next
    Ebook Download
    View all
    Learn
    View all