tags:

views:

388

answers:

3

Hi I have an application that operations like this..

Client <----> Server <----> Monitor Web Site

WCF is used for the communication and each client has its own session on the server. This is so callbacks can be used from the server to callback to the client.

The objective is that a user on the "Monitor Website" can do the following:

a) Look at all of the users currently online - that is using the client application. b) Select a client and then perform an action on the client.

This is a training system so the idea being the instructor using a web terminal can select his or her target client and then make the client application do something. Or maybe they want to send a message to the client that will be displayed on the clients screen.

What I cant seem to do is to store a list of all the clients in the server application, that can then be retreived by the server. If I could do this I could then access the callback object for the client and call the appropriate method.

A Method on the monitoring website would look something like this...

Service.SendMessage(userhashcode, message)

The service would then somehow look up the callback that matches the hashcode and then do something like this

callback.SendMessage(message).

So far I have tried without look to serialise the callbacks into a centralised DB. However, it doesnt seem possible on the service to serialise a remote object as the callback exists from the client.

Additionally I thought I could create a global hash table in my service but im not sure on how to do this and to make it accesible application wide.

Any help would be appreciated.

A: 

Typically, WCF services are "per-call" only, e.g. each caller gets a fresh instance of the service class, it handles the request, formats the response, send it back and then gets disposed. So typically, you don't have anything "session-like" hanging around in memory.

What you do have is not the service classes themselves, but the service host - the class that acts as the host for your service classes. This is either IIS (in that case you just need to monitor IIS), or then it's a custom app (Windows NT Service, console app) that has a ServiceHost instance up and running.

I am not aware what kind of hooks there might be to connect to and "look inside" the service host - but that's what you're really looking for, I guess.

WCF services can also be configured to be session-ful, and keep a session up and running with a service class - but again: you need to have that turned on explicitly. Even then, I'm not really sure if you have many API hooks to get "inside" the service host and have a look around the current sesssions.

Question is: do you really need to? WCF exposes a gazillion of performance counters, so you can monitor and record just about anything that goes on in WCF - wouldn't that be good enough for you?

Right now, WCF services aren't really hosted in a particularly well-designed system - this should become better with the so-called "Dublin" server-addon, which is designed to host WCF services and WF workflows and give admins a great experience monitoring and managing them. "Dublin" is scheduled to be launched shortly after .NET 4.0 becomes available (which Microsoft has promised will be before the end of calendar year 2009).

Marc

marc_s
A: 

What I have done is as follows...

  1. Created a static instance in my service that keeps a dictionary of callbacks keyed by the hashcode of each WCF connection.

  2. When a session is created it publishes itself to a DB table which contains the hash code and additional connection information.

  3. When a user is using the monitor web application, it can get a list of connected clients from the DB and get the hashcode for that client.

  4. If the monitor application user wants to send a command to the client the following happens..

    • The hashcode for the sessionn is obtained from the db.
    • A method is called on the service e.g. SendTextMessage(int hashcode, string message).
    • This method now looks up the callback to the client from the dictionary of callbacks and obtains a reference to it.
    • The appropriate method in this case SendTextMessage(message) is called on the callback.

Ive tested this and it works ok, Ive also added a functionality to keep the DB table synchronised to the actual WCF sessions and to clean up as required.

RemotecUk
A: 

Hi RemoteUk,

you seem to have managed what i'm seeking for:

When a session is created it publishes itself to a DB table which contains the hash code and additional connection information.

Can you perhaps tell me how you've implemented this.

Would be a great help.

Kind Regards Nihat

Edit: Oh, i guess now i understand what you made. You didn't manage to save the Callback Channel into the DB, right?

Nihat