6

我在 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;
        }
    }
}
4

1 回答 1

19

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

[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;
    }
}
于 2012-08-27T21:41:33.013 回答