My Photo

Microsoft Dynamics 365

Official Blog for Microsoft Dynamics Functional and Technical Solutions....

Connect to Dynamics CRM / D365 WebApi v9 from Console Application C#

There are 2 major steps involved in the process.
  • Register the application with your Azure subscription
  • Build the Console Application

CRM / D365 Trial Organisation

Register the application with your Azure subscription

Step 1 Login to azure portal with your CRM credentials

Step 2 Click on Azure Active Directory - App registrations

 Step 3 Click on to New application registration

 Step 4 Enter Your Desired Name and Redirect URL but select Native in Application type and click on create Button

Step 5 After some some time you will be able to see your created apps then click on it

Step 6  Then click on Required permissions under API Access and then click on Add

Step 7  Click on Select API and then Select Dynamics CRM Online and Click on Select

Step 8  Select Access CRM Online as organisation users checkbox and click on Select Button

Step 9 Then click on Done

Build the Console Application 

Step 1 Navigate to Microsoft Url for sample for web API or click here quick start sample and extract to your desired location

Step 2 Open the Solution file in vs and you have to edit the code by reading the comment with TODO tag

Step 3 Update the service URLwith your current CRM organisation

        private static string serviceUrl = "";   // CRM Online

To get the client ID go to your app in Azure and copy the GUID specified for Application ID

To get the client ID go to your app in Azure and copy the GUID specified for Application ID and redirecting URL to Home Page URL ( will be same as you gave at the time of app creation in Redirecting URL)

Your Code should look like below

private static string serviceUrl = "";   // CRM Online
private static string userAccount = null;  //CRM user account
private static string domain = null;  //CRM server domain
private static string clientId = "e5cf0024-a66a-4f16-85ce-99ba97a24bb2";
private static string redirectUrl = "http://localhost";  //e.g. "http://localhost/SdkSample"

Step 3 Update Authentication Context with direct Authorisation Endpoint URL

To get Authorisation Endpoint URL go to your app in Azure click on Endpoints button

And copy the OAUTH 2.0 Authorization Endpoint URL

Replace the previous lines for getting authority information and update with the below code

string authority = "";
AuthenticationContext authContext = new AuthenticationContext(authority, false);

Your Code should look like below

//AuthenticationParameters ap = AuthenticationParameters.CreateFromResourceUrlAsync(
//        new Uri(serviceUrl + "api/data/")).Result;
//AuthenticationContext authContext = new AuthenticationContext(ap.Authority, false);

string authority = "";
AuthenticationContext authContext = new AuthenticationContext(authority, false);

AuthenticationResult authResult = authContext.AcquireToken(serviceUrl, clientId, new Uri(redirectUrl), PromptBehavior.Always);

The above code is connection with Prompt dialogue, for connection without prompt see my another thread - without prompt

Step 4 Rebuild

 Include the below reference to your project(to global config file the line before where your client credentials is configured) and change the .Net framework to 4.6.1 and rebuild 

"ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12"

for More details on it refer to my another thread here 

Step 5 Rebuild Your code and run it you will be prompted with sign in page enter your credentials

Step 5 Press on Accept

 And Your are done

You can have a look at my code here : My Sample Code

Inspired By : Nishant Rana's Weblog

Happy Coding and CRMing 😊


Dynamics CRM V9 / D365 connection Error Console or Custom Web Application

Last Night I Created a new Organisation and Connected it with console app an then I faced a strange issue in CRM v9 while connecting to Org Service with D365 through web API. It was perfectly working before that. If any one faces the below issue then try the solution given below.

Issue : Connection to CRM V9 / D365 from console application or Custom Web application failed with exception

Error Observed:

Message : "One or more errors occurred." 
Source : "mscorlib"


Its all because of the latest update in the Microsoft TSL(Transport Security Layer) Protocol in SDK assemblies..Microsoft allowed the TSL connection 1.0  and 1.1 for the browsers or client to connect the CRM org.Now Microsoft will support only TSL 1.2 or above going forward(Reference) . If you are connecting your org with the old version of plugin registration tool , then you may face this issue


Include the below reference to your project(to global config file the line before where your client credentials is configured) and change the .Net framework to 4.6.1 and rebuild 

"ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12"

Code Snippet :

//Create an HTTP client to send a request message to the CRM Web service.
                using (HttpClient httpClient = new HttpClient(messageHandler))
                    //Specify the Web API address of the service and the period of time each request
                    // has to execute.
                    httpClient.BaseAddress = new Uri(serviceUrl);
                    httpClient.Timeout = new TimeSpan(0, 2, 0);  //2 minutes

                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

                    //Send the WhoAmI request to the Web API using a GET request.
                    var response = httpClient.GetAsync("api/data/v9.0/WhoAmI",

                    if (response.IsSuccessStatusCode)
                        //Get the response content and parse it.
                        JObject body = JObject.Parse(response.Content.ReadAsStringAsync().Result);
                        Guid userId = (Guid)body["UserId"];
                        Console.WriteLine("Your system user ID is: {0}", userId);
                        Console.WriteLine("The request failed with a status of '{0}'",

Happy Coding 😊


CRM Rest Builder for Dynamics CRM D365 / MSCRM 2013, 2015, 2016

Navigate to the below URL and Download the latest version of the solution of CRM Rest Builder

For 2015 & 2016 & D365 use the v2.5.0.0 release
For 2011 & 2013 use the v1.5.0.0 release

1) CRM Rest Builder GIT Hub URL
2) CRM Rest Builder Drive  v2.5.0.0 , v1.5.0.0

