Azure Service Bus–working with the appfabriclabs account

So I have been playing with Azure Service Bus lately. I have created an Azure AppFabric Labs account for myself and this allows me to easily get started with and try Azure AppFabric services like Service Bus, Access Control Service and Cache for my sample applications.

When I started with my first basic Service Bus sample which simply creates a WCF service and registers itself to the Service Bus to enable the queue to listen for messages, I ran into couple of interesting issues which took a bit of online search time to figure out. I am describing the solution here in case anyone else finds themselves in the same shoes as mine.

First - I got the following error when I started my simple WCF service host. 

“The token provider was unable to provide a security token while accessing ' -sb.accesscontrol.windows.net/WRAPv0.9/'">-sb.accesscontrol.windows.net/WRAPv0.9/'">-sb.accesscontrol.windows.net/WRAPv0.9/'">-sb.accesscontrol.windows.net/WRAPv0.9/'">-sb.accesscontrol.windows.net/WRAPv0.9/'">-sb.accesscontrol.windows.net/WRAPv0.9/'">-sb.accesscontrol.windows.net/WRAPv0.9/'">-sb.accesscontrol.windows.net/WRAPv0.9/'">https://<myNamespace>-sb.accesscontrol.windows.net/WRAPv0.9/' . Token provider returned message: 'Unable to connect to the remote server'.”

I figured that this is because my service bus namespace is situated in labs environment. So I modified the code while creating the service address to replace the domain:

// Create the service uri based on service namespace Uri serviceAddress = ServiceBusEnvironment.CreateServiceUri ("sb", serviceNamespace, "MyEchoService");serviceAddress = new Uri(serviceAddress.ToString().Replace ("windows.net", "appfabriclabs.com"));

  

However, even after my above fix, the problem didn't go away and I ran into another error message:

uri provided <myNamespace>.servicebus.appfabriclabs.com does not match service bus domain: servicebus.windows.net

It turns out that the fix to redirect from servicebus.windows.net to servicebus.appfabriclabs.com environment is simple once you know it and there is no change in code required, not even correcting the service address bit I did above. All you need to do is to create an xml file named ServiceBus.xml with the following content in the …\Microsoft.Net\Framework(64)\<version>\Config directory:

<?xml version="1.0" encoding="utf-8"?> <!-- the root web configuration file -->
<configuration>
<Microsoft.ServiceBus>
<relayHostName>servicebus.appfabriclabs.com</relayHostName>
<stsHostName>accesscontrol.appfabriclabs.com</stsHostName>
<acmHostName>accesscontrol.appfabriclabs.com</acmHostName>
</Microsoft.ServiceBus>
</configuration>

More on this here - https://abhishekrlal.wordpress.com/2011/03/22/clientsdkconfig/.

There is a catch though – you should also check the “Platform target” setting of your application before deciding where to put this ServiceBus.config. If your application is set to AnyCPU, which is the default, then on a 64 bit machine you will put the above ServiceBus.config in the Framework64\…\Config directory otherwise in the Framework\…\Config directory. However if the Platform target is explicitly set, then you will need to place the file depending on the setting here – e.g. if Platform target is set to x86, then even on a 64 bit machine – above config file will go in the Framework\…\Config (and not Framework64\…\Config) directory.

 

image