【问题标题】:WCF IncludeExceptionDetailInFaults programmatically?WCF IncludeExceptionDetailInFaults 以编程方式?
【发布时间】:2011-05-18 05:06:49
【问题描述】:

我在配置文件中有以下内容,我正在尝试在 C# 中找到等效的位,因为我有一个完全以编程方式配置的服务。我应该寻找什么类/属性/方法?

谢谢。

<behaviors>
    <serviceBehaviors>
        <behavior name="ServiceGatewayBehavior">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
    </serviceBehaviors>
</behaviors>

【问题讨论】:

    标签: wcf binding fault


    【解决方案1】:

    如果您想在所有情况下都这样做,请使用ServiceBehaviorAttribute

       [ServiceBehavior(IncludeExceptionDetailInFaults=true)]
       class MyServiceImplementation : IMyService
       {
          /// ...
       }
    

    如果你只想在某些情况下这样做,要在运行时确定....

    ////////////////////////////////////
    // Must include these at the top of file
    using System.ServiceModel;
    using System.ServiceModel.Description;
    // ...
    
    /////////////////////////////////////////////////////////////
    // Inside whichever function initializes the service host
    //
    _serviceHost = new ServiceHost(_service);
    if (IWantToIncludeExceptionDetails())
    {
        var behavior = _serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>();
        behavior.IncludeExceptionDetailInFaults = true;
    }
    _serviceHost.Open();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-07
      • 2010-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-19
      • 1970-01-01
      相关资源
      最近更新 更多