Microsoft has annouced .Net Core SDK which can be used to Connect to CRM from .Net Core application.
Some of the limitations of current version of SDK
- This package is an ALPHA release. – Use at your own risk.
- This package is intended to work with .net full framework 4.6.2, 4.7.2 and 4.8, .net core 3.0 and 3.1
- We have not stabilized on NameSpace or Class names with this package as of yet and things will change as we move though the preview.
- General Documentation is the same as CrmServiceClient and can be found here:
https://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.tooling.connector.crmserviceclient?view=dynamics-xrmtooling-ce-9 - Connection String Docs can be found here:
https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/xrm-tooling/use-connection-strings-xrm-tooling-connect
Note: that only OAuth, Certificate, ClientSecret Authentication types are supported at this time.
C# Code to connect to CRM Dynamics Online using .Net Core SDK
Install below nuget package on your .Net core project
Install-Package Microsoft.Powerplatform.Cds.Client -Version 0.2.14-Alpha
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; var cdsClient = new CdsServiceClient("AuthType = ClientSecret; ClientId=ed841ef3-a44a-43f4-b097-9f6005437c8b; Url = https://CRMOrg.crm.dynamics.com; ClientSecret=****;"); if (cdsClient.IsReady) { Console.WriteLine("Hello, connected to CDS using .NET Core"); //cdsClient.CallerId = Guid.Parse("bc1809ae-552f-48d0-8f2d-75bf4f6f927b"); Entity newAccount = new Entity("account"); newAccount["name"] = "Test .NET Core"; cdsClient.Create(newAccount); QueryExpression query = new QueryExpression("account"); query.ColumnSet = new ColumnSet(true); var response = cdsClient.RetrieveMultiple(query); foreach (var item in response.Entities) { Console.WriteLine($"Account: {item.GetAttributeValue("name")} [{item.GetAttributeValue("ownerid").Name}]"); } } else { Console.WriteLine("Failed to connect to CDS using .NET Core :("); } Console.ReadKey();
Note:-
Currently impersonation with callerId is not working
//cdsClient.CallerId = Guid.Parse(“bc1809ae-552f-48d0-8f2d-75bf4f6f927b”);
Use below code to impersonate web service call
cdsClient.CallerAADObjectId= Guid.Parse(“bc1809ae-552f-48d0-8f2d-75bf4f6f7659”);
Hope this helps!
That’s helpful, thank you
LikeLike