My Hello Azure Service Bus WCF Service–Step by step guide

This is the first post in a series to take you through my learning experience to using the Windows Azure service bus. The Service Bus is a concrete implementation of the service bus pattern designed to operate at Internet scope within highly-scalable Microsoft data centers as a constituent of the Windows Azure platform. The Service Bus provides a federated identity and access control mechanism through Access Control, a federated naming system, a dynamic service registry, and a robust messaging fabric capable of overcoming the internet and distributed services connectivity. The internet challenges that any distributed service platform face are summarized in the below diagram.


The way that the service bus overcomes these challenges is by implementing a relay service pattern as below.


Here’s how it works: the on-premises service connects to the relay service through an outbound port and creates a bidirectional socket for communication tied to a particular rendezvous address. The client can then communicate with the on-premises service by sending messages to the relay service targeting the rendezvous address. The relay service will then “relay” messages to the on-premises service through the bidirectional socket already in place. The client does not need a direct connection to the on-premises service nor does it need to know where it resides. The on-premises service doesn’t need any inbound ports open on the firewall. This is how most instant messaging applications work today.

A central component of the Service Bus messaging fabric is a centralized (but highly load-balanced) relay service that supports a variety of different transport protocols and Web services standards, including SOAP, WS-*, and even REST.  The relay service provides a variety of different relay connectivity options and can even help negotiate direct peer-to-peer connections when possible.

So in this article I will show you how to develop your first hello service hosted on the service bus. The major steps can be summarized as below.

Step 1:               Create a new service bus namespace on the Azure service bus.

Step 2:               Implement the service and client.

Step 3:               Configure the service and client to use the required relay binding configuration.

So as you can see it is as easy as 1, 2, and 3. Or is it?! J

Step1: Create a new service bus namespace

So you need to go to the URL: that will request you either to login using a live ID that has already an active Azure subscription or to sign up. If you already have an account then just logon, or if not you can click sign up.


That would lead you to the purchase screen of subscription options, study your options well and pick whatever type you want or (even better) click on the FREE trial.


Then you will be asked to login using an existing live ID then you will need to go through three steps as below:



Then in the third step you would need to enter a credit card just as a form of verification and voila you have a three month trial subscription on Azure.

Next logon to your management portal using you live ID on the URL: it should look something like this.


Now to create a new namespace do the following steps.

·         Click on “Service Bus, Access Control & Caching” from the bottom left.

·         Then click on “Service Bus”

·         Then click “New”

·         Enter the namespace name and the portal will check if it is available or not for you and select the needed details as below:

·         Click “Create” and the namespace would be ready to use.

·         Now we will need three details to get started, the service hosting URL, the secret issuer name and issuer secret. The service hosting URL would be dependent on the namespace you already created so for the shown above example the URL would be:

·         To get the secret details click on the created namespace.

·         Then scroll the right action pan all the way down and click on “View” for the “Default Key”.

·         It will then give you the option to copy both the issuer name and the issuer secret to the clipboard. Do this one by one and keep this information were you can use it later.

Step 2: Implement the service and client

This is a straight forward step. Just create two console applications, one for the service host and another for the client and create a service definition as below.


public interface IHelloServiceBus



    string SayHello(string name);


Listing 1: Service Contract

public class HelloServiceBus : IHelloServiceBus


    public string SayHello(string name)


        string greeting = string.Format("Hello {0}!", name);

        Console.WriteLine("Returning: {0}", greeting);

        return greeting;



Listing 2: Service Implementation

static void Main(string[] args)


    Console.WriteLine("**** Service ****");

    ServiceHost host = new ServiceHost(typeof(HelloServiceBus));



    Console.WriteLine("Press [Enter] to exit");





Listing 3: Host Implementation

static void Main(string[] args)


    Console.WriteLine("**** Client ****");

    Console.WriteLine("Press <Enter> to run client.");




    ChannelFactory<IHelloServiceBus> channelFactory =

        new ChannelFactory<IHelloServiceBus>("webRelay");

    IHelloServiceBus channel = channelFactory.CreateChannel();


    for (int i = 0; i < 10; i++)


        string response = channel.SayHello("Service Bus");






Listing 4: Client Implementation

Now we need to configure both the client and service to use the service bus bindings.

Step 3: Configure the service and client to use the required relay binding configuration

All you need to do is to put the proper Azure service bus configuration. But before you do that how would the service and client implementation know where to get the binding implementation from? You did not add any custom references, right?! So here is how.

·         Make sure both the client and service is using the .NET 4 profile (not the client profile).

·         The go in Visual Studio to tools and then extension manager:

·         Click on line gallery and search for “NuGet”

·         Click download and hence install the NuGet Package Manager.

·         Close the extension manager.

·         Right click on the references node for the service project and click “Manage NuGet Packages”.

·         Click online.

·         Search for “Azure” and select the “Windows Azure Service Bus” and click  “Install”.

·         Install the same NuGet package to the client project.

·         Now that you have the Azure assemblies in place you can change the service and client configurations as below.



    <service name="Service.HelloServiceBus">

      <endpoint address="" behaviorConfiguration="sharedSecretClientCredentials" binding="ws2007HttpRelayBinding" contract="Service.IHelloServiceBus"/>





      <behavior name="sharedSecretClientCredentials">

        <transportClientEndpointBehavior credentialType="SharedSecret">


            <sharedSecret issuerName="[Issuer name retrieved before]" issuerSecret="[issuer secret retrieved before]"/>







Listing 5: Service Configuration



    <endpoint address="" behaviorConfiguration="sharedSecretClientCredentials" binding="ws2007HttpRelayBinding" contract="Service.IHelloServiceBus" name="webRelay"/>




      <behavior name="sharedSecretClientCredentials">

        <transportClientEndpointBehavior credentialType="SharedSecret">


            <sharedSecret issuerName="[Issuer name retrieved before]" issuerSecret="[issuer secret retrieved before]"/>







Listing 6: Client Configuration

Now you are ready to start the service and (wait for it to properly start, as it take some time – couple of minutes or so) the client and watch them communicate through the Azure service bus.

Final Notes

During this exercise I tried many bindings and I must say that the most reliable one I used was the “ws2007HttpRelayBinding” (I mean reliable from the perspective of being able to start hosting the service with no problems).

Hosting a service behind a proxy (specially a proxy that requires authentication) is not supported and does not workL. Check this URL:

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.