How to force a WCF service channel to enter an erroneous state?

I tried timeouts and excluded exceptions from the service implementation, but this did not cause the channel to go into a faulty state, as it happens in my production code.

How can I make this event happen for testing purposes?

The following code throws an exception for the first request, which makes it unsuccessful, but subsequent requests succeed (unfortunately, since my goal is to make them fail)

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

    SampleData ISampleService.SampleMethod(SampleData data)
    {
        if (first)
        {
            first = false;
            throw new Exception();
        }
        return data;
    }
}
+3
source share
1 answer

Raising an uncovered exception on your server will result in the loss of your Chanel in a failed state, unless that exception is a FaultException; (thanks marc_s!)

0
source

Source: https://habr.com/ru/post/1727238/


All Articles