How to control client connection to WCF service?

I created a WCF service where the ServiceHost class cannot be created as Singleton. I need to track every connection to this service, even before the first call to the methods associated with it. In practice, I would like to register when a client opens a channel for communication with the service. Is it possible? On the Internet, I find only two kinds of solutions:

  • The ServiceHost object must be created by the server and used as a singleton. Then I have to provide an initial method called by the client to register itself with the service.
  • Use the performance monitor to display the counters associated with the service.

Neither (1) nor (2) satisfy my needs, because I want to create my own application, and, as I said, I can not use singleton mode. Have you ever encountered such a problem? How did you do it?

Last but not least, I also need to track calls for each method the service provides. Is there any way to do this? Any help would be appreciated.

+4
source share
2 answers

There are a number of issues with this.

First of all, the preferred way to call the WCF service is a model for each call, for example. your client will call the service method, which invokes the creation of the service class instance on the server, the corresponding method is executed, and then the service instance is deleted again. Thus, you cannot control client connections per se - they exist only for fractions of a second during a call.

In addition, there is not much infrastructure on the server side to monitor calls per second, etc., with the exception of performance counters. The new server add-on product, formerly known as Dublin (currently called AppFabric), should bring many improvements in this area (manageability) - see This MSDN for more information .

But even today, you might think about taking a service class and controlling the creation and destruction of this class. The service class also has a reference to ServiceHost , which created it using the OperationContext.Current.Host property, so that you can somehow tell the host that a new instance of the service class has been created. There, only goign is the only host object, so it can work, but it requires a well-designed and well-tested approach to multithreading in ServiceHost (you can create your own ServiceHost to achieve something similar).

This could be a step towards "monitoring my service." As for performance monitoring, why don't the dozens of WCF performance counters help you or provide you with the information you need?

+4
source

Have you looked at the WCF trace and the WCF message log ?

0
source

Source: https://habr.com/ru/post/1300808/


All Articles