I created a simple wcf service hosted in IIS and the wcf client and found out that when you catch a FaultException from the wcf service and then call client.Abort () to free the session (as Microsoft samples said), 'release the session and hang up the handset on the 11th call.
Here is an 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 client.Abort () with client.Close () for catch (FaultException), then everything works like a charm, and after the 11th call to the wcf service method, there is no lock.
Why? Why doesn't the Abort () method clear the session after a FaultException is detected?
c # wcf faultexception
Sergey Smelov
source share