Click here to Skip to main content
15,867,835 members
Articles / Programming Languages / C#
Tip/Trick

Basic WCF Call + Callback example

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
19 Mar 2012CPOL2 min read 37.9K   3.7K   10   3
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)


Written By
Software Developer NexTReT S.L.
Spain Spain
Javier graduated from Rochester Institute of Technology in 2010 and has been working as a software developer since then

Comments and Discussions

 
QuestionThe caller was not authenticated by the service Pin
Member 9505516-Jun-13 22:54
Member 9505516-Jun-13 22:54 
QuestionWorks great! Pin
David Covert21-Oct-12 11:33
David Covert21-Oct-12 11:33 
Questiondoesnt compile Pin
jnlt25-Sep-12 8:08
jnlt25-Sep-12 8:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.