Click here to Skip to main content
Click here to Skip to main content

Basic WCF Call + Callback example

, 19 Mar 2012
Rate this:
Please Sign up or sign in to vote.
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)

About the Author

javieranton
Software Developer NexTReT S.L.
Spain Spain
Javier attended Rochester Institute of Technology and now works as a Firmware Engineer at NexTReT S.L. and Amper S.A.

Comments and Discussions

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

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 19 Mar 2012
Article Copyright 2012 by javieranton
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid