2

I created a WCF service and the user requirement is to have only one client connected on the service at a time.

So I set the value of the parameter maxConcurrentSessions to 1.

It's working great and if another client try to connect after a specific time it receives a timeout exception error.

But I don't like to send the timeout exception error to the client I want to have a more specific error like :

A timeout occurs because the number of maximum client on the service was reached.

Something like that.

It's there a way to do that?

Thanks

Bert
  • 80,741
  • 17
  • 199
  • 164
Hugo
  • 139
  • 1
  • 11

1 Answers1

0

You can override default exceptions by implementing IErrorHandler

From MSDN

To explicitly control the behavior of the application when an exception is thrown, implement the IErrorHandler interface and add it to the ErrorHandlers property. IErrorHandler enables you to explicitly control the SOAP fault generated, decide whether to send it back to the client, and perform associated tasks, such as logging. Error handlers are called in the order in which they were added to the ErrorHandlers property.

Implement the ProvideFault method to control the fault message that is returned to the client

Also check this one .Net WFC/Web service exception handling design pattern

Community
  • 1
  • 1
Surjit Samra
  • 4,614
  • 1
  • 26
  • 36
  • Yes but my goal is like to know if this timeout occured because the maxconcurrent sessions is reached. I mean, client A connect to the service, client B connect but enter a queue because a client is already connected to the service. A timeout occurs for client B after X times because it wasn't able to do the connection. How I can know the timeout occurs because a max session was reached. It's there's a way to know if the maxconcurrentsession is reached in WCF ? – Hugo Nov 28 '11 at 18:08
  • Looks like you are changing your goals :), Your original goal was to send a specific message , To achieve your new goal one approach could be write your custom binding and use maxoutboundconnectionsperendpoint http://msdn.microsoft.com/en-us/library/system.servicemodel.configuration.tcpconnectionpoolsettingselement.maxoutboundconnectionsperendpoint.aspx – Surjit Samra Nov 28 '11 at 18:20