Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 431
Tamas Molnar Avatar asked Nov 05 '18 15:11

Tamas Molnar


People also ask

What does %c mean in C?

%d is used to print decimal(integer) number ,while %c is used to print character . If you try to print a character with %d format the computer will print the ASCII code of the character.

What is code C used for?

C is used as a programming language in several ways, such as: In IoT, also known as the "Internet of things," applications. Compiler development. When developing the operating system used on a desktop or smartphone.

Which language C is?

C (/ˈsiː/, as in the letter c) is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential.

What is C in easy language?

" " C is a computer programming language. That means that you can use C to create lists of instructions for a computer to follow. C is one of thousands of programming languages currently in use.


Video Answer


1 Answers

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.

like image 177
Rohan Avatar answered Oct 06 '22 05:10

Rohan