加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

在Microsoft Dynamics CRM(OData)中的单个请求中创建多个实体

发布时间:2020-12-14 05:45:18 所属栏目:Windows 来源:网络整理
导读:我知道如何在单个请求中创建单个实体.但是,有一个要求要我创建多个实体(在我的例子中,它是ContactSet中的多个条目).我尝试将数组放入 POST /XRMServices/2011/OrganizationData.svc/ContactSet [{ "MobilePhone": "+0012 555 555 555","YomiFullName" : "Dem
我知道如何在单个请求中创建单个实体.但是,有一个要求要我创建多个实体(在我的例子中,它是ContactSet中的多个条目).我尝试将数组放入

POST /XRMServices/2011/OrganizationData.svc/ContactSet

[{
    "MobilePhone": "+0012 555 555 555","YomiFullName" : "Demo User 1","GenderCode" : {
        "Value" : 1
      }
     .....
     <data removed for sanity>
     .....    
},{
    "MobilePhone": "+0012 555 555 111","YomiFullName" : "Demo User 2","GenderCode" : {
        "Value" : 1
      }
     .....
     <data removed for sanity>
     .....    

}]

然而,这不起作用,我找不到任何文件解释我实现这一目标的方法.任何帮助将不胜感激.

解决方法

您需要使用 ExecuteMultipleRequest,但我不认为这在Rest服务中可用,但在SOAP服务中可用.

// Get a reference to the organization service.
using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,serverConfig.HomeRealmUri,serverConfig.Credentials,serverConfig.DeviceCredentials))
{
    // Enable early-bound type support to add/update entity records required for this sample.
    _serviceProxy.EnableProxyTypes();

    #region Execute Multiple with Results
    // Create an ExecuteMultipleRequest object.
    requestWithResults = new ExecuteMultipleRequest()
    {
        // Assign settings that define execution behavior: continue on error,return responses. 
        Settings = new ExecuteMultipleSettings()
        {
            ContinueOnError = false,ReturnResponses = true
        },// Create an empty organization request collection.
        Requests = new OrganizationRequestCollection()
    };

    // Create several (local,in memory) entities in a collection. 
    EntityCollection input = GetCollectionOfEntitiesToCreate();

    // Add a CreateRequest for each entity to the request collection.
    foreach (var entity in input.Entities)
    {
        CreateRequest createRequest = new CreateRequest { Target = entity };
        requestWithResults.Requests.Add(createRequest);
    }

    // Execute all the requests in the request collection using a single web method call.
    ExecuteMultipleResponse responseWithResults =
        (ExecuteMultipleResponse)_serviceProxy.Execute(requestWithResults);

    // Display the results returned in the responses.
    foreach (var responseItem in responseWithResults.Responses)
    {
        // A valid response.
        if (responseItem.Response != null)
            DisplayResponse(requestWithResults.Requests[responseItem.RequestIndex],responseItem.Response);

        // An error has occurred.
        else if (responseItem.Fault != null)
            DisplayFault(requestWithResults.Requests[responseItem.RequestIndex],responseItem.RequestIndex,responseItem.Fault);
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读