Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Connections exceeding max connections when using Asynchronous pattern

Tags:

c#

wcf

I have a simple WCF service that i'm communicating with Asynchronously.

The thing i don't like is when calling the EndServiceMethod(IASyncResult)

if i forget to call the Close() method, the service will actually leave the connection open and then all remaining connections will fail after the wcf reaches it's max concurrent connections count with timeout exceptions.

I've tried using the [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)] attribute to the Service contract, which doesn't appear to have any effect on the state of the connection from the service.

Perhaps I've implemented it incorrectly?

Any ideas or suggestions.

I'm trying to locate a behavior pattern for the WCF that allows the clients to make a request, and then the server to respond to the request and then assume that the connection is finished and can be terminated.

like image 780
Beta033 Avatar asked Oct 01 '10 19:10

Beta033


2 Answers

This is actually a tricky problem.

On the one hand if you do not close the connection it will remain open until it times out (1 min), under load you will hit the max connections (default 10).

On the other hand you are calling the services asynchronously, so if you close the connect before the callback is received, the callback will be lost.

There are a few things that you could try:

  • increase the max connections
  • close the connection in the callback handler
  • reduce the length of the timeout
like image 81
Shiraz Bhaiji Avatar answered Oct 29 '22 22:10

Shiraz Bhaiji


Specifies the throttling mechanism of a Windows Communication Foundation (WCF) service.

http://msdn.microsoft.com/en-us/library/ms731379%28v=VS.90%29.aspx

like image 39
pedrocgsousa Avatar answered Oct 29 '22 23:10

pedrocgsousa