DataServiceConfiguration 类

管理 WCF 数据服务 的配置。

继承层次结构

System.Object
  System.Data.Services.DataServiceConfiguration

命名空间:  System.Data.Services
程序集:  Microsoft.Data.Services(在 Microsoft.Data.Services.dll 中)

语法

声明
Public NotInheritable Class DataServiceConfiguration _
    Implements IDataServiceConfiguration
用法
Dim instance As DataServiceConfiguration
public sealed class DataServiceConfiguration : IDataServiceConfiguration
public ref class DataServiceConfiguration sealed : IDataServiceConfiguration
[<SealedAttribute>]
type DataServiceConfiguration =  
    class
        interface IDataServiceConfiguration
    end
public final class DataServiceConfiguration implements IDataServiceConfiguration

DataServiceConfiguration 类型公开以下成员。

属性

  名称 说明
公共属性 AnnotationsBuilder 生成将应用到提供程序数据模型的批注模型。
公共属性 DataServiceBehavior 获取定义数据服务的其他行为的 DataServiceBehavior 对象。
公共属性 DisableValidationOnMetadataWrite 获取或设置在将数据模型作为请求的响应写入 $metadata 终结点之前,是否验证数据模型。
公共属性 EnableTypeConversion 获取或设置数据服务运行时是否应将负载中所含类型转换为请求中指定的实际属性类型。
公共属性 MaxBatchCount 获取或设置单个批处理中允许的更改集和查询操作的最大数量。
公共属性 MaxChangesetCount 获取或设置可以包含在单个更改集中的最大更改数。
公共属性 MaxExpandCount 获取或设置可通过使用 $expand 运算符包括到单个请求中的最大相关实体数。
公共属性 MaxExpandDepth 获取或设置可包括到单个请求的 $expand 路径中的最大相关实体数。
公共属性 MaxObjectCountOnInsert 获取或设置单个 POST 请求中能够包含的最大插入对象数。
公共属性 MaxResultsPerCollection 获取或设置每个返回集合中的最大项数。
公共属性 UseVerboseErrors 获取或设置是否应由数据服务返回详细错误。

页首

方法

  名称 说明
公共方法 EnableTypeAccess 向数据服务运行时注册数据类型,使得该数据类型可供自定义数据服务提供程序使用。
公共方法 Equals (从 Object 继承。)
受保护方法 Finalize (从 Object 继承。)
公共方法 GetHashCode (从 Object 继承。)
公共方法 GetType (从 Object 继承。)
受保护方法 MemberwiseClone (从 Object 继承。)
公共方法 RegisterKnownType 向可由数据服务识别的类型列表中添加类型。
公共方法 SetEntitySetAccessRule 为指定的实体集资源设置权限。
公共方法 SetEntitySetPageSize 为实体集资源设置最大页面大小。
公共方法 SetServiceActionAccessRule 为指定的服务动作设置权限。
公共方法 SetServiceOperationAccessRule 为指定的服务操作设置权限。
公共方法 ToString (从 Object 继承。)

页首

示例

此示例显示了基于 Northwind 的数据服务的代码隐藏页面,并将访问权限授予所选实体集。

Imports System.Data.Services
Imports System.Linq
Imports System.ServiceModel.Web

Public Class Northwind
    Inherits DataService(Of NorthwindEntities)

    ' This method is called only once to initialize service-wide policies.
    Public Shared Sub InitializeService(ByVal config As DataServiceConfiguration)
        ' Grant only the rights needed to support the client application.
        config.SetEntitySetAccessRule("Orders", EntitySetRights.AllRead _
             Or EntitySetRights.WriteMerge _
             Or EntitySetRights.WriteReplace)
        config.SetEntitySetAccessRule("Order_Details", EntitySetRights.AllRead _
            Or EntitySetRights.AllWrite)
        config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead)
    End Sub
End Class
using System.Data.Services;
using System.Linq;
using System.ServiceModel.Web;

namespace NorthwindService
{
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class Northwind : DataService<NorthwindEntities>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // Grant only the rights needed to support the client application.
            config.SetEntitySetAccessRule("Orders", EntitySetRights.AllRead
                 | EntitySetRights.WriteMerge
                 | EntitySetRights.WriteReplace);
            config.SetEntitySetAccessRule("Order_Details", EntitySetRights.AllRead
                | EntitySetRights.AllWrite);
            config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead);
            config.DataServiceBehavior.MaxProtocolVersion =
                System.Data.Services.Common.DataServiceProtocolVersion.V3;
        }
    }
}

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。不保证所有实例成员都是线程安全的。

请参阅

参考

System.Data.Services 命名空间

其他资源

配置数据服务(WCF 数据服务)