Monthly Archives: May 2005

Cinco de Mayo de Cinco!

The first thing I’m always asked about my band (me, Aaron, Brian, and Mike) is “what’s your name?” This should be a simple enough question, but we’ve had an ongoing identity crisis, and nothing has stuck to date.

On May 5th we played out at a Cinco de Mayo party under the name “El Driftwood”. It was our first big event with the current lineup (Mike joined in October as our third bass player in two years), and it was a blast. Lauren took a bunch of pictures, much tequila was consumed, and courtesy of some tapers in attendance I’ve posted recordings here.

The latest name under consideration is “Mostly Harmless”, which I find amusing. I’d love to hear your opinions in this area.

Me on drumsThe whole band

Channels 103: Addressing the World

The next step in our custom transport walk-through is to create our channel managers. This includes an IChannelFactory for our client side channels, and an IChannelListener for our service-side channels.

Both IChannelFactory and IChannelListener derive from IChannelManager. IChannelManager is responsible for tracking channels that are created or accepted. IChannelManager also has a property to control the MessageVersion supported for Messages sent or received on its channels. Lastly, it requires you to specify a Scheme to use for message addressing.

Which leads me to a crucial aspect in defining a channel, namely: what is your addressing model?

For layered channels, the addressing model is simply that of the channels they are layered on top of. Such implementations look like:

public override string Scheme
get { return InnerListenerFactory.Scheme; }


public override void SetUri(Uri uri)

return InnerListenerFactory.SetUri(uri);


public override void SetUniqueUri()

return InnerListenerFactory.SetUniqueUri();


For transport channels, it’s an area that takes some thought. While HTTP has a pre-defined syntax and semantic, when writing a new transport you need to define both of these. Concretely, this includes a scheme and its associated URI syntax. This work is closely related to how you bind your protocol to SOAP.

The first item to consider is how your client Channels will resolve the URI. For example, HTTP takes the host name and TCP port of the URI (based on the defined URI grammar), uses DNS to resolve the host name into an IP Address, establishes a TCP connection to the resulting (IP Address, port), and sends an HTTP request using the path portion of the URI in our POST request.

The second factor in your URI design is how to match an incoming URI to an IListenerFactory (which will dispatch to a service). IListenerFactory URIs are broken down into 2 parts: a base address and a relative address. The base address is defined by your hosting environment (ServiceHost<T>, IIS vroot, etc). Individual endpoints then define a simple relative address. Note that an endpoint can be configured with a full URI, but this is only necessary in a few corner cases. This model allows for the host to be decoupled from its endpoints, and also allows the transport to optimize the network resources it uses (i.e. we only require at most one per base address, and can share that resource among relative endpoints).

Given these requirements, we define our URI syntax for UDP as:

soap.udp:// host [":" port] path-absolute

where host, port, and path-absolute are defined in the ABNF of RFC 3986.

For example: soap.udp://localhost:7000/service/endpoint

Our UdpOutputChannel will take the hostname (localhost) and convert it to an IP Address:

switch (remoteAddress.Uri.HostNameType)
// …
case UriHostNameType.IPv4:
case UriHostNameType.IPv6:
remoteIP = IPAddress.Parse(remoteAddress.Uri.Host);

case UriHostNameType.Basic:
case UriHostNameType.Dns:

IPHostEntry hostEntry = Dns.GetHostEntry(remoteAddress.Uri.Host);
if (hostEntry.AddressList.Length > 0)
remoteIP = hostEntry.AddressList[0];
// …


We will then use the resulting IP Address along with the UDP port from the URI (7000), construct a UDP socket to that remote endpoint, and set:

