【问题标题】:Run a query on the Dynamics 365 API在 Dynamics 365 API 上运行查询
【发布时间】:2023-03-20 10:01:01
【问题描述】:

我正在寻找一些简单的样板代码,可用于针对 Dynamics 365 API 运行查询并获取一些 JSON。

最好使用 WebClient 或 HttpClient。没有什么花哨。最简单、可重复使用的示例得到了答案。

【问题讨论】:

标签: c# azure dynamics-crm dynamics-crm-online dynamics-crm-webapi


【解决方案1】:

您可以在 SDK 示例中找到示例代码。同样解释here

一些关键点:

1.阅读代码里面的cmets。非常重要的一个:

/// Before building this application, you must first modify the following configuration   
/// information in the app.config file:  
///   - All deployments: Provide connection string service URL's for your organization.  
///   - CRM (online): Replace the application settings with the correct values for your    
///                 Azure app registration.

2.方法ConnectToCRM会做认证片&HttpClient调用

3. 代码示例中解释了包括 fetchxml 在内的几乎每一种查询类型

如果您需要帮助从 Azure 注册的 CRM appId 获取 AccessToken,请参考 Jason Lattimer blog

整体简单的样板代码和步骤可以在Inogic blog找到。

HttpClient httpClient= null;
httpClient = new HttpClient();
 //Default Request Headers needed to be added in the HttpClient Object
httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
 
 //Set the Authorization header with the Access Token received specifying the Credentials
 httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _result.AccessToken);

【讨论】:

  • 我应该实现 QueryData 类吗?
  • @MarkMicallef 这不是一个库。这是一个完整的控制台应用程序代码,其中包含要运行的命名空间、类、方法和 Main。
  • 我只想访问一个端点并取回一些 JSON 数据。看起来非常复杂。
  • 你的示例代码中的AccessToken是从哪里来的?
猜你喜欢
  • 1970-01-01
  • 2015-06-04
  • 2018-11-09
  • 2018-06-08
  • 1970-01-01
  • 2017-05-06
  • 2021-06-28
  • 1970-01-01
  • 2020-01-17
相关资源
最近更新 更多