WCF Data Service - Request error
Asked Answered
D

1

6

I am doing a simple WCF Data service on top of LINQ to SQL data context. My svc.cs file is very simple. However, when I run it from VS2012, I get a generic "Request Error" with no more information. How can I troubleshoot/resolve it?

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;
        }
    }
}
Destinee answered 27/8, 2012 at 20:17 Comment(0)
C
19

If you set the [ServiceBehavior(IncludeExceptionDetailInFaults=true)] attribute on the service and set config.UseVerboseErrors to true, you will get a much clearer error message on the client side. Please be sure to remove these settings before you go to production as they could result in unintentional information disclosure:

[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;
    }
}
Chemarin answered 27/8, 2012 at 21:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.