{"id":218,"date":"2009-03-05T10:52:00","date_gmt":"2009-03-05T05:22:00","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=218"},"modified":"2009-03-05T10:52:00","modified_gmt":"2009-03-05T05:22:00","slug":"how-to-login-to-various-crm-deployments","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2009\/03\/how-to-login-to-various-crm-deployments\/","title":{"rendered":"How to Login to various CRM deployments"},"content":{"rendered":"<p>CRM supports various Deployment methods and unfortunately for the developers the method to connect to each of these differs. So here are the login functions for each of the Deployment methods supported by Dynamics CRM.<br \/>\n<strong><span style=\"text-decoration: underline;\">On Premise CRM connection:<\/span><\/strong><br \/>\nOn premise uses AD for authentication.<br \/>\nCrmService service = new CrmService();<br \/>\nservice.Url = &#8220;http:\/\/&#8221; + servername + &#8220;\/mscrmservices\/2007\/crmservice.asmx&#8221;;<br \/>\nservice.CrmAuthenticationTokenValue.OrganizationName = &#8220;orgname&#8221;;<br \/>\nservice.CrmAuthenticationTokenValue.AuthenticationType = 0;<br \/>\nservice.Credentials = new System.Net.NetworkCredential(&#8220;username&#8221;, &#8220;Password&#8221;, &#8220;DomainName&#8221;);<br \/>\nOR<br \/>\ncrmService.Credentials = System.Net.CredentialCache.DefaultCredentials;<br \/>\n<strong><span style=\"text-decoration: underline;\">Live CRM connection: <\/span><\/strong><br \/>\nCRM Live uses Passport authentication. It requires a reference to the Idcrlwrapper be added. The Idcrlwrapper is available along with the SDK as helper files.<br \/>\nMake sure you have copied the msidcrl40.dll to the system32 folder before you try to run this code.<br \/>\nCrmDiscoveryService discoveryService = new CrmDiscoveryService();<br \/>\ndiscoveryService.Url = &#8220;<a href=\"https:\/\/dev.crm.dynamics.com\/MSCRMServices\/2007\/Passport\/CrmDiscoveryService.asmx\">https:\/\/dev.crm.dynamics.com\/MSCRMServices\/2007\/Passport\/CrmDiscoveryService.asmx<\/a>&#8220;;<br \/>\nRetrievePolicyRequest policyRequest = new RetrievePolicyRequest();<br \/>\nRetrievePolicyResponse policyResponse = (RetrievePolicyResponse)discoveryService.Execute(policyRequest);<br \/>\n\/\/ Retrieve a Windows Live ticket from the Live<br \/>\nservice.LogonManager lm = new LogonManager();<br \/>\nstring passportTicket = lm.Logon(&#8220;LiveWindowsUserId&#8221;, &#8220;password&#8221;, &#8220;crm.dynamics.com&#8221;, policyResponse.Policy, &#8220;Production&#8221;);<br \/>\nRetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();<br \/>\ncrmTicketRequest.OrganizationName = &#8220;OrganizationName&#8221;;<br \/>\ncrmTicketRequest.PassportTicket = passportTicket;<br \/>\nRetrieveCrmTicketResponse crmTicketResponse = (RetrieveCrmTicketResponse)discoveryService.Execute(crmTicketRequest);<br \/>\nCrmAuthenticationToken token = new CrmAuthenticationToken();<br \/>\ntoken.AuthenticationType = 1;<br \/>\ntoken.CrmTicket = crmTicketResponse.CrmTicket;<br \/>\ntoken.OrganizationName = crmTicketResponse.OrganizationDetail.OrganizationName;<br \/>\nNow, once you have the token assign it to the crmservice object as we do in on premise.<br \/>\n<strong><span style=\"text-decoration: underline;\">Hosted CRM connection:<\/span><\/strong><br \/>\nThis uses SPLA authentication. You need to use the userid and password provided to you by your hosting provider. You would also need to get the discovery URL from them.<br \/>\nFrom the discovery service URL you can retrieve the list of organizations.<br \/>\nRetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();<br \/>\norgRequest.UserId = username;<br \/>\norgRequest.Password = password;<br \/>\nRetrieveOrganizationsResponse orgResponse = (RetrieveOrganizationsResponse)disco.Execute(orgRequest);<br \/>\n\/\/Find the desired organization with which you want to connect.<br \/>\n\/\/Retrieve the ticket.<br \/>\nRetrieveCrmTicketRequest ticketRequest = new RetrieveCrmTicketRequest();<br \/>\nticketRequest.OrganizationName = organization;<br \/>\nticketRequest.UserId = username;<br \/>\nticketRequest.Password = password;<br \/>\nRetrieveCrmTicketResponse ticketResponse = (RetrieveCrmTicketResponse)disco.Execute(ticketRequest);<br \/>\n\/\/Create the CrmService Web service proxy.<br \/>\nCrmAuthenticationToken sdktoken = new CrmAuthenticationToken();<br \/>\nsdktoken.AuthenticationType = 2;<br \/>\nsdktoken.OrganizationName = organization;<br \/>\nsdktoken.CrmTicket = ticketResponse.CrmTicket;<br \/>\nNow, once you have the token assign it to the crmservice object as we do in on premise.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CRM supports various Deployment methods and unfortunately for the developers the method to connect to each of these differs. So here are the login functions for each of the Deployment methods supported by Dynamics CRM. On Premise CRM connection: On premise uses AD for authentication. CrmService service = new CrmService(); service.Url = &#8220;http:\/\/&#8221; + servername\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2009\/03\/how-to-login-to-various-crm-deployments\/\">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":[19],"tags":[331,407,409,410,1007,1298],"class_list":["post-218","post","type-post","status-publish","format-standard","hentry","category-dynamics-crm","tag-connection","tag-crm-live","tag-crm-on-premise","tag-crm-online","tag-login","tag-partner-hosted"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/218","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=218"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/218\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}