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:
THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL
Hi Carl,
Is connecting to CRM Service Proxy is deprecated now.
Also, does that mean we cannot use LINQ with Dynamics 365 anymore.
Thanks,