【问题标题】:How to cause a WCF service channel to enter a faulty state?如何使WCF服务通道进入故障状态?
【发布时间】:2010-01-04 15:20:44
【问题描述】:

我在服务实现中尝试了超时和抛出异常,但它并没有像我的生产代码中那样导致通道进入错误状态。

出于测试目的,我如何强制此事件发生?

下面的代码对第一个请求抛出异常,使其失败,但随后的请求成功(不幸的是,因为我的目标是让它们失败)

public class SampleService : ISampleService
{
    static bool first = true;

    SampleData ISampleService.SampleMethod(SampleData data)
    {
        if (first)
        {
            first = false;
            throw new Exception();
        }
        return data;
    }
}

【问题讨论】:

    标签: .net wcf


    【解决方案1】:

    在您的服务器中引发未捕获的异常将使您的 Chanel 处于故障状态,除非它是 FaultException ; (感谢 marc_s !)

    【讨论】:

    • 实际上,这行不通 - 使用 FaultContracts 或 SOAP 故障专门设计为将您的频道置于故障模式!
    • 我的异常没有起作用,因为我在新请求之前丢弃了故障通道。
    猜你喜欢
    • 2010-09-23
    • 2011-04-02
    • 1970-01-01
    • 2011-07-05
    • 2012-01-28
    • 2014-06-27
    • 2015-07-06
    • 1970-01-01
    • 2016-08-05
    相关资源
    最近更新 更多