声明、Azure 和 SharePoint 集成工具包(第 3 部分)

声明、Azure 和 SharePoint 集成工具包(第 3 部分)

这是 CASI(声明、Azure 和 SharePoint 集成)工具包系列文章的第 3 部分,本系列共 5 部分。 第 1 部分概括性介绍整个框架和解决方案并说明本系列文章要尝试解决的问题及涵盖的内容。 第 2 部分提供有关创建 WCF 应用程序并使其能够识别声明,然后将其移到 Windows Azure 的指南。 在本博客中,我将讨论此框架的重大交付成果之一:一个自定义控件基类,用于从 SharePoint 连接到 Windows Azure 中承载的 WCF 应用程序。 我们将涉及以下主题:

· 基类 – 什么是基类以及如何在项目中使用基类

· 布局页 – 如何向 _layouts 目录的页面中添加新控件

· 重要属性 – 讨论要了解的基类中的一些重要属性

CASI 工具包基类

CASI 工具包的主要交付成果之一是自定义控件的基类,用于连接到 WCF 应用程序和使用当前用户的登录令牌提交请求。 基类本身是标准 ASP.NET 服务器控件,这种开发模式的实现要求您构建继承自该基类的新 ASP.NET 服务器控件。 您的控件实际上需要执行以下两项操作,这样做的原因不在本博客的讨论范围之内:

1. 创建对 Windows Azure 中承载的 WCF 应用程序的服务引用。

2. 重写基类的 ExecuteRequest 方法。 这实际上相当简单,因为您只需编写大约 5 行代码,以便创建和配置用于连接到 WCF 应用程序的代理,然后调用基类的 ExecuteRequest 方法。

为此,首先可以在 Visual Studio 中创建一个新项目,并选择 Windows 类库类型的项目。 将命名空间和类名称更改为所需内容后,添加对 CASI 工具包基类(位于 AzureConnect.dll 程序集中)的引用。 您还需要添加对以下程序集的引用: Microsoft.SharePoint、System.ServiceModel、System.Runtime.Serialization 和 System.Web。

在您的基类中,为 Microsoft.SharePoint 添加 using 语句,然后更改您的类,以便它继承自 AzureConnect.WcfConfig。 WcfConfig 是包含用于连接到 WCF 应用程序的所有代码和逻辑的基类,请包含所有属性以增加实现的灵活性并且不再需要对 web.config 进行任何典型更改(连接到 WCF 服务终结点通常需要这么做)。 了解这一点很重要 – 在使用 web.config 文件的每个 Web 应用程序的每台服务器上的每个 web.config 文件中,您通常需要为要连接的每个 WCF 应用程序添加大约 100 行 web.config 更改。 WcfConfig 基类将所有这些更改都包装在控件本身中,以便您只需从控件继承,控件会为您执行其余操作。 还可以在 WcfConfig 控件中更改将在 web.config 文件中更改的所有这些属性,因为该控件会公开所有属性。 我将在介绍重要属性的部分进一步讨论这一点。

现在,应该添加对 Windows Azure 中承载的 WCF 应用程序的新服务引用。 在这里不需要执行特定于 CASI 工具包的任何操作 – 只需在项目中右键单击“引用”并选择“添加服务引用”即可。 插入 Azure WCF 应用程序的 Url 并在末尾附加“WSDL”,以便它检索服务实现的 WSDL。 然后将名称更改为所需内容,添加引用,这一部分就完成了。

此时,您具有一个空类和对 WCF 应用程序的服务引用。 现在到了编写代码的部分,幸好要编写的代码很少。 您需要重写 ExecuteRequest 方法,创建并配置服务类代理,然后调用基类的 ExecuteRequest 方法。 为了简化这一过程,下面提供了我在本博客中附加的示例控件的完整代码;对于需要根据您的服务引用进行更改的部分,我已 使用黄色 突出显示:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Diagnostics;

using Microsoft.SharePoint;

//requires References to:

//1. AzureConnect

//2. Microsoft.SharePoint

//3. System.ServiceModel

//4. System.Runtime.Serialization

//5. System.Web

namespace AzureWcfPage

{

    public class WcfDataControl : AzureConnect.WcfConfig

    {

        //this method must be overridden so the proxy can be

