WCF connections exceeding maximum connections using an asynchronous pattern

I have a simple WCF service that I communicate with asynchronously.

I don't like it when you call EndServiceMethod(IASyncResult)

if I forget to call the method Close(), the service will actually leave the connection open, and then all other connections will fail after wcf reaches the maximum number of concurrent connections with timeout exceptions.

I tried using the [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)] attribute of the service contract, which does not seem to affect the state of the connection to the service.

Perhaps I implemented it incorrectly?

Any ideas or suggestions.

I am trying to find a behavior pattern for WCF that allows clients to make a request, and then the server to respond to the request, and then assume that the connection is complete and can be completed.

+5
source share
5 answers

This is a really difficult problem.

On the one hand, if you do not close the connection, it will remain open until the time has elapsed (1 minute), under load, you will reach the maximum connections (10 by default).

On the other hand, you call services asynchronously, so if you close the connection before receiving the callback, the callback will be lost.

There are a few things you could try:

  • increase max connections
  • close the connection in the callback handler
+4
+1

, :

,

  • ​​
  •     <wsHttpBinding>
            <binding name="MyWsHttpBinding">
                <reliableSession enabled="false"/> 
                <security mode="None" />
            </binding>
        </wsHttpBinding>
    

, , , "", .

, .

0

, , - . . , . Close - .

0

I would not use an asynchronous template with WCF. Instead, I would simply use synchronous calls with regular blocks to ensure that the connection is closed. Then I would wrap the whole mess in a regular Task (.NET 4.0) or ThreadPool work item.

0
source

All Articles