c# - 使用分页 cookie 的 MS Dynamics REST API FetchXML

标签 c# cookies dynamics-crm-2011 dynamics-crm crm

我正在使用这种方法,可在 MSDN 上找到。检索超过 5000 条记录。我将 MS Dynamics REST API 与 fetchXML 一起使用。我的第一个请求如下所示:

//ROOT.dynamics.com//api/data/v8.1/contacts?fetchXml=<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="contact"><attribute name="emailaddress1" /></entity></fetch>

结果我得到了下一页的记录集和页面 cookie:

"@Microsoft.Dynamics.CRM.fetchxmlpagingcookie":"<cookie pagenumber=\"2\" pagingcookie=\"%253ccookie%2520page%253d%25221%2522%253e%253ccontactid%2520last%253d%2522%257bAF17816D-3AAE-E511-80FC-1458D043A570%257d%2522%2520first%253d%2522%257bFF672EF5-22AE-E511-80FC-1458D043A570%257d%2522%2520%252f%253e%253c%252fcookie%253e\" istracking=\"False\" />"

我在下一个请求中使用此 cookie:

//ROOT.dynamics.com//api/data/v8.1/contacts?fetchXml=<fetch mapping='logical' paging-cookie='&lt;cookie page="1"&gt;&lt;contactid last="{UUID}" first="UUID}"/&gt;&lt;/cookie&gt;' page='2'><entity name='contact'><all-attributes/></entity></fetch>

得到了

{
Message: "An item with the same key has already been added.",
ExceptionMessage: "An item with the same key has already been added.",
ExceptionType: "System.ArgumentException",
StackTrace: " at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector) at Microsoft.Crm.Extensibility.OData.CrmODataHeaders.ProcessVersioningQueryParameters() at Microsoft.Crm.Extensibility.OData.CrmODataHeaders..ctor(HttpRequestMessage request) at Microsoft.Crm.Extensibility.OData.Extensions.EdmExtensions.GetCrmODataRequestHeader(HttpRequestMessage request) at Microsoft.Crm.Extensibility.OData.CrmODataRoutingConvention.SelectController(ODataPath odataPath, HttpRequestMessage request) at System.Web.OData.Routing.ODataPathRouteConstraint.SelectControllerName(ODataPath path, HttpRequestMessage request) at System.Web.OData.Routing.ODataPathRouteConstraint.Match(HttpRequestMessage request, IHttpRoute route, String parameterName, IDictionary`2 values, HttpRouteDirection routeDirection) at System.Web.Http.Routing.HttpRoute.ProcessConstraint(HttpRequestMessage request, Object constraint, String parameterName, HttpRouteValueDictionary values, HttpRouteDirection routeDirection) at System.Web.Http.Routing.HttpRoute.ProcessConstraints(HttpRequestMessage request, HttpRouteValueDictionary values, HttpRouteDirection routeDirection) at System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)",
ErrorCode: 500
}

这个 fetchXML 在此 tool 内运行良好但不适用于纯 REST API 请求。 也许我对 URL 的编码或结构有一些问题。

最佳答案

我遇到了同样的问题,我的解决方案是对分页 cookie 中的&符号进行 uri 编码

//ROOT.dynamics.com//api/data/v8.1/contacts?fetchXml=<fetch mapping='logical' paging-cookie='%26lt;cookie page=%26quot;1%26quot;%26gt;%26lt;contactid last=%26quot;{UUID}%26quot; first=%26quot;UUID}%26quot;/%26gt;%26lt;/cookie%26gt;' page='2'><entity name='contact'><all-attributes/></entity></fetch>

希望有帮助

关于c# - 使用分页 cookie 的 MS Dynamics REST API FetchXML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39593820/

相关文章:

c# - 当 CRM 中的记录发生更改时更新源中的记录

c# - 使用 LINQ 从 Microsoft CRM 检索数据时出现奇怪的行为

c# - 如何在 Linux 中使用 libusb 获取设备路径

c# - Windows 服务更改批处理文件中回显/流重定向的行为

IE11 Windows 7 上未为 iframe 应用程序设置 Cookie

java - 通过 Volley 设置登录 session Cookie

javascript - iOS 7 中的跨域 cookie

javascript - CRM 2011 表单上同一查找字段的多个查找控件实例

c# - Elasticsearch-计算数组中(不可预测的)字符串的出现

c# - 如何在 Dropdownlist selectedIndexChanged 中获取行索引?