WCF数据服务 - 请求错误

时间:2012-08-27 20:17:49

标签: wcf-data-services

我在LINQ to SQL数据上下文之上做一个简单的WCF数据服务。 我的svc.cs文件非常简单。但是,当我从VS2012运行它时,我得到一个通用的“请求错误”,没有更多的信息。我该如何解决/解决它?

using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using MyApp.Business.Pmw.DataAccess;

namespace MyApp.DataService
{
    public class SystemData : DataService<PmwModelDataContext>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("SysParam", EntitySetRights.ReadMultiple);            
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
            // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }
    }
}

1 个答案:

答案 0 :(得分:19)

如果您在服务上设置[ServiceBehavior(IncludeExceptionDetailInFaults=true)]属性并将config.UseVerboseErrors设置为true,您将在客户端获得更清晰的错误消息。在开始制作之前,请务必删除这些设置,因为它们可能会导致无意的信息泄露:

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class FileService : DataService<FileContext>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.UseVerboseErrors = true;
        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
    }
}