【发布时间】:2012-01-16 00:11:27
【问题描述】:
我在 Windows 服务中对 CrmOrganizationServiceContext 上的 RetrieveMultiple 操作使用 FetchExpression 操作,以从队列中获取和处理项目。
第一次运行时,它会获取要正确处理的项目。在使用相同CrmOrganizationServiceContext 实例的后续调用中,它始终检索零个实体而不会引发错误。我添加了新实体并重新激活了应该使用 FetchXml 获取的现有实体,但它们没有被检索到。
一旦我重新启动我的服务,它就会创建一个 CrmOrganizationServiceContext 的新实例并获取新项目。
我在这里做错了什么?
public CrmConnector(string connectionString)
{
Context = new CrmOrganizationServiceContext(CrmConnection.Parse(connectionString));
}
public void FetchStuff()
{
string fetchXml = "...";
FetchExpression fetchExpression = new FetchExpression(fetchXml);
EntityCollection entityCollection = Context.RetrieveMultiple(fetchExpression);
// entityCollection.Entities is always empty following first run
}
private CrmOrganizationServiceContext Context { get; set; }
根据请求获取 Xml,唯一的自定义是限制返回项目数量的计数属性(因为这是一个队列处理器)
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" count="10">
<entity name="xxx1">
<attribute name="xxx_name" />
<attribute name="createdon" />
<attribute name="xxx_1" />
<attribute name="xxx_2" />
<attribute name="xxx_3" />
<attribute name="xxx_4" />
<attribute name="statecode" />
<order attribute="createdon" descending="false" />
<filter type="and">
<condition attribute="xxx_exported" value="0" operator="eq"/>
</filter>
</entity>
</fetch>
【问题讨论】:
-
我做了类似的事情并且遇到了同样的问题,但在我的情况下,我更改了我的服务,以便每次轮询运行时(大约每 10 分钟一次)我重新实例化上下文和相关的类来重新开始,这是一个选择吗?
-
为了完整起见,你能发布你的
FetchXml吗? -
@Chris - 我不想这样做,因为每次创建实例都需要很长时间:(
-
是的,正如我告诉我的同事,
bloody ages是一个技术术语 :) -
@Chris 每次都尝试重新创建实例,但它仍然没有拾取实体,所以发生了其他事情......
标签: c# dynamics-crm dynamics-crm-2011 dynamics-crm-online xrm