Microsoft Dynamics 365 CRM Tips and Tricks
By Inogic
Skip to content
  • Blogs
  • D365 Apps
  • Inogic
  • D365 / Power Platform Services
  • Maplytics Docs
  • New D365 Apps Docs
    • Subscription Recurring Billing Management
    • Marketing4Dynamics
    • Gamifics365
    • Business Process Checklist
  • D365 Apps Docs
    • Alerts4Dynamics
    • Attach2Dynamics
    • SharePoint Security Sync
    • Kanban Board
    • Lead Assignment and Distribution Automation
    • Map My Relationships
    • User Adoption Monitor
    • InoLink
    • Click2Clone
    • Click2Export
    • Undo2Restore
    • Auto Tax Calculator

How to Login to various CRM deployments

By Inogic | March 5, 2009
0 Comment

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 = “http://” + servername + “/mscrmservices/2007/crmservice.asmx”;
service.CrmAuthenticationTokenValue.OrganizationName = “orgname”;
service.CrmAuthenticationTokenValue.AuthenticationType = 0;
service.Credentials = new System.Net.NetworkCredential(“username”, “Password”, “DomainName”);
OR
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
Live CRM connection:
CRM Live uses Passport authentication. It requires a reference to the Idcrlwrapper be added. The Idcrlwrapper is available along with the SDK as helper files.
Make sure you have copied the msidcrl40.dll to the system32 folder before you try to run this code.
CrmDiscoveryService discoveryService = new CrmDiscoveryService();
discoveryService.Url = “https://dev.crm.dynamics.com/MSCRMServices/2007/Passport/CrmDiscoveryService.asmx“;
RetrievePolicyRequest policyRequest = new RetrievePolicyRequest();
RetrievePolicyResponse policyResponse = (RetrievePolicyResponse)discoveryService.Execute(policyRequest);
// Retrieve a Windows Live ticket from the Live
service.LogonManager lm = new LogonManager();
string passportTicket = lm.Logon(“LiveWindowsUserId”, “password”, “crm.dynamics.com”, policyResponse.Policy, “Production”);
RetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();
crmTicketRequest.OrganizationName = “OrganizationName”;
crmTicketRequest.PassportTicket = passportTicket;
RetrieveCrmTicketResponse crmTicketResponse = (RetrieveCrmTicketResponse)discoveryService.Execute(crmTicketRequest);
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 1;
token.CrmTicket = crmTicketResponse.CrmTicket;
token.OrganizationName = crmTicketResponse.OrganizationDetail.OrganizationName;
Now, once you have the token assign it to the crmservice object as we do in on premise.
Hosted CRM connection:
This 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.
From the discovery service URL you can retrieve the list of organizations.
RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
orgRequest.UserId = username;
orgRequest.Password = password;
RetrieveOrganizationsResponse orgResponse = (RetrieveOrganizationsResponse)disco.Execute(orgRequest);
//Find the desired organization with which you want to connect.
//Retrieve the ticket.
RetrieveCrmTicketRequest ticketRequest = new RetrieveCrmTicketRequest();
ticketRequest.OrganizationName = organization;
ticketRequest.UserId = username;
ticketRequest.Password = password;
RetrieveCrmTicketResponse ticketResponse = (RetrieveCrmTicketResponse)disco.Execute(ticketRequest);
//Create the CrmService Web service proxy.
CrmAuthenticationToken sdktoken = new CrmAuthenticationToken();
sdktoken.AuthenticationType = 2;
sdktoken.OrganizationName = organization;
sdktoken.CrmTicket = ticketResponse.CrmTicket;
Now, once you have the token assign it to the crmservice object as we do in on premise.

Category: Dynamics CRM Tags: Connection, CRM Live, CRM On-premise, CRM Online, Login, Partner Hosted
Post navigation
← List of Events available to trap in Scripts when saving a Dynamics CRM Form How to use the Duplicate Detection Feature of CRM →

Follow Us!

Follow Us on FacebookFollow Us on TwitterFollow Us on LinkedInFollow Us on YouTubeFollow Us on InstagramFollow Us on E-mailFollow Us on Docs

Blog Series

  • Power Apps – Model Driven Apps
  • Power Apps – Canvas App
  • Power Apps Portal
  • Power Automate
  • Power BI
  • AI Builder
  • Dynamics 365 for Field Service
  • Dynamics 365 for Project Service Automation
  • Dynamics 365 for Mobiles and Tablets

Recent Updates

New Release: Business Process Checklist app for streamlining business processes in Microsoft Dynamics 365 CRM

Document Management Solution for your Dynamics 365 CRM – How to choose the better one?

Integrate Dynamics 365 Customer Engagement with SharePoint – The secure way!

Get valuable insights into CRM data with new-age smart Data Visualization apps – Kanban Board and Map My Relationships!

Visualize intricate details in Dynamics 365 CRM with finesse using latest Map My Relationships feature

Top 5 Reasons why Subscription and Recurring Billing Management is must for easy subscription management within Dynamics 365 CRM!

QuickBooks Online + Dynamics 365 CRM – Get Accounting & Sales Data on one platform with InoLink!

From beginners to experts – Shorten the journey of adapting to Dynamics 365 CRM with our advanced User Adoption Monitor app!

New Age Automation App to Clone/Copy Records in Dynamics 365 CRM with just 1 Click

1 Click is all you need to Undo, Restore / Retrieve Deleted Data within Dynamics 365 CRM!

Bid goodbye to export woes with Dynamics 365 CRM 1 Click productivity app – Click2Export

Alerts4Dynamics – New age Dynamics 365 CRM alert management solution to bridge the information gap!

Automatically set user availability while assigning leads in Dynamics 365 CRM – New Feature of our Lead Assignment and Distribution Automation!

Mailchimp integration with Dynamics 365 CRM – Sync Audience, Tags, Campaigns and more!

Gamification in Microsoft Dynamics 365 CRM – Set goals, Make them fun, and Everyone wins!

Recent Posts

  • Outsourcing Dynamics 365 and Power Platform Development – Choose Inogic for Experience, Expertise, and More!
  • Microsoft Release 2023 Wave 1: Form creation and management in Real-Time Marketing – Part 2
  • Configure the Right Subscription-Based Pricing Model for Your Product within Microsoft Dynamics 365 CRM!
  • Microsoft Release 2023 Wave 1: Form creation and management in Real-Time Marketing – Part 1
  • Webinar: The Magic of Gamification in Microsoft Dynamics 365 CRM with Gamifics365!

Archives

SiteLock
Copyright © 2023 Inogic. All Rights Reserved
Iconic One Theme | Powered by Wordpress