 //configured and created correctly

        public override bool ExecuteRequest()

        {

            try

            {

                //create the proxy instance with bindings and endpoint the base class

                //configuration control has created for this

                CustomersWCF.CustomersClient cust =

                    new CustomersWCF.CustomersClient(this.FedBinding,

                     this.WcfEndpointAddress);

                //configure the channel so we can call it with

              //FederatedClientCredentials.

                SPChannelFactoryOperations.ConfigureCredentials<CustomersWCF.ICustomers>

                     (cust.ChannelFactory,

                     Microsoft.SharePoint.SPServiceAuthenticationMode.Claims);

                //create a channel to the WCF endpoint using the

  //token and claims of the current user

                CustomersWCF.ICustomers claimsWCF =

                    SPChannelFactoryOperations.CreateChannelActingAsLoggedOnUser

                    <CustomersWCF.ICustomers>(cust.ChannelFactory,

                     this.WcfEndpointAddress,

                    new Uri(this.WcfEndpointAddress.Uri.AbsoluteUri));

          //set the client property for the base class

                this.WcfClientProxy = claimsWCF;

            }

            catch (Exception ex)

            {

                Debug.WriteLine(ex.Message);

            }

               

            //now that the configuration is complete, call the method

            return base.ExecuteRequest();

        }

    }

}

因此,您具有了重写 – 从根本上讲是 5 行代码,您实际上只需将此处所示的 ExcecuteRequest 重写中的代码直接复制并粘贴到自己的重写中。复制后,您只需将使用黄色突出显示的部分替换为您的 WCF 应用程序公开的相应类和接口即可。 在上面突出显示的代码中:

· CustomersWCF.CustomersClient: “CustomersWCF”是我创建服务引用时使用的名称,CustomersClient 是我通过 WCF 应用程序公开的类的名称。 我的 WCF 中的类名称实际上只有“Customers”;VS.NET 添加服务引用工具在末尾添加了“Client”部分。

· CustomersWCF.ICustomers: “CustomersWCF”与上文所述相同。 “ICustomers”是我在 WCF 应用程序中创建的接口,我的 WCF“Customers”类实际上实现该接口。

就是这些 – 这就是连接到 Windows Azure 中承载的 WCF 应用程序时需要编写的所有代码。 希望在您看来这相当简单。 介绍一些背景知识,通过您编写的代码,可以将对 WCF 应用程序的调用和 SharePoint 用户的令牌一起传递。 在我撰写的其他博客中对此进行了更详细的说明,博客网址为: https://blogs.technet.com/b/speschka/archive/2010/09/08/calling-a-claims-aware-wcf-service-from-a-sharepoint-2010-claims-site.aspx

现在代码已经完成,您需要确保在将使用新自定义控件的每台服务器上的全局程序集缓存中注册基类和新自定义控件。 很明显,可以使用 SharePoint 解决方案轻松完成此操作。 完成并注册控件后,我们来看一下如何使用它检索和呈现数据。 在 CASI 工具包中,我尝试处理使用 Azure 数据的三种主要情况:

1. 使用 Web 部件在 SharePoint 页面中呈现内容

2. 检索配置数据,以供一个或多个控件使用并将其存储在 ASP.NET 缓存中

3. 检索数据并在任务类型可执行文件(如 SharePoint 计时器作业)中使用该数据

第一种情况可能最普遍,所以我们首先处理这种情况。 采用这种方法后最简单的做法是只创建在发生 Load 事件期间进行所有这些调用的自定义 Web 部件或类似内容,检索数据并在页面中呈现数据。 然而,我认为这是一个很大的错误。 在 Web 部件本身中包装该代码,以便它在处理页面请求期间在服务器端执行,这种做法会严重降低服务器场的整体吞吐量。 在页面上包含一个或多个跨应用程序和数据中心进行一个或多个潜在调用以检索数据的 Web 部件,我对这种做法非常担心,这样做很容易会导致这种情况:严格意义上讲,广泛使用可能会使整个服务器场崩溃。 然而,又存在一些代码必须在服务器上运行这项要求,因为配置到 WCF 应用程序的通道以随请求发送用户令牌时需要这样做。 我的解决方案包含两部分:

