【问题标题】:Add includeExceptionDetailInFaults添加 includeExceptionDetailInFaults
【发布时间】:2015-08-14 08:54:31
【问题描述】:

尝试将 includeExceptionDetailInFaults="true" 添加到我正在调用的 Web 服务的 Web 配置中,但我定义的两种行为都不起作用。

这是我调用网络服务时遇到的错误:

System.ServiceModel.FaultException:服务器无法处理 由于内部错误导致的请求。有关更多信息 错误,要么打开 IncludeExceptionDetailInFaults(要么来自 ServiceBehaviorAttribute 或从配置行为)上 服务器为了将异常信息发送回客户端, 或根据 Microsoft .NET Framework 3.0 SDK 打开跟踪 文档并检查服务器跟踪日志。

<behaviors>
  <serviceBehaviors>
    <behavior name="debug">
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<!--<behaviors>
  <endpointBehaviors>
    <behavior name="debug">
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </endpointBehaviors>
</behaviors>-->

<client>
  <endpoint address="..."
            binding="wsHttpBinding" 
            bindingConfiguration="WSHttpBinding_ICommunicationService"
            behaviorConfiguration="debug"
            contract="CommunicationServiceReference.ICommunicationService" 
            name="WSHttpBinding_ICommunicationService" />
</client>

编辑: 我看了这个类似的问题,但在建议的答案中有

<services>
      <service...

在我的情况下是

<client>
  <endpoint

我也尝试更改为services,但没有成功

【问题讨论】:

    标签: web-services exception web-config


    【解决方案1】:

    我认为您将属性包含在错误的末尾,基本上您是在告诉客户端包含异常信息(这将是一个安全风险)。

    在服务 web.config 中,您将有一个行为部分(这取自我们的代码,该代码运行良好并且已经完成了大约 4 年):

    <system.serviceModel>
        <bindings configSource="bindings.config"></bindings>
        <client configSource="client-local.config"></client>
        <behaviors configSource="behaviors.config"></behaviors>
        <services>
          <service name="xxx.SomeService">
            <endpoint contract="xxx.ISomeService" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding"/>
          </service>
        </system.serviceModel>
    

    Behaviours.config 如下所示:

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    

    此外,通过外部化配置,我们可以在 _MasterConfigs 文件夹中保留一份副本,该文件夹在构建时复制到服务,以确保所有项目的一致性。

    编辑: 抱歉...我刚刚重新阅读了您的问题,您基本上已经了解了我所概述的内容。也许您命名行为的事实导致了问题(而不是逻辑上应该)。除非它是一个公开的 WCF,否则我认为最好还是返回异常信息,即使是在发布时,也可以进行日志记录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      • 2011-05-18
      • 2011-02-03
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多