This is a simple working Real-Time data publisher written in C# NET 3.5. It is composed of two pieces, a server WCF console and a WPF client. It demonstrates a simple way of maintaining a persisted callback to multiple clients. Each client subscription is maintained by the server console.
The code demonstrates an implementation of the following:
- Publish / Subscribe Implementation (not events)
- ClientCallback subscription
- Fake Tick Plant
- Data Dictionary
- Object Serialization
How to Run
There are two working executables in this project, a WCF console (WCFMarketDataServer.exe) and a WPF client (WFCTickerWindow.exe).
First start the WCF console. You can only have one instance running. The server is ready once you see the "press any key" prompt:
Now you can start the client. You can start as many clients as you want to simulate multiple users. Each client should maintain its own set of real time data.
As you change the preset value on the combo boxes, a subscription / un-subscription requests will be processed by the server to maintain the proper data each to which each client is subscribed.
Using the Code
Below, find an overview of the main class structure. I am not going into much detail but it shows how the main data flows and the subscription mechanism is working.
The WCF server console is configured programmatically utilizing a TCP channel.
Uri baseAddress = new Uri("net.tcp://localhost:8080/MarketData");
serviceHost = new ServiceHost(typeof(CMarketDataManager), baseAddress);
NetTcpBinding pNetTcpBinding = new NetTcpBinding(SecurityMode.Transport);
serviceHost.AddServiceEndpoint(typeof(IMarketData), pNetTcpBinding, baseAddress);
CMarkerConfig.LogInfo("Adding Metadata behavior...");
ServiceMetadataBehavior servicemetadatabehavior = new ServiceMetadataBehavior();
servicemetadatabehavior.HttpGetEnabled = true;
servicemetadatabehavior.HttpGetUrl = new Uri("http://localhost:8081/MarketData");
Following is the service contact:
[OperationContract(IsOneWay = true)]
void SendTickUpdate(TickUpdate pTickUpdate);
[ServiceContract(Namespace = "tcp://localhost/", CallbackContract = typeof(
void SubscribeRT(CGenericMsg pCGenericMsg);
All data updates are sent via
IClientCallback implemented by the WPF client.
SubscribeRT() is designed to take a
CGenericMsg object. This object is generic so multiple types of messages can be added without having to change the contract.
Points of Interest
This sample helped me better understand what WCF and WPF are all about. It is a good introductory project into the frameworks for an intermediate developer.
I hope someone can benefit from it at some level as much as I did.
20+ yrs Leading and Developing Microsoft products in the Financial Industry.
My main background is VC++, server and client development.
Currently focused in WPF/XAML, Windows 8 and Windows Azure Server technologies.