message.To = RemoteUri (soap.udp://localhost:7000/service/endpoint).

When our UdpListenerFactory (which is on the receiving end of the UDP socket) deserializes the message, it will compare the incoming message.To against its Uri and only accept the message if the two values match. More advanced implementations could factor out the listening socket into a shared app-domain wide resource that dispatches to the appropriate UdpListenerFactory based on the To of the incoming message.

With our transport addressing model crisply defined, we continue on to actually sending and receiving Messages over UDP!

It was a Darth and Stormy Knight

Attack of the Muppets!Star Wars Episode III opened today (actually last night at midnight from what I hear). A bunch of people from work checked it out and enjoyed it.

In preparation for tomorrow’s viewing, Lauren sent me a fun Star Wars refresher guide from Slate. I’ve also received a bunch of other silly links, including a haX0red trailer and a Star Wars photoshop contest. Yet I think I’m most partial to the Darth Vader blog.

Anyways, I’m keeping my expectations in check (Episodes I and II have set a pretty low bar), so it should be an entertaining respite from the very non-Seattle-like thunderstorms we’ve been having.

Saga of The Best Turkey Burger Ever

Southwest Style Turkey BurgerLast summer on a whim, Lauren and I bought a package of “Southwest Style Turkey Burgers” from Trader Joe’s. We forgot about them and they sat in the freezer for a month or so. Then we decided to bring them to a BBQ at Mike’s house. They were, in a word, awesome. Never again did a package of them last for more than a week or two.

Then on a rainy weekday in February, disaster struck. Walking down the freezer aisle, there were garden burgers, buffalo burgers, gorgonzola stuffed beef burgers, but no southwest turkey burgers. We asked the staff and were told: “We no longer stock that item. It was discontinued due to slow sales.” I was thunderstruck. I considered wearing all black for a week. Went through all seven stages of loss in fairly rapid succession.

Fast forward to yesterday afternoon and a routine trip to TJ’s to fill the empty fridge. I was in a wandering mood and decided to stroll all the aisles (at our local TJ’s this is all of 4 aisles). Just past the frozen Turbot I stopped, agape. Lauren wondered if I lost my mind, and all I could do was point. They had come back from the dead. The Southwest Turkey Burgers had returned. It was a miraculous event. The checkout lady told us that they hadn’t been discontinued, merely “out of stock”. For 3 months? I don’t know if I believe it, but who am I to question. And just to be safe, we purchased 4 boxes on the spot.

And now the story has been told. I encourage all of you who live near a Trader Joe’s to try this very affordable delicacy, and help ensure that the Southwest Turkey Burger stays off the “slow sales” endangered grocery list.

UPDATE (04/12/06): They are gone again. Talked to the staff on Capitol Hill and they had no information to help me. There will be a big hole in our grilling this summer 🙁

UPDATE (11/12/06): They are back! Hopefully this time they are here to stay…

Interlude: Working from home

HomeA co-worker just reminded me that I promised to discuss the effects a home network could have on your Indigo Service, and how that could differ based on the transport you are using.

The first thing to realize about a home network is that your computer is likely behind a NAT. Most DSL or Cable routers will act in this role. The router is assigned an IP Address from your service provider via DHCP, and therefore your router is the only member of your network that is globally addressable. Which means that while you can connect to other machines on the internet, they cannot connect to you.

The practical upshot of this situation is that you cannot use the “dual” standard bindings (a.k.a. WsProfileDualHttpBinding and NetProfileDualTcpBinding) to access services located outside of your home network. Which won’t affect you unless you are using a duplex service contract. I can already hear you saying “but duplex contracts are incredibly useful!” Yes they are. And if you want to use them from behind a NAT you have 2 options:

  1. Use NetProfileTcpBinding. This will allow you to be the client for duplex communication with another Indigo endpoint.
  2. Host a router service on the Internet. This is a complicated solution that entails bridging the TCP connection from your home machine to a dual HTTP connection with the service. I call out HTTP specifically, because the only scenario where NetProfileTcpBinding will prove insufficient is if your service is a non-Indigo service and needs to be contacted through HTTP. I will try to comment further on this solution in a future post.

The second thing to note is that your network may not be configured with DNS. Which means that even though machines within your network are all addressable, you may need to identify them by their IP Address. To do this, simply use your machine’s IP Address where you would normally use a hostname (for a Service’s URL or a Proxy’s remote endpoint).

And now back to our (somewhat) regularly scheduled Channels/layering tutorial…


Limber Liger LogoLast weekend I dragged Lauren to San Francisco to play in Shinteki Decathalon, which is a miniature version of the crazy overnight games I’ve played in the past. Tom and Eric joined us to complete the “Limber Ligers”. It was a good time, we found out just how slow a paddle boat with four adults travels, and that the Fremont Open Space Preserve is not actually in Fremont, CA (though it does sport some nice views).

We came in a respectable 10th out of 23 teams, in spite of completely blanking on one of the puzzles. After reading this article I wonder if we would have done better by lying down to work on our puzzles and getting more “noradrenaline” into our brains. 🙂

Channels 102b: Close vs. Abort (vs. Dispose)

A major source of confusion with Indigo Beta 1 is how to shut down our communication objects, so I’m going to drill further into this topic. First, I must note that this area is under review for Beta 2. We understand there are some inconsistencies between our usage of IDisposable and its usage by other parts of the .Net Framework. But the CTP bits are what you have to work with for now, so I will do my best to explain them 🙂

When I talked about the common state machine in Indigo, I neglected to point out that ICommunicationObject derives from IDisposable. This gives you a third option (in addition to our Close() and Abort() methods) for shutdown. It also allows you to use any ICommunicationObject with the C# using statement.

In the CTP bits, Dispose == Abort. Or put another way, Dispose != Close. This is a point worth re-iterating. Dispose will rudely abort your object.

So when you are done with an ICommunicationObject, what should you do?

First you should call Close(), which will flush any outstanding buffers, acknowledge outstanding data, and provide a graceful shutdown. This is similar to what happens when you call Stream.Close() or XmlWriter.Close(). Then you should make sure that Abort/Dispose is called if anything fails (i.e. throws an exception). This way any heavyweight network resources are released in an eager fashion.

Which leads to code like the following:

IOutputChannel channel = CreateOutputChannel();

using (channel)



Channels 102: Communication object lifecycle

Before we dive into implementing our Channels, it’s important to first understand the lifecycle of communication objects in Indigo. These include our Channel Layer objects (IChannel, IChannelFactory, and IListenerFactory), as well as Typed Layer objects (ServiceHost, ServiceSite, EndpointListener).

All such objects derive from ICommunicationObject, and have a common state machine.

There are 5 states represented by the CommunicationState enum:

  • Created — This is the state of an ICommunicationObject when it is first instantiated. The object may be configured in this state (e.g. properties can be modified, events registered, etc). No I/O occurs in this state.
  • Opening — Objects transition to this state when ICommunicationObject.Open() is called. At this point properties are made immutable, and I/O may begin. This transition is only valid from the Created state.
  • Opened — Objects transition to this state when the open process completes. This transition is only valid from the Opening state. At this point the object is fully usable for transfer.
  • Closing — Objects transition to this state when ICommunicationObject.Close() is called for a graceful shutdown. This transition is only valid from the Opened state.
  • Closed — In the Closed state objects are no longer usable. In general, most configuration is still accessible for inspection purposes, but no communication can occur. This state is equivalent to being disposed.

There are events that fire for each state transition. ICommunicationObject also has an Abort() method that can be called at any time. This will cause the object to transition immediately from its current state into the Closed state. Abort() indicates that any unfinished work will be rudely terminated (Exceptions are likely in this case).

With this background knowledge in place, we can now go into detail about writing our factories.