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: https://windows.azure.com/ 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: https://windows.azure.com/ 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.
· 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: https://MyAzureHello.servicebus.windows.net.
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.
Listing 1: Service Contract
Listing 2: Service Implementation
Listing 3: Host Implementation
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).
· Click download and hence install the NuGet Package Manager.
· Close the extension manager.
· Click online.
· 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.
Listing 5: Service Configuration
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.
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: http://msdn.microsoft.com/en-us/library/windowsazure/ee706729.aspx.