TwilioCON 2012 Developer & Doers @ San Francisco, CA – Day 2

TwilioCON 2012 Hackathon was fun, teamed up with John Palmer @citriusjohn and kicked around a few ideas however figured it would be best if we waited for TwilioCON 2013 to actually compete.

It was great to finally meet some of the people I’ve done some work with remotely and/or through online meetings e.g. Evan Cummack (@cummack), Devin Rader (@devinrader), among other people at TwilioCON. Another highlight of the second day was hearing the good news that we are officially been approved to as an Authorized Twilio SI (Systems Integrator), thanks Greg, Cheetan, and the rest of Twilio’s SI division for making this happen. Wrapping up I had a blast, and hopefully we can do it again next year…!

TwilioCON 2012 Developer & Doers @ San Francisco, CA – Day 1

Had an awesome day yesterday @ TwilioCON 2012 here at San Francisco, CA. Attended some pretty interesting key notes and lab sessions. I really appreciate some of the new features added especially working with call queues ( with Twilio Client (

The demo of full browser soft phone was totally awesome, and having almost full Twilio Client ability on the client side as you would on the server side was also rocked! As day one of TwilioCon 2012 was wrapping up and I started packing, guess what?! Saw Scott Guthrie and fellows walk through the door, will keep you guys posted on what this is about in tomorrows blog, or you can keep an eye on my Twitter ( for updates on this.

Last but not least thanks for the Twilio VIP Dinner invite, had a blast!

Declaritively and Programitcally Subscribing to the Windows Azure Service Bus Relay with WCF

Preferably I like to have most of the configuration for WCF in my config file(s), however when PoC’ing and time is of essence, spending time troubleshooting your config file(s) can be frustrating, for example:

Web.config ‘TransportClientEndPointBehavior‘ element is not recognized when trying to configure your service/application to wire up to Windows Azure Service Bus so that you can push messages on to it, so that you can start relaying.

Error squiggly (message):

“The element ‘behavior’ has invalid child element ‘transportClientEndpointBehavior’. List of possible elements expected: ‘clientVia, callbackDebug, callbackTimeouts, clear, clientCredentials, transactedBatching, dataContractSerializer, dispatcherSyncronization, remove, synchronousRecieve, enableWebScript, webHttp, endpointDiscovery, soapProcessing’.”

Spent some time Googling and regretfully didn’t find any documentation out there on how subscribe to Windows Azure Service Bus 100% programitcally, so hence this blog post. So, let’s get started on how to wire up to Azure’s Service Bus with both approaches.

If you need to know how to setup the Windows Azure Service Bus in the Azure Portal please read

First, let’s review how to push messages onto the Windows Azure Service Bus for relaying.

Programitically (zero configuration in your .config file)

  • Create an interface that implements IAzureTunnelService, IClientChannel.

        public interface IAzureTunnelServiceChannel : IAzureTunnelService, IClientChannel
  • Wire up to push messages on Windows Azure Service Bus for relay.

                var serviceUri = ServiceBusEnvironment
                    .CreateServiceUri("sb", "yournamespace", "relaystatus");
                var sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();
                var tokenProvider = TokenProvider
                    .CreateSharedSecretTokenProvider("owner", "secretkey");
                sharedSecretServiceBusCredential.TokenProvider = tokenProvider;
                var endpoint = new ServiceEndpoint(
                    new NetTcpRelayBinding(
                        new EndpointAddress(serviceUri));
                var channelFactory = new ChannelFactory<IAzureTunnelService>(endpoint);
                var channel = channelFactory.CreateChannel();
                var result = channel.RelayRequest(yourmodel);


  • web.config/app.config (system.serviceModel section)

    In the config we are introducing all known service bus extensions. You can remove the ones you don’t need.

          <endpoint name="relayrequest" contract="YourNameSpace.AzureTunnel.Common.Contracts.IAzureTunnelService" binding="netTcpRelayBinding" address="sb://" behaviorConfiguration="sbTokenProvider" />
            <behavior name="sbTokenProvider">
                  <sharedSecret issuerName="owner" issuerSecret="yoursecretykeygoeshere" />
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
          <!-- In this extension section we are introducing all known service bus extensions. User can remove the ones they don't need. -->
            <add name="connectionStatusBehavior" type="Microsoft.ServiceBus.Configuration.ConnectionStatusElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="serviceRegistrySettings" type="Microsoft.ServiceBus.Configuration.ServiceRegistrySettingsElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="netMessagingTransport" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingTransportExtensionElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="tcpRelayTransport" type="Microsoft.ServiceBus.Configuration.TcpRelayTransportElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="httpRelayTransport" type="Microsoft.ServiceBus.Configuration.HttpRelayTransportElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="httpsRelayTransport" type="Microsoft.ServiceBus.Configuration.HttpsRelayTransportElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="onewayRelayTransport" type="Microsoft.ServiceBus.Configuration.RelayedOnewayTransportElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="basicHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.BasicHttpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="webHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.WebHttpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="ws2007HttpRelayBinding" type="Microsoft.ServiceBus.Configuration.WS2007HttpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="netTcpRelayBinding" type="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="netOnewayRelayBinding" type="Microsoft.ServiceBus.Configuration.NetOnewayRelayBindingCollectionElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="netEventRelayBinding" type="Microsoft.ServiceBus.Configuration.NetEventRelayBindingCollectionElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add name="netMessagingBinding" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement, Microsoft.ServiceBus, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  • C# Code

                var channelFactory = new ChannelFactory<IAzureTunnelServiceChannel>("relayrequest");
                using (var channel = channelFactory.CreateChannel())
                    return channel.RelayRequest(url, myModel);

Note: To shortcut some of this configuration you can add the appropriate references and config configurations by using NuGet and installing the Windows Azure Service Bus package.

Finally, let’s wire up to receive messages off the Windows Azure Service Bus that we relayed earlier (consumer, demonstrated with a console app) programatically.

  • Service Interface

        [ServiceContract(Namespace = "urn:ps")]
        public interface IAzureTunnelService
            XElement RelayRequest(string url, YourModel yourModel);
  • Service Implementation

        public class AzureTunnelService : IAzureTunnelService
            public XElement RelayRequest(string url, YourModel yourModel)
  • Host the WCF Service

            private static void Main(string[] args)
                var serviceHost = new ServiceHost(typeof (AzureTunnelService));
                    typeof (IAzureTunnelService), 
                    new NetTcpBinding(), "net.tcp://localhost:9385/relayrequest");
                    new NetTcpRelayBinding(),
                        .CreateServiceUri("sb", "yourSBnamespace", "relayrequest"))
                        .Behaviors.Add(new TransportClientEndpointBehavior
                                TokenProvider = TokenProvider
                Console.WriteLine("Press ENTER to close.");

Yes, we have configuration in code, however push comes to shove, it’s always good to have an alternative solution. Being pragmatic about this, how often are you going to need to change your configuration on how your are communicating with Windows Azure Service Bus anyway?

Happy Coding…! 🙂