In this blog post, we’ll learn to add a standard Microsoft Dataverse login to your Windows client app using XRM Tooling. Before we begin, ensure you subscribe to CRM Crate to remain informed about the latest developments in the Power Platform field.
Microsoft Dataverse, formerly known as the Common Data Service (CDS), is a cloud-based data storage and management service within the Microsoft Power Platform. It provides a secure and scalable repository where you can store and manage data used by business applications. Dataverse includes capabilities for defining data schemas, relationships, business rules, and security roles, making it suitable for building and deploying business applications without requiring extensive backend infrastructure.
Regarding user login, Microsoft Dataverse integrates with Microsoft’s identity management systems, such as Azure Active Directory (Azure AD) or Microsoft Intra ID. Users authenticate using their Azure AD credentials, which ensures secure access control and single sign-on (SSO) across various Microsoft services and applications. This integration simplifies user management and enhances security by leveraging Azure AD’s robust authentication mechanisms.
Utilizing a standing login control within your windows client applications
The common login control for Microsoft Dataverse integrates authentication logic, credential storage, retrieval, and diagnostic logging. This integration enables you to easily utilize these functionalities in your Windows (WPF) client applications for Dataverse.
Below are some key Prerequisites for using XRM tooling common login control:
- You’ll need .NET Framework 4.8 or a newer version.
- You should use Visual Studio 2019 or a more recent version.
- Make sure you have internet access to download the necessary NuGet packages.
- You’ll also need network access to a Dataverse environment and valid login credentials.
In this demonstration, we will use XRM Tooling Login Control within a Windows Presentation Foundation (WPF) application. Follow the below steps for building a new WFP application and incorporating a standard login control within it.
Step 1: Create a new WFP application.
- Open Visual Studio and begin by creating a new project using the WPF App (.NET Framework) template to develop a desktop application for Windows using C#.
- Set up the project and aim for compatibility with the .NET 4.8 framework.
- Create a project.
Step 2: Install NuGet Packages.
- Go to ‘Project’ and choose ‘Manage NuGet Packages’. Look up or search for the packages listed below, then install them into your project in the specified order
1. Microsoft.CrmSdk.XrmTooling.WpfControls
2. Microsoft.CrmSdk.XrmTooling.CoreAssembly
Step 3: Add login control XAML code files
- In the Solution Explorer, right-click on the project name and choose ‘Add’, then ‘New Folder’.
- Name the folder ‘LoginUX’ and then add the below given XAML code for the login control into that folder as shown below.
- Clean & build the project once done.
Step 4: Integrate the login control with the WPF application.
- You can view the Login Control within the file “ExampleLoginForm.xaml” by clicking on it.
- Next, open the file “MainWindow.xaml” to switch to the designer tab.
- Let’s now implement functionality where clicking a button in our application opens the Dataverse login control.
- In the designer, add a Button control and customize the Name and Common Content properties as desired.
- Double-click the button to open the code editor for adding the click event handler. This will bring up the “MainWindow” class file.
- Replace the empty Button_Click method with the following code to invoke the login control and instantiate the Dataverse connection object. Also add a new method “ctrl_ConnectionToCrmCompleted” within the same “MainWindow.xaml” file.
private void Button_Click(object sender, RoutedEventArgs e)
{
// Instantiate the login control.
ExampleLoginForm ctrl = new ExampleLoginForm();
// Wire the button click event to the login response.
ctrl.ConnectionToCrmCompleted += ctrl_ConnectionToCrmCompleted;
// Show the login control.
ctrl.ShowDialog();
// Check that a web service connection is returned and the service is ready.
if (ctrl.CrmConnectionMgr != null && ctrl.CrmConnectionMgr.CrmSvc != null && ctrl.CrmConnectionMgr.CrmSvc.IsReady)
{
// Display the Dataverse version and connected environment name
MessageBox.Show("Connected to Dataverse version: " + ctrl.CrmConnectionMgr.CrmSvc.ConnectedOrgVersion.ToString() +
" Organization: " + ctrl.CrmConnectionMgr.CrmSvc.ConnectedOrgUniqueName, "Connection Status");
// TODO Additional web service operations can be performed here
}
else
{
MessageBox.Show("Cannot connect; try again!", "Connection Status");
}
}
private void ctrl_ConnectionToCrmCompleted(object sender, EventArgs e)
{
if (sender is ExampleLoginForm)
{
this.Dispatcher.Invoke(() =>
{
((ExampleLoginForm)sender).Close();
});
}
}
Step 5: Build the application and test it to observe the login controls.
- Select the current project as “Set an startup project”.
- Run the application using “Start Without Debugging”.
- Now you can view and access the XRM Tooling Control as shown below.
Important Note
The content in this article is sourced from Microsoft documentation, ensuring accuracy and reliability.
Using the standard Micrososft Dataverse login control via XRM Tooling provides a reliable and secure method for accessing Microsoft Dataverse. It ensures streamlined authentication processes and robust data management capabilities, enhancing overall efficiency and data security within applications integrated with Dataverse.
Attractive section of content I just stumbled upon your blog and in accession capital to assert that I get actually enjoyed account your blog posts Anyway I will be subscribing to your augment and even I achievement you access consistently fast
Rely on BWER Company for superior weighbridge solutions in Iraq, offering advanced designs, unmatched precision, and tailored services for diverse industrial applications.