2

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

Rob
  • 663
  • 8
  • 8
  • Hi. This is a very old post, but did you find a solution? I am seeing the exact same problem whilst running the examples. – Mark W Mar 02 '17 at 10:30

1 Answers1

0

You need to set the OperationTimeout on the client created by the ChannelFactory:

    var ch = cf.CreateChannel();

    // Add this Line
    ch.OperationTimeout = new TimeSpan(0, 0, 10, 0);

    ((ICommunicationObject)ch).Open();
    Console.WriteLine(ch.GetData(5));
    Console.ReadLine();
Mark W
  • 705
  • 1
  • 9
  • 20