缓存订阅文件是一个 XML 文件 (*Subscription.xml),它定义 BDC 模型中要缓存的外部内容类型、模型中用于填充缓存中的数据的查询以及刷新缓存中外部项的频率。
上次修改时间: 2011年8月22日
适用范围: SharePoint Server 2010
缓存订阅文件是在部署简单解决方案的过程中由 Microsoft Business Connectivity Services (BCS) 自动生成的。但对于中间 Outlook 声明性解决方案,必须创建 Subscription.xml 文件。该文件遵循一个非常简单的架构且易于创建,而 SDK 提供了要使用的模板和工具,从而使创建该文件变得更加容易。
在此方案中,有两个外部内容类型(即 Customer 和 Order),这将需要您创建两个订阅文件,即 CustomerSubscription.xml 和 OrderHeaderSubscription.xml。可使用 SDK 中提供的模板或 BCS 项目生成器工具创建这两个文件。
备注
由于 AdventureWorks 示例数据库包含 2,000 多个客户,而此示例 Web 服务只返回前 1,000 个客户行,以使传入客户端的数据量不大以便于管理。因此,在此方案中,只返回与这 1,000 个客户相关的订单,而不返回整个订单列表。定义此示例中的订阅关联,以在缓存中填入与 1,000 个客户相关的订单。还可以考虑使用 BulkAssociationNavigator 方法实例来提高性能。
先决条件
步骤 1:创建 BDC 模型 (Metadata.bdcm)
创建缓存订阅
可通过使用 BCS 项目生成器工具创建缓存订阅,也可以使用 SharePoint 2010 SDK 中提供的模板:BasicSubscription_Subscription.xml 手动创建缓存订阅。
使用 BCS 项目生成器工具创建订阅文件
若要基于 BDC 模型创建这两个必需的订阅文件(即 CustomerSubscription.xml 和 OrderHeaderSubscription.xml),请下载并运行 BCS 项目生成器工具。有关详细信息,请参阅 BCS 项目生成器工具(该链接可能指向英文页面)。
使用基本订阅模板创建订阅文件
找到 SharePoint 2010 SDK 中提供的模板:SubscriptionWithAssociation_Subscription.xml,复制它,然后在 Solution Artifacts 文件夹中将其另存为 CustomerSubscription.xml。
打开 CustomerSubscription.xml 以在 XML 编辑器中进行编辑。如果在 Microsoft Visual Studio 中打开 XML 文件,则附加 Subscription 架构 (Subscription.xsd)。这将为您提供 IntelliSense 功能并可帮助阻止您创建无效的项。
将 XML 中标记有 EnterX 的值替换为有效值。下面的 XML 示例演示该文件在经编辑后可能的显示形式。
备注
这是一个非常简单的订阅。可以通过将多个元素和属性添加到文件中,来创建多个复杂的订阅文件。有关详细信息,请参阅 Subscription 架构文档。
<?xml version="1.0" encoding="utf-8" ?> <Subscription LobSystemInstanceName="http://contoso/webservice.asmx?wsdl" EntityNamespace="AdventureWorks" EntityName="Customer" Name="CustomerSubscription" View="GetCustomerById" IsCached="true" RefreshIntervalInMinutes="360" xmlns="https://schemas.microsoft.com/office/2006/03/BusinessDataCatalog"> <Queries> <Query Name="CustomerQuery" MethodInstanceName="GetCustomers" DefaultDisplayName="Customer Read List" RefreshIntervalInMinutes="180" IsCached="true" Enabled="true" /> </Queries> <Associations> <Association Name="GetOrdersForCustomer" MethodInstanceName="GetOrdersForCustomer" TargetSubscriptionName="OrderHeaderSubscription" TargetView="GetSalesOrderHeaderById" LobSystemInstanceName="http://contoso/webservice.asmx?wsdl" RefreshIntervalInMinutes="60" /> </Associations> </Subscription>保存并关闭文件。
创建告知 Business Connectivity Services 要执行的查询的目标订阅,以填充每个客户的相关订单。为此,复制模板:BasicSubscription_Subscription.xml,然后在 Solution Artifacts 文件夹中将其另存为 OrderHeaderSubscription.xml。
打开 OrderHeaderSubscription.xml 文件以对其进行编辑。如果在 Visual Studio 中打开此文件,则附加 Subscription 架构 (Subscription.xsd)。
将 XML 中标记有 EnterX 的值替换为有效值。此处指定的订阅名称必须与为 CustomerSubscription.xml 中的 TargetSubscriptionName 属性指定的名称匹配。下面的 XML 示例演示此文件经编辑后的显示形式。
<?xml version="1.0" encoding="utf-8" ?> <Subscription LobSystemInstanceName="http://contoso/webservice.asmx?wsdl" EntityNamespace="AdventureWorks" EntityName="Customer" Name="CustomerSubscription" View="GetCustomerById" IsCached="true" RefreshIntervalInMinutes="360" xmlns="https://schemas.microsoft.com/office/2006/03/BusinessDataCatalog"> <Queries> <Query Name="CustomerQuery" MethodInstanceName="GetCustomers" DefaultDisplayName="Customer Read List" RefreshIntervalInMinutes="180" IsCached="true" Enabled="true" /> </Queries> <Associations> <Association Name="GetOrdersForCustomer" MethodInstanceName="GetOrdersForCustomer" TargetSubscriptionName="OrderHeaderSubscription" TargetView="GetSalesOrderHeaderById" LobSystemInstanceName="http://contoso/webservice.asmx?wsdl" RefreshIntervalInMinutes="60" /> </Associations> </Subscription>保存并关闭文件。
您已成功为中间声明性 Outlook 解决方案创建所需的缓存订阅。