无法使用外部包装器 (davidyack) 在 mvc 核心中执行 MSCRM Webapi 自定义绑定操作

Unable to execute MSCRM Webapi Custom Bound Action in mvc core using external wrapper (davidyack)

我无法使用适用于 mscrm webapi 的 David Yack 包装器在 MSCRM 中执行绑定的自定义操作 github。我可以使用 MSCRM SDK 库轻松执行操作,但是因为我使用的是 MVC 核心 2.2,所以这些 DLL 对我不可用,我发现最好的选择是 david 的包装器,尽管在文档方面很薄,但它很棒。

我尝试了各种执行动作的方法。如果操作是没有参数的未绑定自定义操作,我就可以开始工作。我在实体绑定操作和传递参数以及关联的实体 ID 上没有运气。

我曾尝试在文档中找到一个 C# 示例,但事实证明这很困难。

我试图在下面的 SDK 代码中实现相同的功能,但使用的是 David 的包装器。

OrganizationRequest request = new OrganizationRequest("new_GetProductBuyPrice");
request["Target"] = new EntityReference("product", new Guid(ProductID));
request["Account"] = new EntityReference("account", new Guid(AccountID));
request["Currency"] = new EntityReference("transactionalcurrency", new Guid(CurrencyID));
request["Qty"] = 1.00m;

OrganizationResponse response = Xrm.XrmSvc.Execute(request);
UnitBuy = Math.Round(((Money)response.Results["BuyPrice"]).Value, 2);
DiscountReason = response.Results.Contains("DiscountReason") ? response.Results["DiscountReason"].ToString() : string.Empty;

如何让 david 的包装程序与我在 CRM 中的自定义操作一起执行?

因此,设法在 github 上使用 David Yack API 包装器解决了这个问题,并且只是 post 了我的发现,以防万一有人偶然发现这个 post。他们的关键是使用字典,就好像它是 Microsoft SDK 中的 EntityReference class,并使用“@odata.type”作为实体类型,实体 ID 全部小写,如下所示:

dynamic AccountRef = new Dictionary<String, object>();
            AccountRef["@odata.type"] = "Microsoft.Dynamics.CRM.account";
            AccountRef["accountid"] = AccountId.ToString();

            dynamic CurrencyRef = new Dictionary<String, object>();
            CurrencyRef["@odata.type"] = "Microsoft.Dynamics.CRM.transactioncurrency";
            CurrencyRef["transactioncurrencyid"] = CurrencyId.ToString();

            var actionParams = new
            {
                Account = AccountRef,
                Currency = CurrencyRef,
                Qty = 1.00m
            };
            var response = await _crmClient.API.ExecuteAction("Microsoft.Dynamics.CRM.new_GetProductBuyPrice", "products", ProductId, actionParams);