1. 在 _layouts 文件夹中承载的自定义页面。 它包含我们刚刚在前面编写的自定义控件,并且实际呈现从 WCF 调用返回的数据。

2. 在服务器端执行代码,而是使用 JavaScript 和 jQuery 调用 _layouts 文件夹中页面的自定义 Web 部件。 它读取从页面返回的数据,然后将数据提供给默认情况下正好在 Web 部件中呈现内容的 JavaScript 函数。 当然,Web 部件中可能包含的内容不止这些,我将在下一篇博客中详细介绍 Web 部件。 总而言之,就是用户请求页面时无需对 WCF 应用程序进行任何其他潜在调用即可处理该页面。 实际上,页面经过处理管道并立即呈现在用户的浏览器中。 完全加载页面后,进行调用以仅检索 WCF 内容。

布局页

实际上很容易编写将承载自定义控件的布局页。 我只用了大概 5 分钟就在记事本中完成了此操作。 希望您可以更快地完成,因为我要在此处复制和粘贴我的布局页,并向您说明需要在您的页面中替换的内容。

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase,Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" MasterPageFile="~/_layouts/simple.master" %>

 

<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>

<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Import Namespace="Microsoft.SharePoint" %>

<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

 

<%@ Assembly Name="AzureConnect, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c0b51bd3d3b33212"%>

<%@ Register Tagprefix="AzWcf" Namespace="AzureWcfPage" Assembly="AzureWcfPage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ed63b2f4046026" %>

 

 

<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">

    <SharePoint:EncodedLiteral ID="wcfConnectPageTitle" runat="server" text="Azure Wcf Connect Page" EncodeMethod='HtmlEncode'/>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">

    <SharePoint:EncodedLiteral ID="wcfConnectPage" runat="server" text="Azure Wcf Connect Page" EncodeMethod='HtmlEncode'/>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderId="PlaceHolderSiteName" runat="server"/>

<asp:Content ID="Content4" ContentPlaceHolderId="PlaceHolderMain" runat="server">

    <AzWcf:WcfDataControl runat="server" id="wcf" WcfUrl="https://azurewcf.vbtoys.com/Customers.svc" OutputType="Page" MethodName="GetAllCustomersHtml" />

</asp:Content>

 

再次说明,页面本身的实现实际上非常容易。 实际必须更改的只是自定义控件的程序集的强名称。 为便于说明,我同样突出显示了控件标记本身中的两个属性。 这些属性特定于我的 WCF 服务,在您的实现中可以更改,在某些情况下可以完全删除它们。 在下文中我将更详细地说明这些属性。 创建布局页后,需要将它分发到 SharePoint 场中每台 Web 前端服务器上的 _layouts 目录中。 分发后,可以从 SharePoint 场中能够识别声明的任何 Web 应用程序的任何网站中调用该布局页。 很明显,在经典身份验证网站(如管理中心)中它不能正常工作。 部署页面后,它可以供 CASI 工具包 Web 部件使用,在本系列文章的第 4 部分将介绍 Web 部件。

重要属性

WcfConfig 包含两大类属性 – 用于配置到 WCF 应用程序的通道和连接的属性,以及用于配置控件本身用法的属性。

WCF 属性

如前所述,WCF 应用程序的所有配置信息(通常包含在 web.config 文件中)已封装在 WcfConfig 控件中。 然而,实际上所有这些属性都已公开,以便可以根据实现的需要对其进行更改。 两个重要的例外是消息安全版本(始终为 MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10)和传输(始终为 HTTPS,而非 HTTP)。 另外,在您的实现中该控件具有一些属性,对这些属性多一些了解可能非常有用(尽管通常情况下不需要更改它们)。

首先,有 5 个只读属性,它们用于公开在配置中使用的顶级配置对象。 只读是指对象本身是只读的,但是以编程方式处理控件时您可以设置它们的各个属性。 这 4 个属性是:

SecurityBindingElement SecurityBinding

BinaryMessageEncodingBindingElement BinaryMessage

HttpsTransportBindingElement SecureTransport

WS2007FederationHttpBinding FedBinding

EndpointAddress WcfEndpointAddress

