0

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jukka Puranen
  • 8,026
  • 6
  • 27
  • 25

1 Answers1

0

Ok, I got this now (partially at least). The culprit is this line in my global.asax:

RouteTable.Routes.Add(new ServiceRoute("", new AutofacServiceHostFactory(), typeof(SaraService)));

So this will make the service endpoint to root which is what I wanted.

Also I just wanted a route (any route other than root) to access the ELMAH error log page. Which of course means that there has to be a route with a handler that runs the Elmah.ErrorLogPageFactory.

Now this should be simple but when I add my service to root url then it seems that I cannot access any route with a handler (axd) no matter what.

This just seems odd to me because I can create a file for example in www/index.html and that will be served just fine without touching the web.config at all. But in case of a "generated" route like elmah.axd or www/elmah.axd the service that I added in the root url will always get executed. Giving me the "no endpoint" page which is WCF pipelines HTTP 404.

In any case, if I put my service to some url other than root I can access ELMAH error log.

And yes, I did try ignoring elmah.axd url but it just gave me normal 404 error.

So I guess I'll just have to put my service to some place other than root unless somebody can come up with a better answer to do this.

Jukka Puranen
  • 8,026
  • 6
  • 27
  • 25
  • Thanks to your answer I was able to get the Elmah Log Web Front end to load up at all. The solution being to change the WCF service root path to something else other than root ie "". I changed the root for my WCF service to "root/svc/.." and was able to access Elmah web log via "root/elmah" – AlexVPerl Nov 15 '15 at 21:58