I’m creating a game application with networking and I’m trying to utilise WCF. Ultimately it will be a peer to peer system but for development purposes I’ve split the application into core and player applications. This means that WCF services need to interact with the data on both the host and the client. So my question is how do I get a service to interact with the objects on the host application. If I set the InstanceContextMode of the ServiceBehaviour attribute to InstanceContextMode.Single then I can pass a class instance to the ServiceHost constructor and can then interact with Host objects, but how do I do this when I’m passing a class type to the ServiceHost constructor, which I must do if I’m using PerCall or PerSession InstanceContextMode.
All the simple examples for WCF services use things like calculators. With the Calculator example you can pass data from the client via the method parameters of the class/ interface, and you don’t need to interact with any objects on the host. Am I using the wrong tool for the job?
Take a look at full duplex communications in WCF… You should be able to find a whole bunch of chat room examples (that’s a good parallel – many clients maintaining state through a central server).
http://msdn.microsoft.com/en-us/library/ms731064.aspx
EDIT It looks like the question has more to do with how to access shared server state…
There are a number of ways to do this. One way to do this would be to create a singleton instance of a class on the server side that manages shared state:
Then, in a service that is implemented as PerCall: