我有一个WCF/REST Web服务,我正在尝试添加一个全局异常处理程序.我正在寻找类似于标准.NET网站中的Application_Error事件的东西.
我发现了很多关于使用IErrorHandler和IServiceBehavior的信息,如下所示:http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.ierrorhandler.aspx#Y1479
这似乎是我需要的,但我发现的每个例子都假定该服务是在web.config中定义的.我不这样做 - 我正在使用在global.asax中配置的RouteTables,如下所示:
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private void RegisterRoutes()
{
// Edit the base address of Service1 by replacing the "Service1" string below
RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHost2Factory(), typeof(myService)));
}
Run Code Online (Sandbox Code Playgroud)
那么,鉴于此,我如何配置我的自定义IErrorHandler和IServiceBehavior?我是否在正确的轨道上,因为我使用的是RouteTable,而不是通过web.config配置它?我对WCF很新....