如何使用web api获取资源的可用性?

l--*_*''' 6 c# rest microsoft-dynamics dynamics-crm asp.net-web-api2

CRM 2016公开了odata/web api,并且具有开箱即用的功能和操作.

通过组织服务,我们可以发出如下请求:

// Create the van required resource object.
RequiredResource vanReq = new RequiredResource
{
    ResourceId = _vanId,
    ResourceSpecId = _specId
};

// Create the appointment request.
AppointmentRequest appointmentReq = new AppointmentRequest
{
    RequiredResources = new RequiredResource[] { vanReq },
    Direction = SearchDirection.Backward,
    Duration = 60,
    NumberOfResults = 10,
    ServiceId = _plumberServiceId,
    // The search window describes the time when the resouce can be scheduled.
    // It must be set.
    SearchWindowStart = DateTime.Now.ToUniversalTime(),
    SearchWindowEnd = DateTime.Now.AddDays(7).ToUniversalTime(),
    UserTimeZoneCode = 1
};

// Verify whether there are openings available to schedule the appointment using this resource              
SearchRequest search = new SearchRequest
{
    AppointmentRequest = appointmentReq
};
SearchResponse searched = (SearchResponse)_serviceProxy.Execute(search);

if (searched.SearchResults.Proposals.Length > 0)
{
    Console.WriteLine("Openings are available to schedule the resource.");
}
Run Code Online (Sandbox Code Playgroud)

是否可以使用函数/动作或任何其他odata功能来模仿此功能?

我相信请求应该是这样的:

crmOrg/api/v8.1/Search(AppointmentRequest=@request)?@request=
Run Code Online (Sandbox Code Playgroud)

但是,我不确定如何编码请求的其余部分.

Ond*_*dar 3

参数如下:

http://yourcrm.org/org/api/data/v8.1/Search(AppointmentRequest=@ar)/?@ar={SearchWindowStart:%272017-01-01%27,Duration:60,NumberOfResults:10}
Run Code Online (Sandbox Code Playgroud)

它是序列化AppointmentRequest类的 url 编码的 json。

{
  SearchWindowStart:'2017-01-01',
  Duration: 60,
  NumberOfResults:10,
  etc...
}
Run Code Online (Sandbox Code Playgroud)

更多信息请参见:https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.appointmentrequest.aspx

ODATA参考:http://odata.github.io/WebApi/04-06-function-parameter-support/