One of the biggest concerns we hear when talking to clients about moving to the cloud is protecting their data. Organizations are wary of moving their important data up the cloud for fear of losing control of it. One of the easiest ways to ease that transition up to the cloud is to build your application in the cloud and keep your data on premise and use the Azure Relay Service to bring your data to your application in a secure way.

This walk through will assume you already have the Azure SDK downloaded and installed, but if you do not there is a link at the bottom to download it
.

Setting up the Relay Service

  1. Setting up the Service Namespace
    1. Log into your Windows Azure Account
    2. From the left hand menu select Service bus
    3. If this is your first service bus it will ask you to create a new namespace
    4. Enter in the Namespace name, what region, type and tier. And click ok For our example we are going to use Messaging and Standard tier

    5. Once the service is created you should see a dashboard, at the top we are going to be focusing on the relays. If you were to click there now you wouldn't see anything but a message suggesting that you create one.
  2. Creating your WCF Service
    1. The initial creation of the WCF service is just like any other WCF service you may build
    2. Once you are ready to create the relay you will have to add the Service bus Nuget Package by running the following command Install-Package WindowsAzure.ServiceBus
    3. Once package is installed look at your web config. You will notice a bunch of new entries for the service bus
    4. We are interested in the netTCPRelay binding. We are going to be adding this endpoint to our existing WCF endpoint.
    5. In order to add the endpoint we will need to grab the connection information off of the Azure Management Portal. The link to the connection information is at the bottom of web page

    6. Click the connection information link and copy the url. It should look something like this Endpoint=sb://captechmessaging.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=E7whhMFN/C1ipSUnSC6VW2qTOvenopG2miypT7ry/xQ=

      We are going to take the first Endpoint address part of this url and put it as an extra endpoint for our service. We are going to take the next two sections, SharedAccessKeyName and the Key and add them as an endpoint behavior. <>> <> name="MessageExample.CapTechMessagingService"> <> name="basic" contract="MessageExample.ICapTechMessagingService" binding="basicHttpBinding" address=""> <> contract="MessageExample.ICapTechMessagingService" binding="netTcpRelayBinding" address="sb://captechmessaging.servicebus.windows.net/SecureMessage" behaviorconfiguration="sharedAccessSignatureClientCredentials"> > > <>> <>> <> name="sharedAccessSignatureClientCredentials"> <>> <>> <> keyname="RootManageSharedAccessKey" key="E7whhMFN/C1ipSUnSC6VW2qTOvenopG2miypT7ry/xQ="> > > > > > >>>
    7. Run your WCF service to confirm everything is working.
    8. Open back up your Windows Azure Management Console and click on the relay tab. You should now see an entry for your account. Congratulations- you have a relay service set up.

  3. Calling the relay service: As long as the endpoint is up and has access to the internet you should be able to call the relay from anywhere just like you would a normal WCF service. In our case we can call it programmatically by creating our bindings in C# code var cf = new ChannelFactoryicaptechmessagingservice>(new NetTcpRelayBinding(), new EndpointAddress(ServiceBusEnvironment.CreateServiceUri(SCHEME, ServiceNamespace, ServicePath))); cf.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior { TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(##yourkeyname##, ##yourprivatekey##); }); _service=cf.CreateChannel();

That is the basic way to set up and call the Azure Relay service. There are however, a few other interesting pieces to note. Depending on your IIS settings your application pool will expire after a certain amount of time, usually 20 minutes. Once the application pool recycles you will lose the relay endpoint until someone calls it from a normal HTTP endpoint. There are ways to make sure that your service never dies, and that it will auto restart on the box restarting from normal patching and things like that. I will save that for a future article, so stay tuned.

Summary

  1. Azure service bus relay is an easy way to get your data up to the cloud in a secure manner
  2. Setting it up is easy and once you have a namespace you can have x number of relays
  3. You can have more than one listener for a relay, which allows for load balancing scenarios
  4. You must ensure that your wcf service is resilient and will auto restart or else you will lose your connection to the cloud on iis app pool recycles or the box restarting.

Download azure sdk (http://azure.microsoft.com/en-us/downloads/)