Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

How to: Change the Connection Mode

Updated: May 18, 2015

The connection mode defines how a Service Bus application connects to other applications when it uses a TCP connection: either Relayed or Hybrid:

The connection mode is defined by the Microsoft.ServiceBus.TcpRelayConnectionMode enumeration, which is in turn used by Microsoft.ServiceBus.TcpRelayTransportBindingElement to define the NetTcpRelayBinding binding. Therefore, you can set the connection mode for a NetTcpRelayBinding binding by setting the Microsoft.ServiceBus.NetTcpRelayBindingBase.ConnectionMode property. You can do this at any time in your application: Service Bus will take the change and attempt to modify the connection. As with most properties, you can decide to set the connection status in the App.config file. Finally, Service Bus exposes the current status of the connection through the IHybridConnectionStatus interface, which you can decide to implement.

The following topic describes how to determine or modify the mode of a Service Bus application.

  1. Create the binding, and then set the property.

    NetTcpRelayBinding myTcpBinding = new NetTcpRelayBinding();
    myTcpBinding.ConnectionMode = TcpRelayConnectionMode.Hybrid;
    

  1. Open the application configuration file for the client application, as in the following example.

    <bindings>
      <netTcpRelayBinding>
        <binding name="default"/>
      </netTcpRelayBinding>
    </bindings>
    
    

    Note that the netTcpRelayBinding tag does not specify the connection mode attribute. By default, the connection mode used is Relayed.

  2. Explicitly change the connection mode to Hybrid by adding the Microsoft.ServiceBus.NetTcpRelayBindingBase.ConnectionMode field, which is set to Hybrid.

    <bindings>
      <netTcpRelayBinding>
        <binding name="default" connectionMode="Hybrid">
          <security mode="None" />
        </binding>
      </netTcpRelayBinding>  
    </bindings>
    
    

  1. Optionally, you might want to receive a notification when the connection between the connected endpoints changes from a Relayed connection to a Hybrid connection.

    channel.Open();
    
    IHybridConnectionStatus hybridConnectionStatus = channel.GetProperty<IHybridConnectionStatus>();
    if (hybridConnectionStatus != null)
    {
        hybridConnectionStatus.ConnectionStateChanged += (o, e) =>
        {
            Console.WriteLine("Connection state changed to: {0}.", e.ConnectionState);
        };
    }
    
    Console.WriteLine("Enter text to echo (or [Enter] to exit):");
    
    

Show:
© 2015 Microsoft