views:

54

answers:

2

Hi

I am creating a silverlight card game which talks to a WCF service using a duplex binding

Each client communicates with the service when it is their turn by sending their ID and the cards they want to play

And in response, the updated Game state is transmitted to each client

While I've been testing, I have had the instancing set up as follows

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]

This means the game state is maintained in memory.

Now if I want to set this up for widespread use, (it's unlikely to be very popular but lets assume that more than 1 game might be played at the same time), what would be the most appropriate WCF Instancing mode?

I am currently thinking that serializing the game state to a document database after each players turn, then retirieving it on future client comms

But I am curious to know if there is a way to maintain the game state in memory, but for multiple games

e.g. if there are 3 games happening at the same time, can the clients for game A all connect to one service instance aned the clients for game B connect to another instance?

Or is the only way to have each client pass a game id and retrieve a serialized game state from a DB or other data store?

EDIT:

I'm specifically interested in Sharable services - see this article http://msdn.microsoft.com/en-us/magazine/cc163590.aspx But that doesn't seem to be availiable in the version of WCF I am using. I only have Single, Persession and PerCall

A: 

The InstanceContextMode (as you probably know) is PerSession, PerCall or Single. None of these support the scenario of maintaining a single instance for a particular implementation of the service. Instead these refer to the nature of the connection between the service and the client. For instance PerSession will create new instance of you service implementation for each new client session.

The ideal solution I would think is to store saved games in a database keyed by game type, but keep ongoing games in memory within a singleon instance.

However, if you do need to implement something along the lines of instance sharing among clients then there is some documention on this.

Noel Abrahams
yes, and the question is how to "keep ongoing games in memory". A singleton instance isn't appropriate for multiple games being kept in memory, unelss the game state serialized/deserialized on each client request. I am asking if multiple instances can be kept in memory and have certain clients directed to certain client instances
Christo Fur
@Christo, the link in your post refers to some out-dated documentation. InstanceContextMode.Shared was never released. I've updated my answer with a possible workaround. (Although I still can't figure out why a Singleton won't work: store the state in a dictionary?)
Noel Abrahams
A: 

We kinda had the same requirement a time ago, and we did this using 'in-memory state management". Creating a List of Games Channels, and another list for users along with the game channel Id, so thats how we know which user is subscribed to which game channel.

a user can play multiple games, but cannot be entered into to same game twice, in case of any disconnects from Client/ Server, it can be connected again upon request from the client.

There are a lot of other things as well. I'd recommend to load test every solution you implement.

Mazhar Karimi