其他属性都可以在添加到布局 aspx 页面的控件标记中进行配置。 对于这些属性,我使用了命名约定,希望它可以清楚地说明复合属性值的含义。 例如,SecurityBinding 属性具有名为 LocalClient 的属性,后者具有名为 CacheCookies 的布尔属性。 为了尽可能地易于理解和使用,我设置了一个名为 SecurityBindingLocalClientCacheCookies 的属性。 您将看到一些类似属性,这也是查看 .NET Framework SDK 并且想知道如何在基类实现中修改其中一些属性值时如何查找正确属性的线索。 以下是属性的完整列表:

SecurityAlgorithmSuite SecurityBindingDefaultAlgorithmSuite

SecurityHeaderLayout SecurityBindingSecurityHeaderLayout

SecurityKeyEntropyMode SecurityBindingKeyEntropyMode

bool SecurityBindingIncludeTimestamp

bool SecurityBindingLocalClientCacheCookies

bool SecurityBindingLocalClientDetectReplays

int SecurityBindingLocalClientReplayCacheSize

int SecurityBindingLocalClientMaxClockSkew

int SecurityBindingLocalClientMaxCookieCachingTime

int SecurityBindingLocalClientReplayWindow

int SecurityBindingLocalClientSessionKeyRenewalInterval

int SecurityBindingLocalClientSessionKeyRolloverInterval

bool SecurityBindingLocalClientReconnectTransportOnFailure

int SecurityBindingLocalClientTimestampValidityDuration

int SecurityBindingLocalClientCookieRenewalThresholdPercentage

bool SecurityBindingLocalServiceDetectReplays

int SecurityBindingLocalServiceIssuedCookieLifetime

int SecurityBindingLocalServiceMaxStatefulNegotiations

int SecurityBindingLocalServiceReplayCacheSize

int SecurityBindingLocalServiceMaxClockSkew

int SecurityBindingLocalServiceNegotiationTimeout

int SecurityBindingLocalServiceReplayWindow

int SecurityBindingLocalServiceInactivityTimeout

int SecurityBindingLocalServiceSessionKeyRenewalInterval

int SecurityBindingLocalServiceSessionKeyRolloverInterval

bool SecurityBindingLocalServiceReconnectTransportOnFailure

int SecurityBindingLocalServiceMaxPendingSessions

int SecurityBindingLocalServiceMaxCachedCookies

int SecurityBindingLocalServiceTimestampValidityDuration

int BinaryMessageMaxReadPoolSize

int BinaryMessageMaxWritePoolSize

int BinaryMessageMaxSessionSize

int BinaryMessageReaderQuotasMaxDepth

int BinaryMessageReaderQuotasMaxStringContentLength

int BinaryMessageReaderQuotasMaxArrayLength

int BinaryMessageReaderQuotasMaxBytesPerRead

int BinaryMessageReaderQuotasMaxNameTableCharCount

System.Net.AuthenticationSchemes SecureTransportAuthenticationScheme

System.ServiceModel.HostNameComparisonMode SecureTransportHostNameComparisonMode

System.Net.AuthenticationSchemes SecureTransportProxyAuthenticationScheme

System.ServiceModel.TransferMode SecureTransportTransferMode

bool SecureTransportManualAddressing

long SecureTransportMaxBufferPoolSize

long SecureTransportMaxReceivedMessageSize

bool SecureTransportAllowCookies

bool SecureTransportBypassProxyOnLocal

bool SecureTransportKeepAliveEnabled

int SecureTransportMaxBufferSize

string SecureTransportRealm

bool SecureTransportUnsafeConnectionNtlmAuthentication

bool SecureTransportUseDefaultWebProxy

bool SecureTransportRequireClientCertificate

HostNameComparisonMode FedBindingHostNameComparisonMode

WSMessageEncoding FedBindingMessageEncoding

Encoding FedBindingTextEncoding

SecurityAlgorithmSuite FedBindingSecurityMessageAlgorithmSuite

SecurityKeyType FedBindingSecurityMessageIssuedKeyType

bool FedBindingSecurityMessageNegotiateServiceCredential

int FedBindingCloseTimeout

int FedBindingOpenTimeout

int FedBindingReceiveTimeout

int FedBindingSendTimeout

bool FedBindingBypassProxyOnLocal

bool FedBindingTransactionFlow

