简体   繁体   English

Dynamics CRM 365 Web Api使用哪个C#OData客户端库?

[英]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. 我正在通过OData Web Api调用Dynamics 365,我想知道我可以使用哪个客户端库来简化编程。

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. Currenlty我正在使用简单的HTTP Client类与Dynamics进行通信。

I am developing a .NET Core application for Linux hosts, because of this I can't use the Dynamics CRM SDK (SOAP Endpoint). 我正在为Linux主机开发.NET Core应用程序,因此,我无法使用Dynamics CRM SDK(SOAP端点)。

My question would be what your advice is: should I use Microsoft.OData.Client or Simple.OData.Client ? 我的问题是您的建议是:我应该使用Microsoft.OData.Client还是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/ 我根据本文尝试使用Microsoft.OData.Client并生成了一个客户端(proxy / wrapper): https : //blogs.msdn.microsoft.com/odatateam/2014/03/11/tutorial-sample-how-to -使用odata-client-code-generator生成客户端代理类/

The problem with this is that it generates a .cs filewith 86 MB file size. 问题是它会生成一个.cs文件,文件大小为86 MB。 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... 我想避免它,但是我没有找到生成它的选项。如果我不小心打开它,Visual Studio崩溃,Intellisense变慢了,如果打开了ReSharper,VS的速度就大大降低了,等等。

I checked Simple.OData.Client and seems to have nice documentation and API. 我检查了Simple.OData.Client,似乎有不错的文档和API。 For instance: https://github.com/object/Simple.OData.Client/wiki/Retrieving-data 例如: 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. 对于Microsoft.OData.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 我只在使用生成的上下文的地方找到了它: 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. 我认为使用Simple.OData.Client似乎是更好的选择,但我更喜欢使用Microsoft库。 Do you have any reccomendations? 你有什么建议吗?

I have just implemented integration from .Net Core Web App running in Azure App services to Dynamics 365 Web API as a POC. 我刚刚实现了从在Azure App服务中运行的.Net Core Web App到POC Dynamics 365 Web API的集成。 This included reading reference data ( joining different entities ) and modifying entities with referential data columns. 这包括读取参考数据(连接不同实体)和使用参考数据列修改实体。

Full OData interface generation is problematic I found: 我发现完整的OData接口生成是有问题的:

  • Could not find tooling that supports OAuth2 authorization and VS2019 找不到支持OAuth2授权和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. 完整的界面定义(包括导航属性/功能/动作)以及具有所有字段的所有实体变得难以导航,而VS导航则很缓慢。
  • 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. 根据要使用的OData客户端,它将通过网络发送比所需更多的信息,并增加了基础REST OData服务的精神。
  • 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. 生成的代码工具违反了C#编码规则(使用保留关键字,例如event,abstract,还生成了与封闭类型同名的成员),因此需要进行手动更正。

After much research I started using Simple.OData.Client as this allowed me 经过大量研究,我开始使用Simple.OData.Client,因为这使我

  • VS2019 / .Net core compatible toolset / runtime VS2019 / .Net核心兼容工具集/运行时
  • Connect to Dynamics 365 OData Web API with OAuth2 bearer token 使用OAuth2承载令牌连接到Dynamics 365 OData Web API
  • Write typed code in VS 在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 ) 只能选择您需要返回的实体属性,而不是200(较小的有效负载)

You have to create the entity classes used in the typed fluent API yourself 您必须自己创建在类型化的Fluent API中使用的实体类

Use DataContract attributes in case you want the CRM entity names to be different between CRM / C# code. 如果希望CRM / C#代码之间的CRM实体名称不同,请使用DataContract属性。 Simple.OData will then use the DataContract attributes when making up the Http call. 然后,在进行Http调用时,Simple.OData将使用DataContract属性。

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/ 不幸的是,当我开始更深入地研究OAuth2授权和导航属性之类的问题时,并没有找到所有如此有见地的文档,而是在诸如github问题和一些高级教程(例如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. 同样,使用Fiddler查看来回的通讯对于理解正在发生的事情非常有用。

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. Microsoft已经引入了Web API,这是一种RESTful Web服务,您可以使用它来使用各种平台,编程语言和设备与Dynamics 365中的数据进行交互。

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

This is a new way of communicating with Dynamics 365 programmatically. 这是通过编程方式与Dynamics 365进行通信的新方式。

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 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. 我个人使用过David Yack的图书馆。

https://github.com/davidyack https://github.com/davidyack

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM