{"id":25498,"date":"2020-11-09T10:31:36","date_gmt":"2020-11-09T10:31:36","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=25498"},"modified":"2020-11-09T10:49:39","modified_gmt":"2020-11-09T10:49:39","slug":"using-xrm-tooling-login-control-in-your-wpf-applications","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/11\/using-xrm-tooling-login-control-in-your-wpf-applications\/","title":{"rendered":"Using XRM Tooling Login Control in your WPF Applications"},"content":{"rendered":"<p style=\"text-align: justify;\">For designing any application for Dynamics 365 CRM that is not a web resource but rather a standalone application, the first thing that is required is designing an interface to accept details to connect with Dynamics 365.<\/p>\n<p style=\"text-align: justify;\">Back in the old days, we used to include a couple of text boxes for user id and password and the domain usually was North American Data Center or a few others that were available back then. Since then however much has changed, data centers have been added, there are different methodologies to connect as well. With the enhancements in mind, it is no longer advisable to design your own interface for login control but rather use the one that has been thoughtfully provided as part of the Dynamics 365 CRM SDK assemblies.<\/p>\n<p style=\"text-align: justify;\">Let us look at how we could add this within our application and leverage its functionality to easily get a connection object for CRM that we could use further on in our application. Using this method, we do not have to bother about implementing the logic for establishing control it is already taken care of by the control.<\/p>\n<ol style=\"text-align: justify;\">\n<li>The first step is to include the references to the assembly in the project. The assembly in question is <strong>Microsoft.CrmSdk.Xrm.Tooling.WpfControls<\/strong><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-1.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25503 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-1.png\" alt=\"Using XRM Tooling Login Control in your WPF Applications\" width=\"2980\" height=\"874\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-1.png 2980w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-1-300x88.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-1-768x225.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-1-1024x300.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-1-660x194.png 660w\" sizes=\"(max-width: 2980px) 100vw, 2980px\" \/><\/a><\/li>\n<li>Next, let us add this assembly in the toolbox so we could add the CRMConnectControl aka the login control to our page<\/li>\n<\/ol>\n<ol style=\"text-align: justify;\" start=\"3\">\n<li>Right click the toolbox to add new items to the toolbox and select choose items<br \/>\n<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-2.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25504 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-2.png\" alt=\"Using XRM Tooling Login Control in your WPF Applications\" width=\"706\" height=\"828\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-2.png 706w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-2-256x300.png 256w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-2-660x774.png 660w\" sizes=\"(max-width: 706px) 100vw, 706px\" \/><\/a><\/li>\n<\/ol>\n<ol style=\"text-align: justify;\" start=\"4\">\n<li>This will bring up the following window, choose Browse and select the CRMConnectControl assembly from the debug folder of your application<br \/>\n<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-3.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25505 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-3.png\" alt=\"Using XRM Tooling Login Control in your WPF Applications\" width=\"2338\" height=\"870\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-3.png 2338w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-3-300x112.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-3-768x286.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-3-1024x381.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-3-660x246.png 660w\" sizes=\"(max-width: 2338px) 100vw, 2338px\" \/><\/a><\/li>\n<\/ol>\n<ol style=\"text-align: justify;\" start=\"5\">\n<li>Once selected, it will list all controls available in the assembly, we are interested in the CRMServerLogin control so check that one<br \/>\n<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-4.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25499 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-4.png\" alt=\"Using XRM Tooling Login Control in your WPF Applications\" width=\"1204\" height=\"870\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-4.png 1204w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-4-300x217.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-4-768x555.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-4-1024x740.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-4-660x477.png 660w\" sizes=\"(max-width: 1204px) 100vw, 1204px\" \/><\/a><\/li>\n<\/ol>\n<ol style=\"text-align: justify;\" start=\"6\">\n<li>Click OK to see the control added to the toolbox<br \/>\n<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-5.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25500 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-5.png\" alt=\"Using XRM Tooling Login Control in your WPF Applications\" width=\"536\" height=\"554\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-5.png 536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-5-290x300.png 290w\" sizes=\"(max-width: 536px) 100vw, 536px\" \/><\/a><\/li>\n<li>You can now double click on this control to add it to your page<br \/>\n<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-6.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25501 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-6.png\" alt=\"Using XRM Tooling Login Control in your WPF Applications\" width=\"2330\" height=\"1626\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-6.png 2330w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-6-300x209.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-6-768x536.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-6-1024x715.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-6-660x461.png 660w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-6-200x140.png 200w\" sizes=\"(max-width: 2330px) 100vw, 2330px\" \/><\/a><\/li>\n<li>As soon as it is added you will see the design of the control that includes all components necessary for accepting connection details.<\/li>\n<li>This control is a fully functional control that does not require you to add any code for establishing connection. You only need to implement the various events that have been made available by the control to perform operations required at each stage.<\/li>\n<li>This control works in conjunction with the CrmConnectionManager class that is available within the same assembly that we added reference of earlier.<\/li>\n<li>Write the following code to initialize the Connection Manager class<\/li>\n<\/ol>\n<blockquote><p>\/\/ make an object of the connection manager<\/p>\n<p>mgr = new CrmConnectionManager();<\/p>\n<p>\/\/ Since WS-Trust is no longer supported \u2013 provided creds for OAuth authentication<\/p>\n<p>mgr.ClientId = &#8220;2ad88395-b77d-4561-9441-d0e40824f9bc&#8221;;<\/p>\n<p>mgr.RedirectUri = new Uri(&#8220;app:\/\/5d3e90d6-aa8e-48a8-8f2c-58b45cc67315&#8221;);<\/p>\n<p>\/\/Set Login control as the parent of the connection manager<\/p>\n<p>mgr.ParentControl = CrmLoginCtrl;<\/p><\/blockquote>\n<ol style=\"text-align: justify;\" start=\"12\">\n<li>Beginning October 2020, Organization Service Proxy will no longer be supported for establishing a connection as stated <a href=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/developer\/common-data-service\/xrm-tooling\/use-connection-strings-xrm-tooling-connect\" target=\"_blank\" rel=\"noopener noreferrer\">here.<\/a>\n<p>OAuth authentication requires Client ID and Redirect URL to be provided. Usually, this information is obtained from the Azure AD Application that you have to create in Azure AD. However per the documentation <a href=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/developer\/common-data-service\/xrm-tooling\/use-connection-strings-xrm-tooling-connect\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>, the client ID and redirect URL provided in the code is globally available across all CRM online tenants and could be used in our code.<\/li>\n<\/ol>\n<ol start=\"13\">\n<li>\n<p style=\"text-align: justify;\">Now when you run the application and enter all the details and hit Login<br \/>\n<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-7.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-25502 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-7.png\" alt=\"Using XRM Tooling Login Control in your WPF Applications\" width=\"1384\" height=\"980\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-7.png 1384w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-7-300x212.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-7-768x544.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-7-1024x725.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/11\/Using-XRM-Tooling-Login-Control-in-your-WPF-Applications-7-660x467.png 660w\" sizes=\"(max-width: 1384px) 100vw, 1384px\" \/><\/a>It will internally try to establish a connection using the details provided without you having to write any code for connection.It will raise the following events in the process:<\/p>\n<blockquote><p>\/\/ this wires an event that is raised when the login button is pressed.<\/p>\n<p>CrmLoginCtrl.ConnectionCheckBegining += new<br \/>\nEventHandler(CrmLoginCtrl_ConnectionCheckBegining);<\/p>\n<p>\/\/ this wires an event that is raised when an error in the connect process occurs.<\/p>\n<p>CrmLoginCtrl.ConnectErrorEvent += new<br \/>\nEventHandler&lt;ConnectErrorEventArgs&gt;(CrmLoginCtrl_ConnectErrorEvent);<\/p>\n<p>\/\/ this wires an event that is raised when a status event is returned.<\/p>\n<p>CrmLoginCtrl.ConnectionStatusEvent += new<br \/>\nEventHandler&lt;ConnectStatusEventArgs&gt;(CrmLoginCtrl_ConnectionStatusEvent);<\/p>\n<p>\/\/ this wires an event that is raised when the user clicks the cancel button.<\/p>\n<p>CrmLoginCtrl.UserCancelClicked += new<br \/>\nEventHandler(CrmLoginCtrl_UserCancelClicked);<\/p><\/blockquote>\n<ol style=\"text-align: justify;\" start=\"14\">\n<li>In the ConnectionStatusEvent, check if connection is established and the connection manager will return reference to the CRMServiceClient that could be used going forward in your code to perform operations in CRM application.<br \/>\n<br \/>\nCrmServiceClient CrmSvc = mgr.CrmSvc;<br \/>\n<br \/>\nLeverage this Login Control to benefit from the connection logic already implemented in this control and also to make sure you stay up to date with all the changes added to the login logic over a period of time. Being part of the CRM SDK this will most likely be updated with every update to the login methods and then all you need to do is to add a reference to the latest library and you are good to go.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>For designing any application for Dynamics 365 CRM that is not a web resource but rather a standalone application, the first thing that is required is designing an interface to accept details to connect with Dynamics 365. Back in the old days, we used to include a couple of text boxes for user id and\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/11\/using-xrm-tooling-login-control-in-your-wpf-applications\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[16,19,24],"tags":[545,592,1854,1855,1856],"class_list":["post-25498","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-dynamics-crm","category-dynamics-crm-2016","tag-dynamics-365-crm","tag-dynamics-crm","tag-xrm","tag-xrm-dynamics-crm","tag-xrm-tooling"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/25498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=25498"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/25498\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=25498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=25498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=25498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}