long FedBindingMaxBufferPoolSize

long FedBindingMaxReceivedMessageSize

bool FedBindingUseDefaultWebProxy

int FedBindingReaderQuotasMaxDepth

int FedBindingReaderQuotasMaxStringContentLength

int FedBindingReaderQuotasMaxArrayLength

int FedBindingReaderQuotasMaxBytesPerRead

int FedBindingReaderQuotasMaxNameTableCharCount

bool FedBindingReliableSessionOrdered

int FedBindingReliableSessionInactivityTimeout

bool FedBindingReliableSessionEnabled

再次说明,创建这些属性是为了可以在布局 aspx 页面的控件标记中直接修改它们。 例如,下面的内容说明了如何设置 FedBindingUseDefaultWebProxy 属性:

<AzWcf:WcfDataControl runat="server" id="wcf" WcfUrl="https://azurewcf.vbtoys.com/Customers.svc" OutputType="Page" MethodName="GetAllCustomersHtml" FedBindingUseDefaultWebProxy="true" />

 

用法属性

控件的其他属性设计用于控制该控件的使用方式。 尽管属性列表有点长,但请注意,它们主要用于灵活地使用控件 – 在简单情况下,您只需设置一个或两个属性,或者只需要在 Web 部件(将在本系列文章的第 4 部分中介绍)中设置它们。 下面列出了每个属性及其简短说明。

string WcfUrl – 这是 WCF 服务终结点的 Url,例如 https://azurewcf.vbtoys.com/Customers.svc。

string MethodName – 这是请求页面时应该调用的方法的名称。 您可以将此属性设置为默认情况下调用的方法。 此外,还可以将 AllowQueryStringOverride 属性设置为 false,这样会限制页面仅使用您在控件标记中定义的 MethodName。 可使用 CASI Kit Web 部件通过查询字符串设置此属性。

string MethodParams – 这是应该传递给方法调用的参数值的分号分隔列表。 它们的顺序应该与方法签名中的显示顺序相同。 如在本博客系列文章的第 2 部分中所述,参数值实际上仅支持简单数据类型,如字符串、布尔值、整数以及日期时间。 如果要将更复杂的对象作为方法参数传递,则需要将参数设置为字符串、调用方法之前将对象反序列化为 Xml,然后在 WCF 应用程序中可以将字符串重新序列化为对象实例。 如果将复杂对象作为查询字符串参数传递,将受浏览器和 IIS 支持的最大查询字符串长度的限制。 可使用 CASI Kit Web 部件通过查询字符串设置此属性。

object WcfClientProxy – WcfClientProxy 是用于实际调用 WCF 应用程序的对象。 需要将此参数配置为支持随调用传递用户令牌,这就是在自定义控件的 ExecuteRequest 重写中编写的配置代码的最后部分将此代理对象设置为您所创建和配置为使用当前客户端凭据的服务应用程序代理的原因。

string QueryResultsString – 此属性包含方法调用所返回结果的字符串表示形式。 如果您的 WCF 方法返回简单数据类型,如布尔值、整数、字符串或日期时间,则此属性的值将为返回值 ToString()。 如果您的 WCF 方法返回同样受支持的自定义类,则基类获取返回值时会将它反序列化为字符串,以便您具有数据的 Xml 表示形式。

object QueryResultsObject – 此属性包含方法调用所返回结果的对象表示形式。 以编程方式使用控件时它非常有用。 例如,如果使用控件检索要存储在 ASP.NET 缓存中或者要在 SharePoint 计时器作业中使用的数据,则 QueryResultsObject 属性准确包含 WCF 方法调用返回的结果。 如果它是自定义类,则只需将此属性的结果转换为适当的类类型即可使用。

DataOutputType OutputType – OutputType 属性是一个枚举,它可以是以下四个值之一: Page、ServerCache、Both 或 None。 如果要在布局页中使用控件并且要使用 Web 部件呈现结果,则 OutputType 应该为 Page 或 Both。 如果要检索数据并将数据存储在 ASP.NET 缓存中,则应该使用 ServerCache 或 Both。 注意: 如果将结果存储在缓存中,则存储 QueryResultsObject。 很明显,Both 既呈现数据又将数据存储在 ASP.NET 缓存中。 如果在诸如 SharePoint 计时器作业之类的可执行文件中仅以编程方式使用控件,则可以将此属性设置 None,因为调用 ExecuteRequest 方法后仅读取 QueryResultsString 或 QueryResultsObject。 可使用 CASI Kit Web 部件通过查询字符串设置此属性。

