Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Basic WCF Call + Callback example

0.00/5 (No votes)
19 Mar 2012CPOL2 min read 38.6K   3.7K  
A basic WCF call + callback example in C# using WSDualHttpBinding.

Introduction

Although there are many WCF examples on the web there aren’t many examples that implement both WCF calls and callbacks in a simple way. This article expands on the WCF tutorial Microsoft has on its site (http://msdn.microsoft.com/en-us/library/ms734712.aspx) and adds a simple Callback method. The attached code consists of a Windows Service that hosts the WCF Service and a WindowsForms application that implements the client side.

The Service can be easily installed by clicking on the installService.bat file that comes within the release folder and uninstalled with uninstallService.bat. In addition, it provides logs that can be implemented using the project’s own TraceManager.

The Windows Forms application provides the user with the same WCF calls explained in the cited MSDN tutorial but it also offers the possibility of subscribing the client to the service so the service can perform callbacks on the client.

Tools Used

To edit and compile the code it is required that you use Microsoft Visual Studio 2008 or better. To run the compiled service and application you should only need installed the Microsoft Net Framework 2.0.

Procedure

The ServiceHost is published through WsDualHttpBinding to support the call and callback channels.

The calls are of course initiated from the client side. The callbacks are initiated from an asynchronous thread on the service side every 10 seconds to all subscribed clients.

The Service project also has a class that serves as a communication bridge for all other processes to ease locking problems. There are many other ways of doing this but this removes the burden of having to place lock statements in several places.

Conclusion

All in all I tried to keep it as simple as possible and implement both calls and callbacks. I developed this for my own use but I hope it can serve to help others as well. Comments and questions are welcome, positive and negative.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)