代码段:获取 BCS 缓存订阅 2 的成员

上次修改时间: 2010年5月13日

适用范围: SharePoint Server 2010

本文内容
说明
必备组件
使用该示例

说明

以下示例演示如何获取客户端上 Business Connectivity Services 缓存订阅的成员。

必备组件

  • 服务器上安装了 Microsoft SharePoint Server 2010 或 Microsoft SharePoint Foundation 2010

  • 客户端计算机上安装了 Microsoft Office Professional Plus 2010 和 Microsoft .NET Framework 3.5

  • Microsoft Visual Studio

  • Business Connectivity Services 客户端缓存中至少有一个订阅

使用该示例

  1. 启动客户端计算机上的 Visual Studio,然后新建一个 C# Microsoft Office 应用程序加载项项目。在创建项目时,选择".NET Framework 3.5"。

  2. 从"视图"菜单中,选择"属性页"以显示项目属性。

  3. 在"生成"选项卡中,为"目标平台"选择"任何 CPU"。

  4. 关闭项目属性窗口。

  5. 在"解决方案资源管理器"中的"引用"下,移除除 SystemSystem.Core 之外的所有项目引用。

  6. 将以下引用添加到项目中:

    1. Microsoft.Office.BusinessApplications.Runtime

    2. Microsoft.BusinessData

    3. System.Windows.Forms

  7. 使用以下语句替换现有 using 语句:

    using System;
    using Microsoft.BusinessData.Offlining;
    using Microsoft.Office.BusinessData.Offlining;
    using System.Windows.Forms;
    using System.Collections.Generic;
    using Microsoft.BusinessData.Runtime;
    
  8. 将加载项启动事件中的代码替换为该过程末尾列出的代码。

  9. 将 <entityNamespace>、<entityName>、<viewName> 和 <subscriptionName> 占位符值替换为有效值。

  10. 保存该项目。

  11. 编译并运行该项目。

    这将打开 Office 应用程序并显示根据该代码输出的消息。

RemoteOfflineRuntime remoteOfflineRuntime = new RemoteOfflineRuntime();

// Read the subscription.
ISubscription sub = 
    remoteOfflineRuntime.GetSubscriptionManager().GetSubscription(
    "<entityNamespace>", "<entityName>", "<viewName>", "<subscriptionName>");

//Get subscription members.
using (IEnumerator<IEntityInstance> subMembers = sub.GetMembers())
{
    while (subMembers.MoveNext())
    {
        //Get the Synchronization Status of each member.
        MessageBox.Show((((IOfflineEntityInstance)subMembers.Current).SynchronizationStatus).ToString());
    }
}

请参阅

引用

RemoteOfflineRuntime

GetSubscriptionManager()

ISubscription

GetSubscription(String, String, String, String)

GetMembers()