如何在服务器端异步检索 Dynamics CRM 365 数据

How to retrieve Dynamics CRM 365 data asynchronous on server side

我正在实施一个 Web API,它从多个 Microsoft Dynamics CRM 365 检索数据,汇总数据,然后 returns 将其发送给调用者。

我想知道是否可以从 CRM 组织服务异步检索数据。 CrmServiceClient 和 CrmSvcUtil 提供的异步操作生成的 ServiceContext 都没有。
是否无法进行异步 crm 查询调用?

Xrm.WebApi 的 Http 请求默认是异步的,例如Xrm.WebApi.retrieveRecord。我链接的 API 文档中的示例是用 JavaScript 编写的,但您当然也可以从 C# 向 WebApi 发出 Http 请求。

This document 使用 C# 和 HttpClient.SendAsync() 演示了对 WebApi 的基本 CRUD 操作。摘录:

string connectionString = ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;

using (HttpClient client = SampleHelpers.GetHttpClient(
   connectionString,
   SampleHelpers.clientId,
   SampleHelpers.redirectUrl,"v9.0"))
{
   Console.WriteLine("--Section 1 started--");
   string queryOptions;
   contact1.Add("firstname", "Rafel");
   contact1.Add("lastname", "Shillo");

   HttpRequestMessage createrequest1 = new HttpRequestMessage(HttpMethod.Post, 
      client.BaseAddress + "contacts");
   createrequest1.Content = new StringContent(contact1.ToString());
   createrequest1.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

   HttpResponseMessage createResponse1 = client.SendAsync(createrequest1, 
   HttpCompletionOption.ResponseHeadersRead).Result;

   if (createResponse1.IsSuccessStatusCode)
   {
      Console.WriteLine("Contact '{0} {1}' created.", contact1.GetValue("firstname"), contact1.GetValue("lastname"));
      contact1Uri = createResponse1.Headers.GetValues("OData-EntityId").FirstOrDefault();
      entityUris.Add(contact1Uri);
      Console.WriteLine("Contact URI: {0}", contact1Uri);
   }
}