Windows Communication Foundation extensibility to the max

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.

Comments

# Sam Gentile's Blog (if (DeveloperTask == Communication && OS == Windows) said:

Agile/ALT.NET Zen and the Art of Software Development Acceptance Test "Lifecycle" DevLink 2009 - Good News Everyone! Some nice observations on conference organization in general Refactoring Day 17: Extract Superclass Fluent NHibernate 1.0RC

dinsdag 18 augustus 2009 0:40
# Scott Banwart's Blog said:

There wasn’t much action last week, but this week we have a couple new BizTalk tools and a nice series on WCF extensibility. Speaking of which, I need to sit down and finish reading that series myself.

BizTalk Configuration Manager – New R

vrijdag 21 augustus 2009 16:29
# DotNetShoutout said:

Thank you for submitting this cool story - Trackback from DotNetShoutout

vrijdag 21 augustus 2009 22:27
# Sanjeev Agarwal said:

Daily tech links for .net and related technologies - August 20-24, 2009 Web Development ELMAH (Error

zondag 23 augustus 2009 17:21
# 9eFish said:

9efish.感谢你的文章 - Trackback from 9eFish

maandag 24 augustus 2009 3:06