【发布时间】:2014-07-23 17:33:48
【问题描述】:
我一直在尝试将 ELMAH 与 WCF 一起使用,并且已将“正常”ErrorHandler 和 ServiceErrorBehavior 添加到服务中。这些工作,我可以看到,当出现异常时,这些代码运行并向 ELMAH 记录错误。所以应该没问题,但是当我尝试访问错误日志页面 elmah.axd 时,我得到 HTTP 404,WCF 给了我“找不到端点页面”。
这意味着Elmah.ErrorLogPageFactory 未在该网址上使用。所以归结为我的web.config(我认为)。我就是搞不懂,这里是我的web.config 的相关部分:
我的服务端点设置如下:
<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>
所以 / 和 /soap url 中有端点。
我的 ELMAH 配置是这样的:
<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>
我还在根 url 中运行 AutofacServiceHostFactory。这是我的 global.asax.cs 的相关部分:
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)));
}
}
所以我的猜测是,在 root 中运行服务端点或 AutofacServiceHostFactory 会以某种方式阻止我访问 /elmah.axd url 中的 ELMAH 日志页面。
但我只是不明白为什么或如何。
无论如何,我们将不胜感激。
【问题讨论】:
标签: asp.net web-services wcf elmah