Last week I visited Microsoft at the Redmond campus and spent the larger part of the week with the Windows Communication Foundation and Workflow Foundation team. I spoke with a lot of the team members and managed to get good insights into the things to come in WCF/WF 4.0.
I got a chance to talk to Nicolas Allen and Kenny Wolf. Besides the work-related issues that I wanted to investigate I also discussed my long-running attempt to create a very odd WCF client implementation. They gave me a couple of hints on how to take the last hurdles to get everything working. While still shrugging off the last bits of jetlag I managed to get the first implementation up and running. Although WCF was never designed with such weird things in mind, this proves that WCF is extensible beyond your imagination. I’ll walk you through it all.
Part 1: Background on game server protocols
Part 2: The big picture
Part 3: Formatting operations
Part 4: Applying formatting to operations
Part 5: Make your endpoints behave
But, just as a teaser preview, here are some code snippets of what this will all amount to:
[ServiceContract] public interface IRcon { [OperationContract(Action = "status")] string GetStatus(); [OperationContract(Action = "changelevel")] string ChangeLevel(string mapName); [OperationContract(Action = "mp_restartround")] void Restart(int seconds); } public interface IRconProxy : IRcon, IClientChannel { } class Program { static void Main(string[] args) { SourceRconTcpBinding binding = new SourceRconTcpBinding("abc123"); string uri = "raw.tcp://192.168.100.101:27015"; IRconProxy proxy = null; try { ChannelFactory<IRconProxy> factory = new ChannelFactory<IRconProxy>(binding, new EndpointAddress(uri)); factory.Endpoint.Behaviors.Add(new SourceRconEndpointBehavior()); factory.Open(); proxy = factory.CreateChannel(); proxy.Open(TimeSpan.FromSeconds(10)); string reply = proxy.GetStatus(); proxy.Restart(3); } catch (Exception ex) { Console.WriteLine(ex); } finally { proxy.Close(); } } }
Here, the most interesting lines of code are 31 and 32: a WCF client channel talking a proprietary, non-SOAP protocol over a TCP connection.