WCF IncludeExceptionDetailInFaults以编程方式?

Sno*_*owy 20 wcf binding fault

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

谢谢.

<behaviors>
    <serviceBehaviors>
        <behavior name="ServiceGatewayBehavior">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
    </serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

And*_*erd 36

如果要在所有情况下执行此操作,请使用ServiceBehaviorAttribute:

   [ServiceBehavior(IncludeExceptionDetailInFaults=true)]
   class MyServiceImplementation : IMyService
   {
      /// ...
   }
Run Code Online (Sandbox Code Playgroud)

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

////////////////////////////////////
// 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();
Run Code Online (Sandbox Code Playgroud)