Skip to content
Microsoft Dynamics 365 CRM Tips and Tricks
By Inogic
  • Blogs
  • D365 Apps
  • Inogic
  • D365 / Power Platform Services
  • Maplytics Docs
  • D365 Apps Docs
    • Omnichannel Apps
      • WhatsApp4Dynamics
      • TextSMS4Dynamics
      • LiveChat4Dynamics
    • File and Storage Managment
      • Attach2Dynamics
      • SharePoint Security Sync
    • AI/Copilot Apps
      • SharePoint Knowledge AI Search
      • Predict4Dynamics
    • Visualization Apps
      • Map My Relationships
      • Kanban Board
      • Business Process Checklist
    • Productivity Apps
      • Click2Clone
      • Click2Export
      • Undo2Restore
      • Lead Assignment and Distribution Automation
      • Alerts4Dynamics
      • Translate4Dynamics
      • Subscription Recurring Billing Management
    • User Adoption Apps
      • DeDupeD
      • User Adoption Monitor
      • Gamifics365
    • Integration Apps
      • Marketing4Dynamics
      • InoLink

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 Pages
  • Power Automate
  • Power BI
  • AI Builder
  • Copilot
  • Azure OpenAI
  • Microsoft Teams
  • Dynamics 365 for Field Service

Recent Innovations

Fix SharePoint’s 5000-Item Limit in Dynamics 365 (2026 Guide)

What Is the Best Way to Manage Files and Attachments in CRM?

How to Identify Duplicates in Dynamics 365 CRM (Step-by-Step Guide 2026)

AI-Powered WhatsApp Sentiment Analysis for Smarter Customer Support in Dynamics 365

The Ultimate Guide to AI Semantic Search in SharePoint with Microsoft Copilot

The Complete Guide to Dynamics 365 CRM + Mailchimp Integration (2026)

Top Reasons your Dynamics 365 CRM Needs a Translation App today!

Guide to Branding Your Dynamics 365 Live Chat Integration App!

Recent Posts

  • How the Sales Qualification Agent Transforms Lead Management in Dynamics 365
  • How to Export Data from Dynamics 365 Automatically: A Complete Guide
  • Generating and Sharing Screen in PDFs from D365 Sales Using Canvas Apps
  • 5 Practical Sales Strategies That Deliver Measurable Results
  • How to Customize the Task Pane in Project Operations

Archives

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