01 June 2012

CRM Online IOrganizationService client

In this post I've updated little bit code to connect to Organization Service CRM Online.

    class Program
        static void Main(string[] args)
            String userName;
            String password;
            String organizationUrl;
            userName = <your-live-ID>;
            password = <live-ID-password>;
            organizationUrl = "https://<your-organization-name>.crm.dynamics.com/XRMServices/2011/Organization.svc";

            ClientCredentials credentials = new ClientCredentials();
            credentials.UserName.UserName = userName;
            credentials.UserName.Password = password;

            IServiceManagement<IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri(organizationUrl));

            AuthenticationCredentials authCredentials = new AuthenticationCredentials();
            authCredentials.ClientCredentials = credentials;
            authCredentials.SupportingCredentials = new AuthenticationCredentials();
            authCredentials.SupportingCredentials.ClientCredentials = Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
            AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);
            var organizationTokenResponse = tokenCredentials.SecurityTokenResponse;

            OrganizationServiceProxy _serviceProxy;
            IOrganizationService _service;
            using (_serviceProxy = new OrganizationServiceProxy(orgServiceManagement, organizationTokenResponse))
                _service = (IOrganizationService)_serviceProxy;

                WhoAmIResponse response = (WhoAmIResponse)_service.Execute(new WhoAmIRequest());


  1. Hi anton,

    Nice post,thanks for sharing this information .Looking forward for more useful posts like this.

    Dynamics CRM Developers

  2. this code is working when we Run this Code from Visual Studio.but once I deploy this code this is not working and getting this error

    Most likely causes:

    The directory or file specified does not exist on the Web server.
    The URL contains a typographical error.
    A custom filter or module, such as URLScan, restricts access to the file.

  3. Really great article on Microsoft CRM. Loved it man. Keep up the good work.