Connecting to Dynamics 365 using the Organization Service Proxy

Leave a comment

We will connect to Dynamics 365 from a console app using the Organization Service Proxy.

To do this, create a new console app.

Add the assemblies:

  • Microsoft.Xrm.Sdk
  • System.ServiceModel (for ClientCredentials)

We will also add Microsoft.Crm.Sdk.Proxy to get the version info from Dynamics 365.

Add using statements:

  • using Microsoft.Xrm.Sdk.Client;
  • using System.ServiceModel.Description;
  • using Microsoft.Crm.Sdk.Messages;

Now the code to connect to Dynamics 365:

using System;
using System.Linq;
using Microsoft.Xrm.Sdk.Client;
using System.ServiceModel.Description;
using Microsoft.Crm.Sdk.Messages;

namespace Carl.Crm.OrgServiceProxy
    class Program
        static void Main(string[] args)
                Uri oUri = new Uri("");
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.UserName.UserName = "";
                clientCredentials.UserName.Password = "yourpassword";

                OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(oUri, null, clientCredentials, null);

                OrganizationServiceContext orgContext = new OrganizationServiceContext(_serviceProxy);

                RetrieveVersionRequest versionRequest = new RetrieveVersionRequest();
                RetrieveVersionResponse versionResponse = (RetrieveVersionResponse)_serviceProxy.Execute(versionRequest);

                Console.WriteLine("Microsoft Dynamics CRM version {0}.", versionResponse.Version);

            catch (Exception ex)

This returns:



Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube


Leave a Reply

Your email address will not be published. Required fields are marked *