从Wcf数据服务中抛出异常并从.net客户端捕获异常的最佳做法是什么?
答案 0 :(得分:2)
总的来说,我不确定是否有很多最佳实践,但这里有一些可能会有所帮助的想法。
ServiceBehavior
属性添加到您的服务并将UseVerboseErrors
设置为true:
using System.Data.Services;
using System.Data.Services.Common;
using System.ServiceModel;
namespace Scratch.Web
{
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class ScratchService : DataService<ScratchEntityFrameworkContext>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
config.UseVerboseErrors = true;
}
}
}