I've been trying to use ELMAH with WCF and I have added the "normal" ErrorHandler
and ServiceErrorBehavior
to a service. These work, I can see that when there is an exception the code in these runs and logs an error to ELMAH. So it should be fine but when I try to access the error log page elmah.axd
I get HTTP 404 and WCF gives me the "Endpoint not found page".
Which means that the Elmah.ErrorLogPageFactory
was not used on that url. So what it comes down to is my web.config
(I think). I just can't get this right, here are the relevant parts of my web.config
:
My service endpoints are setup like so:
<system.serviceModel>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true"
automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="SaraService.SaraService"
behaviorConfiguration="SaraSvcBehaviour" >
<endpoint name="SaraService"
address=""
binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP"
behaviorConfiguration="RestEndPointBehaviour"
contract="SaraService.ISaraService" />
<endpoint
address="soap"
behaviorConfiguration="SoapEndPoinstBehaviour"
binding="basicHttpBinding"
contract="SaraService.ISaraService" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SaraSvcBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RestEndPointBehaviour">
<webHttp />
</behavior>
<behavior name="SoapEndPoinstBehaviour">
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP"
crossDomainScriptAccessEnabled="true">
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
So there are endpoints in / and /soap urls.
And my ELMAH config is like this:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
</system.web>
</location>
<system.webServer>
<handlers>
<add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
</system.webServer>
And I'm also running AutofacServiceHostFactory
in the root url. Here is my global.asax.cs for the relevant parts:
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
var builder = new ContainerBuilder();
builder.RegisterType<SaraService>();
builder.RegisterType<MarkkinadataAccess.MarkkinadataEntities>().InstancePerLifetimeScope();
builder.RegisterType<GenerisDbConnectionSettings>().As<IGenerisDbConnectionSetting>().SingleInstance();
builder.RegisterType<GenerisApplication>().As<IGenerisApplication>().PropertiesAutowired().InstancePerLifetimeScope();
builder.RegisterType<CrmProductsQuery>().As<ICrmProductsQuery>();
builder.RegisterType <ProductsByNameQuery>().As<IProductsByNameQuery>();
builder.RegisterType<ProductMWQueryByName>().As<IProductMWQueryByName>();
builder.RegisterType<ProductMWQueryById>().As<IProductMWQueryById>();
AutofacHostFactory.Container = builder.Build();
RouteTable.Routes.Add(new ServiceRoute("", new AutofacServiceHostFactory(), typeof(SaraService)));
}
}
So my guess is that either running the service endpoint in root or the AutofacServiceHostFactory
somehow prevents me accessing ELMAH log page in /elmah.axd url.
But I just don't understand why or how.
In any case, any help would be much appreciated.