首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >WCF IncludeExceptionDetailInFaults编程吗?

WCF IncludeExceptionDetailInFaults编程吗?
EN

Stack Overflow用户
提问于 2010-12-01 07:22:56
回答 1查看 8K关注 0票数 21

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

谢谢。

代码语言:javascript
复制
<behaviors>
    <serviceBehaviors>
        <behavior name="ServiceGatewayBehavior">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
    </serviceBehaviors>
</behaviors>
EN

回答 1

Stack Overflow用户

发布于 2010-12-01 08:07:47

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

代码语言:javascript
复制
   [ServiceBehavior(IncludeExceptionDetailInFaults=true)]
   class MyServiceImplementation : IMyService
   {
      /// ...
   }

如果您只想在某些情况下执行此操作,请在运行时确定...

代码语言:javascript
复制
////////////////////////////////////
// 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();
票数 38
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4319765

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档