2010-11-30 12 views
17

Tengo lo siguiente en un archivo de configuración, y estoy tratando de encontrar los bits equivalentes en C#, ya que tengo un servicio que está configurado completamente mediante programación. ¿Qué clase/propiedad/método debería buscar?WCF IncludeExceptionDetailInFaults programmatically?

Gracias.

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

Respuesta

31

Si usted quiere hacer esto en todos los casos, el uso del ServiceBehaviorAttribute:

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

Si desea hacerlo sólo en algunos casos, que se determinará en tiempo de ejecución ....

//////////////////////////////////// 
// 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();