【发布时间】:2020-10-06 19:21:58
【问题描述】:
TL;DR:
我正在调用 WebApi,WebApi 针对 CRM 进行身份验证并使用 IOrganizationService,所以我的请求是 JObject 而不是 Entity 或 EntityReference,它给了我这个错误:
Error: Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported. Consider modifying the definition of collection 'Newtonsoft.Json.Linq.JToken' to remove references to itself.
上下文:
我用 Angular 构建了一个 Web 应用程序,并构建了一个 WebApi,因此我可以在 CRM 中调用一些自定义操作:
Angular 应用程序 | WebAPI |本地 CRM
所以,当我调用 WebApi 时,有一个控制器将我的请求转换为 OrganizationRequest:
WebApi 请求:
{
"ActionName": "custom_actionname",
"Parameters":
[
{
"Key": "EntityInputParameter1",
"Value": {"@odata.type":"Microsoft.Dynamics.CRM.any_entity"}
}
]
}
我在我的 WebApi 上阅读了此请求并将其转换为对 CRM 的请求
申请 CRM:
OrganizationRequest request = new OrganizationRequest("custom_actionname");
request.Parameters["EntityInputParameter1"] = {"@odata.type":"Microsoft.Dynamics.CRM.any_entity"} // This is a JObject
OrganizationResponse response = service.Execute(request);
当我提出请求时,它给了我以下错误:
Error: Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported. Consider modifying the definition of collection 'Newtonsoft.Json.Linq.JToken' to remove references to itself.
如果我直接向它工作的操作发出请求,但由于安全策略,我不能这样做。
一种选择是将请求转换为有效的 CRM 请求(将 {"@odata.type":"Microsoft.Dynamics.CRM.any_entity} 解析为 Entity 类型),但 CRM 有很多解析场景并且可能非常复杂。
另一种选择是通过网络发送请求并停止使用IOrganizationService,但我无法更改。
我提出这个问题是为了让任何有这个错误的人都能找到“解决方案”,因为我搜索了很多,没有人直接提到这种行为。
我可能正在将我的 InputEntityParameter 转换为字符串,并且我将发送 JSON,因此我可以在我的操作中解析 JSON,但我正在查看是否有其他人有此错误或其他方法。
【问题讨论】:
-
你的
EntityInputParameter1是什么类型我怀疑是实体引用类型? -
@AnkUser 类型为实体
标签: c# asp.net-web-api dynamics-crm