string ServerCacheName – 如果选择将 OutputType 设置为 ServerCache 或 Both,则需要将 ServerCacheName 属性设置为非空字符串值,否则会引发异常。 这是将用于在 ASP.NET 缓存中存储结果的项。 例如,如果将 ServerCacheName 属性设置为“MyFooProperty”,则调用 ExecuteRequest 方法后可以通过引用 HttpContext.Current.Cache["MyFooProperty"] 来检索从 WCF 应用程序返回的对象。 可使用 CASI Kit Web 部件通过查询字符串设置此属性。

int ServerCacheTime – 这是应该保留添加到 ASP.NET 缓存中的项目的时间(以分钟为单位)。 如果将 OutputType 属性设置为 ServerCache 或 Both,则还必须将此属性设置为非零值,否则将引发异常。 可使用 CASI Kit Web 部件通过查询字符串设置此属性。

bool DecodeResults – 此属性适用于 WCF 应用程序返回 HtmlEncoded 结果的情况。 如果将此属性设置为 true,则 HtmlDecoding 将应用于结果。 大多数情况下,这都不是必需的。 可使用 CASI Kit Web 部件通过查询字符串设置此属性。

string SharePointClaimsSiteUrl – 此属性主要用于在 Http 请求之外(如在 SharePoint 计时器作业中)以编程方式创建控件的情况。 默认情况下,通过 Web 部件提出请求时,基类将使用当前网站的 Url 连接到 SharePoint STS 终结点以将用户令牌提供给 WCF 调用。 然而,如果以编程方式创建了控件,并且没有 Http 上下文,则可以将此属性设置为使用声明保护的 SharePoint 网站的 Url,并且该网站将用于访问 SharePoint STS。 因此,不需要在布局页的控件标记中设置此属性,因为调用该页面时始终具有 Http 上下文。

bool AllowQueryStringOverride – 此属性允许管理员有效地锁定布局页中的控件标记。 如果 AllowQueryStringOverride 设置为 false,将忽略从 CASI 工具包 Web 部件中传递的任何查询字符串重写值。

string AccessDeniedMessage – 这是“拒绝访问”错误消息,拒绝用户访问特定方法时会在 CASI 工具包 Web 部件中显示该消息。 例如,正如此系列文章的第 2 部分中所述,由于我们要随 WCF 调用传递用户令牌,因此我们可以使用 PrincipalPermission 要求修饰任何方法,如“此用户必须属于‘销售经理’组”。 如果用户不满足 PrincipalPermission 要求,则 WCF 调用将失败并出现拒绝访问错误。 在这种情况下,Web 部件将显示 AccessDeniedMessage 的内容。 请注意,您可以在此消息中使用多种格式,例如使用 HTML 标记将字体设置为加粗或红色(即 <font color='red'>您没有访问权限;请与管理员联系</font>)。 可使用 CASI Kit Web 部件通过查询字符串设置此属性。

string TimeoutMessage – 这是尝试执行 WCF 方法调用时出现超时错误的情况下将显示在 CASI 工具包 Web 部件中的消息。 它还支持多种格式,例如,将字体设置为加粗、红色等格式。 可使用 CASI Kit Web 部件通过查询字符串设置此属性。

这是一篇很长的博客,它可能是本系列文章中最长的一篇,因为它介绍了最重要的 CASI 工具包整合能力。 在下一篇博客中,我将介绍随 CASI 工具包提供的 Web 部件,此 Web 部件使用在本步骤中开发的自定义控件和布局页呈现来自 WCF 应用程序的数据。

此外,本博客中附加了一个 zip 文件,该文件包含我所创建的、包含 CASI 工具包基类程序集的 Visual Studio 2010 项目示例,继承自 CASI 工具包基类的自定义控件,以及我的自定义布局页。

这是一篇本地化的博客文章。请访问 The Claims, Azure and SharePoint Integration Toolkit Part 3 以查看原文。