Example Three (WCF Duplex Communication with Multiple Clients)

This is the third example project in this series and is based off of the second example. This is a complete example of WCF using OO principles that leverage the NetDataContractSerializer. This example creates a number of clients that access the WCF service through multiple threads (a thread for each client). This example also demonstrates the ability of WCF to call back to clients--which is useful for "push" messaging scenarios. The zip file contains the following projects:

  • Domain: A project that houses the domain objects of the application. The domain objects are used in both the client code and the WCF service.
  • Interfaces: Where the WCF service interface sits. This is located in its own, separate project so that the server and client code can both access it (rather than forcing the client to build a proxy beforehand).
  • WcfClient: The client console application that creates multiple clients (40 at the time of writing) that call into the WCF service.
  • WcfService: The WCF service project.
  • WcfServiceHost: The console application that bootstraps the WcfService.

WCFDuplexCommunication.zip You should be able to download the zip file, unzip it, open up the solution, and build it without a problem. To test the application, set the WcfServiceHost as the startup project and run, and then set the WcfClient project to the startup project before running. Because this is a multithreaded application that simulates a number of clients contacting the WCF service, you might want to play around with the throttling parameters in the service and with the InstanceContextMode attribute applied to the WCF service.

AttachmentSize
WCFDuplexCommunication.zip506.11 KB

Comments



Running the client and the host on two different stations is generating a "The caller was not authenticated by the service" error. Any advice on how to proceed?



Sorry, Omar, I was out of town yesterday. I will take a look at this tonight and get back to you. I'd do so now but am catching up with work.



Hi..

I am using the WCF mechanism(Duplex communication) to communicate between the Client and server.
I am sending the data to Client from server as below
IMessageServiceCallback callback= OperationContext.Current.GetCallbackChannel()
This is working fine when Client initiates the communication first. Means Client sends the message to server
and server reply to that Client using the the above code. However this is not working if the Server wants to send the data to client before Client initiates the communciation. I am getting the exception"" Null reference exception".
Could you please help me in resolving this.
I read in the few articles server can also initiate the communication. But this is not happening in my case.

Also I would like to know is it possible that multiple clients listening to server message?
Waiting for your reply.

Thanks
Rashmi.