2010-11-30 26 views
17

J'ai ce qui suit dans un fichier de configuration, et j'essaie de trouver les bits équivalents en C#, car j'ai un service qui est entièrement configuré par programme. Quelle classe/propriété/méthode dois-je rechercher?WCF IncludeExceptionDetailInFaults par programme?

Merci.

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

Répondre

31

Si vous voulez faire dans tous les cas, utilisez le ServiceBehaviorAttribute:

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

Si vous voulez le faire que dans certains cas, à déterminer lors de l'exécution ....

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