tags:

views:

75

answers:

1

I tried timeouts and throwing exceptions in the service implementation, but it didn't caused the channel to enter a faulty state as it happens in my production code.

How could I force this event to happen for testing purposes?

The following code throws an exception for the first request, making it fail, but the subsequent requests succeed (unfortunately, since my objective 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;
    }
}
A: 

Raising an uncatched exception in your server will put your Chanel in fault state, unless it's a FaultException ; (thanks to marc_s !)

Brann
actually, no this won't work - using the FaultContracts, or SOAP faults, is specifically designed to **NOT** put your channel in faulted mode!
marc_s
you're right, in fact it's exactly the contrary
Brann
My exception was not working because I was discarding the faulty channel before the new requests.
Jader Dias