运行 关于 Dynamics 365 的查询 API

Run a query on the Dynamics 365 API

我正在寻找一些简单的样板代码,我可以使用它们来 运行 针对 Dynamics 365 API 的查询并获取一些 JSON.

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

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

一些要点:

1.Read代码里面的注释。非常重要的一个:

/// 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.The 方法 ConnectToCRM 将进行身份验证 & HttpClient 调用

3.Almost 代码示例中解释了包括 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);