简体   繁体   中英

How to get the number of open/faulted channels for a WCF service?

I know I can use ServiceThrottlingBehavior to set how many concurrent sessions I'd like the service to support but in order to come up with the best values I'm trying to find out what's actually being used at different hours of the day. I'd like to expose a service method to return this live data or in the minimal case, log it.

Is there any way in a WCF service to see how many channels are currently open and/or in the faulted state?

After you "Open" your web service, your program or windows service (however your running it) should execute loop that monitors the status of your connections. If a connection faults, for instance, the program running the web service will not know about the fault unless you query the System.ServiceModel.CommunicationState(repeatedly).

  'execution basically stops here to loop through and check the status of host services
  While True
      For ii = 0 To i - 1  'i = count of started web services, -1 for zero index offset
         'check for broken connection case
         If objServiceHost(ii).State <> CommunicationState.Opened Then
            Throw New Exception("SynchronizationWS Service Host failed.") 
            Exit While
         End If
      Next
      Threading.Thread.Sleep(1000) 'sleep 1 second before going trying next
  End While

You might try something like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM