【发布时间】:2020-01-20 04:19:38
【问题描述】:
我正在为 Dynamics CRM (8.2) 构建一个网络资源。 当我尝试像这样使用 fetchXml 获取数据时,一切都很好:
<fetch mapping="logical" count="3" >
<entity name="product" >
<attribute name="name" />
<attribute name="productnumber" />
</entity>
</fetch>
但如果我添加“页面”参数,就像在下一个代码中一样,我会得到 Invalid XML。
<fetch mapping="logical" count="3" page="1" >
<entity name="product" >
<attribute name="name" />
<attribute name="productnumber" />
</entity>
</fetch>
我使用 XrmToolBox 中的 FetchXml 测试器测试了提取。在那里它工作正常。 我做错了什么?
我尝试使用 npm 包 dynamics-web-api (https://www.npmjs.com/package/dynamics-web-api) 和 XMLHttpRequest 执行请求。两者都像上面描述的那样工作。
错误消息是这样的:(抱歉格式化)
{
"error":{
"code":"",
"message":"Invalid XML.",
"innererror":{
"message":"Invalid XML.",
"type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]",
"stacktrace":" at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.RetrieveMultiple(QueryBase query, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode)
at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.RetrieveMultiple(QueryBase query)
at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.ExecuteQueryForEntitySet(CrmODataExecutionContext context, String entitySetName, CustomQueryOptions queryOptions, String fetchXml)
at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entityCollectionName, String castedEntityName, ODataQueryOptions queryOptions)
at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)
at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
**Edit**
My error were somewhere in the formatting of the fetch-string. I used:
const query = encodeURI(connectionString + "?fetchXml=" + encodeURI(xmlString));
the correct code is:
const 查询 = encodeURI(connectionString) + "?fetchXml=" + encodeURI(xmlString);
Ty AnkUser for your example. It helped me much.
【问题讨论】:
标签: xml dynamics-crm crm fetchxml xrm