I've tried the msdn sample code (http://code.msdn.microsoft.com/windowsazure/Relayed-Messaging-Bindings-ca039161) and have the same issue I've encountered in my own test application. I have an example that works fine in Relay mode, but as soon as I switch to Hybrid the client fails to connect to the server with a timeout exception. I've upped the timeouts and switched on tracing but all the trace shows is a bunch of warnings, e.g.
Failed to open Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel
Failed to open Microsoft.ServiceBus.SocketConnectionChannelFactory`1+DuplexSessionChannel[System.ServiceModel.Channels.IDuplexSessionChannel]
I've tried settings the system connectivity mode environment setting between Tcp, Http and AutoDetect with no success.
Code for server:
ServiceHost sh = new ServiceHost(typeof(Service1));
var uri = ServiceBusEnvironment.CreateServiceUri("sb", "<serverNamespace>", "testing");
var binding = new NetTcpRelayBinding();
binding.ConnectionMode = TcpRelayConnectionMode.Hybrid;
binding.Security.Mode = EndToEndSecurityMode.None;
binding.OpenTimeout = new TimeSpan(0,0,10,0);
binding.ReceiveTimeout = new TimeSpan(0, 0, 10, 0);
binding.SendTimeout = new TimeSpan(0, 0, 10, 0);
sh.AddServiceEndpoint(
typeof(IService1), new NetTcpRelayBinding(), uri
)
.Behaviors.Add(new TransportClientEndpointBehavior
{
TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("<keyName>", "<sharedaccesskey>")
});
sh.Open();
Console.WriteLine("Press ENTER to close");
Console.ReadLine();
sh.Close();
Code for client:
var binding = new NetTcpRelayBinding {ConnectionMode = TcpRelayConnectionMode.Hybrid};
binding.Security.Mode = EndToEndSecurityMode.None;
binding.OpenTimeout = new TimeSpan(0, 0, 10, 0);
binding.ReceiveTimeout = new TimeSpan(0, 0, 10, 0);
binding.SendTimeout = new TimeSpan(0, 0, 10, 0);
binding.CloseTimeout = new TimeSpan(0, 0, 10, 0);
var cf = new ChannelFactory<IService1>(
binding,
new EndpointAddress(
ServiceBusEnvironment.CreateServiceUri("sb", "<serviceNamespace>", "testing")
));
cf.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior
{
TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("<keyName>", "<sharedAccessKey>")
});
var ch = cf.CreateChannel();
((ICommunicationObject)ch).Open();
Console.WriteLine(ch.GetData(5));
Console.ReadLine();
Thanks for reading,
Robin