开发者

WCF IncludeExceptionDetailInFaults programmatically?

开发者 https://www.devze.com 2023-01-28 10:41 出处:网络
I have the following in a config file, and I am trying to find the equivalent bits in C#, as I have a service that is configured fully programmatically. What class/property/method should I look for?

I have the following in a config file, and I am trying to find the equivalent bits in C#, as I have a service that is configured fully programmatically. What class/property/method should I look for?

Thanks.

&l开发者_开发百科t;behaviors>
    <serviceBehaviors>
        <behavior name="ServiceGatewayBehavior">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
    </serviceBehaviors>
</behaviors>


If you want to do this in all cases, use the ServiceBehaviorAttribute:

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

If you want to do it only in some cases, to be determined at runtime....

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号