Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Data Service - Request error

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;
        }
    }
}
like image 723
laconicdev Avatar asked Aug 27 '12 20:08

laconicdev


1 Answers

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;
    }
}
like image 87
Mark Stafford - MSFT Avatar answered Sep 28 '22 17:09

Mark Stafford - MSFT