Which C# OData Client library to use for Dynamics CRM 365 Web Api?
Asked Answered
M

2

9

I'm calling Dynamics 365 through it's OData Web Api and I'm wondering which client library I could use to make programming easier.

My use case is that I mainly have to work with one entity: contact. I would like to retrieve some data, edit data and create new contacts. The other entity type I'm working with in a similar way is address. A contact can have multiple addresses.

Currenlty I'm using plain HTTP Client class for the communication to Dynamics.

I am developing a .NET Core application for Linux hosts, because of this I can't use the Dynamics CRM SDK (SOAP Endpoint).

My question would be what your advice is: should I use Microsoft.OData.Client or Simple.OData.Client? Or any other library?

I tried to use Microsoft.OData.Client and generated a client (proxy/wrapper) according to this article: https://blogs.msdn.microsoft.com/odatateam/2014/03/11/tutorial-sample-how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class/

The problem with this is that it generates a .cs filewith 86 MB file size. Maybe it could be a solution to use this client afterwards, but it just seems so wrong to have such a big source file in our project. I would like to avoid it, but I didn't find an option to generate this If I accidentally open it, Visual Studio crashes, intellisense get's slow some times, if ReSharper is turned on VS is slowed down enourmously, etc...

I checked Simple.OData.Client and seems to have nice documentation and API. For instance: https://github.com/object/Simple.OData.Client/wiki/Retrieving-data

For Microsoft.OData.Client I didn't find documentation how to use it in a typed manner without generating the whole client. Is that possible? I only found this, where the generated context is used: http://odata.github.io/odata.net/v6/#04-01-basic-crud-operations

I think going with Simple.OData.Client seems to be a better option, but I would prefer to use a Microsoft library. Do you have any reccomendations?

Macdonell answered 5/11, 2018 at 15:54 Comment(1)
"Dynamics CRM SDK (SOAP Endpoint)" -- can you link documentation or otherwise why you believe the Dynamics CRM/Dataverse SDK's use SOAP? I've never seen that detail documented about the CRM .NET SDK's.Dishearten
L
6

I have just implemented integration from .Net Core Web App running in Azure App services to Dynamics 365 Web API as a POC. This included reading reference data ( joining different entities ) and modifying entities with referential data columns.

Full OData interface generation is problematic I found:

  • Could not find tooling that supports OAuth2 authorization and VS2019
  • Full interface definition inclusive of navigational properties / functions / actions and all entities with all fields becomes unwieldy to navigate and VS navigation is sluggish.
  • Depending on OData client you are going to use it will be sending much more information over the wire than needed and add complexity that is not in the spirit of the underlying REST OData service.
  • Generated code tools violated C# coding rules ( using reserved keywords like event, abstract and also generating members with same name as enclosing type ) requiring manual correction.

After much research I started using Simple.OData.Client as this allowed me

  • VS2019 / .Net core compatible toolset / runtime
  • Connect to Dynamics 365 OData Web API with OAuth2 bearer token
  • Write typed code in VS
  • Create only the entity models / navigational properties etc that I needed
  • Can select only the entity attributes you need to return instead of 200 ( smaller payloads )

You have to create the entity classes used in the typed fluent API yourself

Use DataContract attributes in case you want the CRM entity names to be different between CRM / C# code. Simple.OData will then use the DataContract attributes when making up the Http call.

Unfortunately I didn't find the documentation all that insightful when I started looking deeper on issues like OAuth2 authorization and navigational properties but did find all my answers in secondary sources like github issues and some advanced tutorials for example https://www.odata.org/blog/advanced-odata-tutorial-with-simple-odata-client/

Also using Fiddler to see the communications going back and forth is unbelievably useful in understanding what is going on.

Landbert answered 14/10, 2019 at 5:55 Comment(3)
Thank you so much for this answer! I have been struggling into integrating the web api in my project!Sotos
Is there other projects targeting .net5 that could be used to call Dynamics 365 Web API ?Damned
Just found that Microsoft.AspNetCore.OData 8.x targets .net5Damned
B
-3

Microsoft has introduced a Web API, a RESTful web service you can use to interact with data in Dynamics 365 using a wide variety of platforms, programming languages, and devices.

https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/perform-operations-web-api

This is a new way of communicating with Dynamics 365 programmatically.

There are several libraries available that you can use. From below article, you can find those.

https://community.dynamics.com/crm/b/briteglobalsolutions/archive/2017/10/22/webapi-library-comparison-in-dynamics-365

I have personally used David Yack's library.

https://github.com/davidyack

Hope this helps.

Blackburn answered 6/11, 2018 at 4:34 Comment(2)
I'm aware of the Web API, I'm using it already. I am using C#, not javascript like the links you have sent. I would like to use a .net core or .net standard C# library to make the usage of the API more convinient.Macdonell
You can use this API using c# as wellBlackburn

© 2022 - 2024 — McMap. All rights reserved.