views:

10

answers:

0

Hello,

I have created a simple wcf service hosted in IIS and wcf client and figured out that when u catch a FaultException from the wcf service and then call client.Abort() to release the session (as the microsoft samples said) it doesn't release the session and hangs up on the 11th call.

Here is example:

Wcf Service:

[ServiceContract]  
public interface IService1
{
    [OperationContract]
    string GetData(int value);
}


public class Service1 : IService1
{
    public string GetData(int value)
    {
        throw new FaultException("Exception is here");

        return string.Format("You entered: {0}", value);
    }
}

Client:

class Program
{
    static void Main(string[] args)
    {
        Service1Client client = null;          

        for(int i = 0; i < 15; i++)
        {
            try
            {
                client = new Service1Client();
                client.GetData(100);                   
            }
            catch (TimeoutException timeoutEx)
            {
                Console.WriteLine(timeoutEx);
                client.Abort();
            }
            catch (FaultException faultEx)
            {
                Console.WriteLine(faultEx);
                client.Abort();
            }
            catch (CommunicationException commEx)
            {
                Console.WriteLine(commEx);
                client.Abort();
            }
      }  
   }              

}

But if you replace the client.Abort() with client.Close() for catch(FaultException ) then everything works like a charm and there is no locking after 11th call of the wcf-service method.

Why could it be? Why Abort() method doesn't clean up the session after FaultException was catched?