Home › Dynamics 365 Customer Engagement (CRM) › Connecting to Dynamics 365 using the Organization Service Proxy
Dynamics 365 Customer Engagement (CRM) · Aug 4, 2016 · 1 MIN READ

Connecting to Dynamics 365 using the Organization Service Proxy

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)
        {
            try
            {
                Uri oUri = new Uri("https://yourcrm.crm.dynamics.com/XRMServices/2011/Organization.svc");
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.UserName.UserName = "your@email.com";
                clientCredentials.UserName.Password = "yourpassword";

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

                OrganizationServiceContext orgContext = new OrganizationServiceContext(_serviceProxy);

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

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

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.ReadLine();
        }
    }
}

This returns:

 

Carl de Souza
Keep learning. Keep building.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.

Subscribe on YouTube →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

One Response to Connecting to Dynamics 365 using the Organization Service Proxy

  1. Hi Carl,
    Is connecting to CRM Service Proxy is deprecated now.
    Also, does that mean we cannot use LINQ with Dynamics 365 anymore.

    Thanks,

Leave a Reply

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

Carl de Souza
KEEP LEARNING. KEEP BUILDING.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.