And follow the below steps

Step 1 - Navigate to your Organisation Settings -> Solutions and click on Import Button

Step 2 - Click on to Browse Button

Step 3 - Navigate to the solution file previously downloaded and click on open and then click on Next

Step 4 - Click on to Import Button

Step 5 - After some time you will see the below success message

Step 6 - Now you will be able to see the CRM Rest Builder Button on the ribbon bar on solutions Click on it

And You are good to go with CRM Rest Builder

Happy CRMing 😊


Getting Started Free Trial - Live Assist for Microsoft Dynamics 365

Providing exceptional customer experience is the new competitive advantage. CaféX Live Assist™ for Microsoft Dynamics 365 enables personalised, omnichannel customer engagement that will delight your customers and improve your agents' productivity.
Hosted in the Azure cloud, the combined solution embeds real-time customer interaction within the Unified Service Desk and web clients for Dynamics 365. The immersive solution extends in-app live assistance to customers, who can interact with service representatives via text, co-browsing, bot escalation and more.
With CaféX Live Assist and Dynamics 365 tightly integrated, you can:
o   Proactively engage with chat
o   Problem solve faster with co-browse and bots
o   Ensure a 360-degree view throughout customers' journeys
o   Reduce operating costs and increase online sales
o   Deliver best-in-class digital experiences based on customers' unique preferences including mobile and web channels.


The prerequisites for  link Live Assist to Microsoft Dynamics 365 Customer Engagement  include:
o   An instance of Dynamics 365 Customer Engagement (Online)
    • You can request a trial of Dynamics 365 for Customer Engagement here

Setting Up Live Assist for Microsoft Dynamics 365

Step 1 - Validate / Promote your Current User to Admin 
1) Login into Your Microsoft D365 Account and navigate to Security Under Settings

2) Go to Users 

3) Select your current user and click on the ribbon button to Promote To Admin 

4) Click on OK 

Step 2 - Configure Live Assist for Dynamics 365

Navigate to Settings and then click on Dynamics Marketplace  

A popup will open type live in search box and you will see the below screen click on Free trial  

Validate the information and click on continue button by accepting the terms and condition

Select your organisation and press on Agree button to agree Microsoft Legal stuff 

On setup Live assist page validate the Dynamics 365 Instance page, enter your email address , accept cafex terms and condition and press on Submit

This configures the Live Assist on the specified Dynamics 365 Instance and also sends the email to the email id specified.

Step 3 - Login into Live assist Admin Center

After some time you will get an email confirmation on your provide email address once your live assist environment is configured 

Press on to login Button 

Enter and validate the details and Click on Confirm and Authorise

Click on Accept Button 

Select with the option for I wish to Begin my trial

Now you will be redirected to your Dashboard of the admin center.

Your are done with setting up Live Assist for Microsoft Dynamics 365

Click on to Get Started button to get started with Live assist

Happy CRMing 😊
Learn more

Create Your First Plugin Dynamics MS CRM

For your first Plugin we will take a test scenario - on create of contact record our plugin will forcefully update its email address to "" and to achieve this you just need to follow the below steps.

There are two parts to successfully run a plugin in MSCRM

1) Create Your Plugin
2) Resister your plugin

Plugin Creation

Step 1 - Open Visual studio

Step 2 - Go to File - New - and Click on Project

Step 3 - A dialogue will appear, from left navigation panel select Class Library template in Visual C#  and Enter Project and Solution name and hit on OK Button

Step 4 - Visual studio will create and open a blank class library template.Right Click on Project and click on Add References option

Step 5 - Reference Manager dialogue will open.From left navigation panel go to Assemblies - Framework then select two references and click on OK button
2) System.ServiceModel

Step 6 -  Right Click on Project and again click on Add References option, then in Reference Manager dialogue from left navigation panel go to Browse - Click on Browse button then select two references
2) System.ServiceModel

Step 7 -  After Click on Browse button go to your sdk (downloaded from prerequisites) - bin, then select the following dlls files and click on add and then OK button
1) miscrosoft.xrm.client.dll
2) Microsoft.Xrm.Sdk.dll

Step 8 -  Open the class named Class.cs from solution explorer and modify the below code in it.
If your namespace name and class name is different then remember to verify and update it.

Code Snippet : 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;

namespace My_First_Plugin
    public class Class1 : IPlugin     //{inherit the class Iplugin in your class}
        public void Execute(IServiceProvider serviceProvider)        //{add the execute method}
            // create context , service factory and service objects
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            //to enter  value in Email field in contact entity

            //create an object of predefined class Entity and pass entity name as its parameter
            Entity Object = new Entity("contact");   // in place of contact you can write schema name of entity on which you want to preform operations

            Object.Attributes.Add("emailaddress1", "");  //emailaddress1 is the schema name of the Email field in contact entity
             // is the value

            //to update the record service.Update(object of the entity)


After updating your code your code will look like this 

Step 9 -  Right click on Project and click on Properties

Step 10 -  Now, we have to create a key. Go to Signing - select the checkbox "Sign the assembly" and click on <New..> option 

Step 11 -  Enter any name you want for your Key and click on OK button

Step 12 -  Click on Save Button

Step 13 - Go to BUILD from ribbon menu and select Build Solution option

Will Update this thread Soon 

Happy Coding 😊