Problem

Recently, i have come across "Microsoft.ServiceBus.AuthorizationFailedException" exception that occurs when trying to run ServiceBus Relay samples included in Windows Azure AppFabric SDK or when following below tutorial

http://msdn.microsoft.com/en-us/library/windowsazure/ee706736.aspx

Symptoms

Encountering below exception when trying to follow Service Bus relay tutorial referred above or while running Service bus relay application included in SDK samples.

Microsoft.ServiceBus.AuthorizationFailedException was unhandled
  Message=Generic: There was an authorization failure. Make sure you have specified the correct SharedSecret, SimpleWebToken or Saml transport client credentials.

  Source=Microsoft.ServiceBus
  StackTrace:
       at Microsoft.ServiceBus.RelayedOnewayTcpClient.ConnectRequestReplyContext.Send(Message message, TimeSpan timeout, IDuplexChannel& channel)
       at Microsoft.ServiceBus.RelayedOnewayTcpListener.RelayedOnewayTcpListenerClient.Connect(TimeSpan timeout)
       at Microsoft.ServiceBus.RelayedOnewayTcpClient.EnsureConnected(TimeSpan timeout)
       at Microsoft.ServiceBus.RelayedOnewayTcpClient.OnOpen(TimeSpan timeout)
       at Microsoft.ServiceBus.Channels.CommunicationObject.Open(TimeSpan timeout)
       at Microsoft.ServiceBus.RelayedOnewayTcpListener.OnOpen(TimeSpan timeout)
       at Microsoft.ServiceBus.Channels.RefcountedCommunicationObject.Open(TimeSpan timeout)
       at Microsoft.ServiceBus.RelayedOnewayChannelListener.OnOpen(TimeSpan timeout)
       at Microsoft.ServiceBus.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at Microsoft.ServiceBus.RelayedSocketListener.Open(TimeSpan timeout)
       at Microsoft.ServiceBus.Channels.BufferedConnectionListener.Open(TimeSpan timeout)
       at Microsoft.ServiceBus.Channels.ConnectionAcceptor.Open(TimeSpan timeout)
       at Microsoft.ServiceBus.Channels.ConnectionDemuxer.StartDemuxing(TimeSpan timeout, OnViaDelegate viaDelegate)
       at Microsoft.ServiceBus.Channels.ConnectionDemuxer.Open(TimeSpan timeout)
       at Microsoft.ServiceBus.SocketConnectionTransportManager.OnOpen(TimeSpan timeout)
       at Microsoft.ServiceBus.Channels.TransportManager.Open(TimeSpan timeout, TransportChannelListener channelListener)
       at Microsoft.ServiceBus.Channels.TransportManagerContainer.Open(TimeSpan timeout, SelectTransportManagersCallback selectTransportManagerCallback)
       at Microsoft.ServiceBus.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
       at Microsoft.ServiceBus.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout)
       at Microsoft.ServiceBus.SocketConnectionChannelListener`2.OnOpen(TimeSpan timeout)
       at Microsoft.ServiceBus.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at Microsoft.ServiceBus.Samples.Program.Main(String[] args) in E:\Azure\AppFabric samples\ServiceBus\ExploringFeatures\RelayedMessaging\RelayAuthentication\SharedSecret\Service\Program.cs:line 41
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

Cause

Issue occured due to mismatch between the dll referenced and the configuration files. In my customer's case, version of Microsoft.ServiceBus.dll that is referenced is 1.6.0.0. However app.config has following entry that refers to 1.5.0.0 version of the dll

<bindingExtensions>
<add name="netTcpRelayBinding" type="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</bindingExtensions>

Resolution

Ensure the version of Microsoft.ServiceBus.dll is matching with the version specified in configuration files. In my customer's case, we have ensured that 1.6.0.0 vesrion of dll is referenced in the project and changed above highlighted version attribute to 1.6.0.0 to resolve the issue.

Note: It is possible that your service comes up fine , but clients are unable to connect to the service, resulting in same exception. If this happens, i would check the list below and ensure dll versions of referenced assemblies in both client, server are same and they are matching with references specified in configuration files of client, service.

  1. Version of Microsoft.ServiceBus.dll in the service project
  2. Version of Microsoft.ServiceBus.dll in the client project
  3. Any references to Microsoft.ServiceBus.dll  in service configuration
  4. Any references to Microsoft.ServiceBus.dll  in client configuration

 

Hope this helps! Comments are welcome :)

~Hari.