简体   繁体   English

在 Dynamics 365 API 上运行查询

[英]Run a query on the Dynamics 365 API

I'm looking for some simple boilerplate code I can use to run a query against the Dynamics 365 API and grab out some JSON.我正在寻找一些简单的样板代码,可用于对 Dynamics 365 API 运行查询并获取一些 JSON。

Preferably using WebClient or HttpClient.最好使用 WebClient 或 HttpClient。 Nothing fancy.没有什么花哨。 Simplest, reusable example gets the answer.最简单、可重用的示例得到了答案。

You can find example code in SDK samples.您可以在 SDK 示例中找到示例代码。 Same is explained here .相同的解释here

Some key points:一些关键点:

1.Read the comments inside the code. 1.阅读代码中的注释。 Very important one:很重要的一点:

/// 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 method ConnectToCRM will do authentication piece & HttpClient call 2.方法ConnectToCRM会做验证件与HttpClient通话

3.Almost every single type of query including fetchxml is explained in the code sample 3.代码示例中解释了几乎所有类型的查询,包括 fetchxml

If you need help to get AccessToken from Azure registered CRM appId, then refer Jason Lattimer blog .如果需要帮助从 Azure 注册的 CRM appId 获取AccessToken ,请参阅Jason Lattimer 博客

The overall simple boiler plate code & steps can be found in Inogic blog .整体简单的样板代码和步骤可以在Inogic 博客中找到。

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);

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

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