SALES: 1-800-867-1380

NetTcpRelayBinding Class

Provides a secure, reliable binding suitable for cross-computer communication.

Namespace:  Microsoft.ServiceBus
Assembly:  Microsoft.ServiceBus (in Microsoft.ServiceBus.dll)

public class NetTcpRelayBinding : NetTcpRelayBindingBase, 
	IBindingRuntimePreferences

The NetTcpRelayBinding type exposes the following members.

  NameDescription
Public methodNetTcpRelayBinding()Initializes a new instance of the NetTcpRelayBinding class.
Public methodNetTcpRelayBinding(String)Initializes a new instance of the NetTcpRelayBinding class with a specified XML configuration.
Public methodNetTcpRelayBinding(EndToEndSecurityMode, RelayClientAuthenticationType)Initializes a new instance of the NetTcpRelayBinding class with the type of security used and relay client authentication specified.
Public methodNetTcpRelayBinding(EndToEndSecurityMode, RelayClientAuthenticationType, Boolean)Initializes a new instance of the NetTcpRelayBinding class with the type of security used, the type of client authentication, and a value that indicates whether reliable sessions are explicitly enabled.
Protected methodNetTcpRelayBinding(TcpRelayTransportBindingElement, BinaryMessageEncodingBindingElement, ReliableSessionBindingElement, NetTcpRelaySecurity)Initializes a new instance of the NetTcpRelayBinding class using the specified transport, encoding, session information, and security settings.
Top

  NameDescription
Public propertyCloseTimeout (Inherited from Binding.)
Public propertyConnectionModeGets or sets the connection mode: Hybrid or Relayed. (Inherited from NetTcpRelayBindingBase.)
Public propertyEnvelopeVersionGets the version of SOAP that is used for messages processed by this binding. (Inherited from NetTcpRelayBindingBase.)
Public propertyHostNameComparisonModeGets or sets the comparison mode used on the hostname. (Inherited from NetTcpRelayBindingBase.)
Public propertyIsDynamicGets or sets whether the relay binding is dynamic. (Inherited from NetTcpRelayBindingBase.)
Public propertyListenBacklogGets or sets the maximum number of queued connection requests that can be pending. (Inherited from NetTcpRelayBindingBase.)
Public propertyMaxBufferPoolSizeGets or sets the maximum size allowed for a buffer pool that stores messages processed by the binding. (Inherited from NetTcpRelayBindingBase.)
Public propertyMaxBufferSizeGets or sets a value that specifies the maximum size of the buffer used to store messages in memory. (Inherited from NetTcpRelayBindingBase.)
Public propertyMaxConnectionsGets or sets a value that controls the maximum number of connections to be pooled for subsequent reuse on the client and the maximum number of connections allowed to be pending dispatch on the server. (Inherited from NetTcpRelayBindingBase.)
Public propertyMaxReceivedMessageSizeGets or sets the maximum size for a received message that is processed by the binding. (Inherited from NetTcpRelayBindingBase.)
Protected propertyMessageSecurityVersionGets the message security version. (Inherited from NetTcpRelayBindingBase.)
Public propertyMessageVersion (Inherited from Binding.)
Public propertyName (Inherited from Binding.)
Public propertyNamespace (Inherited from Binding.)
Public propertyOpenTimeout (Inherited from Binding.)
Public propertyReaderQuotasGets or sets constraints on the complexity of SOAP messages that can be processed by endpoints configured with this binding. This property cannot be null. (Inherited from NetTcpRelayBindingBase.)
Public propertyReceiveTimeout (Inherited from Binding.)
Public propertyReliableSessionGets an object that indicates whether a reliable session is established between Windows Azure Service Bus channel endpoints.
Public propertySchemeGets the URI scheme for the transport. (Inherited from NetTcpRelayBindingBase.)
Public propertySecurityGets an object that specifies the type of security used with services configured with this binding. (Inherited from NetTcpRelayBindingBase.)
Public propertySendTimeout (Inherited from Binding.)
Public propertyTransferModeGets or sets a value that indicates whether the service configured with the binding uses streamed or buffered (or both) modes of message transfer. (Inherited from NetTcpRelayBindingBase.)
Top

  NameDescription
Protected methodApplyConfigurationApplies the settings from the configuration element that corresponds to the specified name to the current instance of this binding element. (Overrides NetTcpRelayBindingBase.ApplyConfiguration(String).)
Public methodBuildChannelFactory<TChannel>(Object[]) (Inherited from Binding.)
Public methodBuildChannelFactory<TChannel>(BindingParameterCollection) (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Object[]) (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(BindingParameterCollection) (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Uri, Object[]) (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Uri, BindingParameterCollection) (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Uri, String, Object[]) (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Uri, String, BindingParameterCollection) (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Uri, String, ListenUriMode, Object[]) (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Uri, String, ListenUriMode, BindingParameterCollection) (Inherited from Binding.)
Public methodCanBuildChannelFactory<TChannel>(Object[]) (Inherited from Binding.)
Public methodCanBuildChannelFactory<TChannel>(BindingParameterCollection) (Inherited from Binding.)
Public methodCanBuildChannelListener<TChannel>(Object[]) (Inherited from Binding.)
Public methodCanBuildChannelListener<TChannel>(BindingParameterCollection) (Inherited from Binding.)
Public methodCreateBindingElementsCreates a collection with the binding elements for the binding. (Overrides NetTcpRelayBindingBase.CreateBindingElements().)
Protected methodCreateMessageSecurityCreates the message security token for the current instance. (Overrides NetTcpRelayBindingBase.CreateMessageSecurity().)
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetProperty<T> (Inherited from Binding.)
Public methodGetType (Inherited from Object.)
Protected methodIsBindingElementsMatch(TcpRelayTransportBindingElement, BinaryMessageEncodingBindingElement)Determines whether the specified binding elements match the default values of the binding elements in the current instance. (Inherited from NetTcpRelayBindingBase.)
Protected methodIsBindingElementsMatch(TcpRelayTransportBindingElement, BinaryMessageEncodingBindingElement, ReliableSessionBindingElement)Returns a value that determines whether the specified objects have matching binding elements.
Protected methodMemberwiseClone (Inherited from Object.)
Public methodShouldSerializeName (Inherited from Binding.)
Public methodShouldSerializeNamespace (Inherited from Binding.)
Public methodToString (Inherited from Object.)
Top

  NameDescription
Protected fieldencodingThe encoding element for the current instance. Along with the security and transport settings, the encoding forms the three core properties of a binding. (Inherited from NetTcpRelayBindingBase.)
Protected fieldtransportThe transport element for the current instance. Along with the encoding and security, the transport setting forms the core properties of a binding. (Inherited from NetTcpRelayBindingBase.)
Top

  NameDescription
Explicit interface implemetationPrivate propertyIBindingRuntimePreferences.ReceiveSynchronouslyGets a value that indicates whether incoming requests are handled synchronously or asynchronously. (Inherited from NetTcpRelayBindingBase.)
Top

Windows Azure Service Bus supports only Full Trust code access security.

NoteNote

By default, NetTcpRelayBinding uses Transport Security.

NetTcpRelayBinding supports two connection modes, specified by the ConnectionMode property: Hybrid and Relayed. In Hybrid connection mode, communication is relayed through the Service Bus infrastructure while the client and service endpoints negotiate a direct socket connection to each other. In Relayed mode, all communication is relayed through the Service Bus cloud.

The NetTcpRelayBinding generates a run-time communication stack by default, which uses transport security, TCP for message delivery, and a binary message encoding.

The default configuration for the NetTcpRelayBinding is faster than the configuration provided by the WSHttpRelayBinding. The security behavior is configurable using the optional securityMode parameter in the constructor. The use of WS-ReliableMessaging is configurable using the optional reliableSessionEnabled parameter. However, reliable messaging is disabled by default.

Services using the NetTcpRelayBinding register their endpoints on the Windows Azure Service Bus using the "sb" URI scheme. Clients and service listeners created using this binding each use a pair of TCP socket connections to the cloud-based listener. The SSL-protected control channel uses outbound TCP port 828, while the data channel is using outbound port 818.

Bindings are generally instantiated and configured at the beginning of both a service and client application, as they are a requirement for connecting to the Windows Azure Service Bus. For more information, see Building a Service for the AppFabric Service Bus, and Building an AppFabric Service Bus Client Application.

The following example shows how to define and use NetTcpRelayBinding with the default configuration for a service and client in an application configuration file.

<system.serviceModel>

  <bindings>
    <!-- Application Binding -->
    <netTcpRelayBinding>
      <binding name="default" />
    </netTcpRelayBinding>
  </bindings>

  <client>
    <endpoint name="RelayEndpoint"
              contract="Microsoft.ServiceBus.Samples.IMyContract"
              binding="netTcpRelayBinding"
              bindingConfiguration="default"
              behaviorConfiguration="ReplaceWithEndpointBehaviorName"
              address="ReplaceWithEndpointAddress" />
  </client>
  
  <services>
    <service name="Microsoft.ServiceBus.Samples.MyService">
      <!-- Keep address empty to use host base address, or -->
      <!-- replace with endpoint address. -->
      <endpoint name="RelayEndpoint"
                contract="Microsoft.ServiceBus.Samples.IMyContract"
                binding="netTcpRelayBinding"
                bindingConfiguration="default"                
                behaviorConfiguration="ReplaceWithEndpointBehaviorName"
                address="" />
    </service>
  </services>

  <behaviors>
    <endpointBehaviors>
      <!-- Add endpoint behavior here. -->
    </endpointBehaviors>
  </behaviors>

</system.serviceModel>

The following example is similar to the previous example except that it defines a custom configuration for NetTcpRelayBinding. It turns client authentication off, which means that the client is not required to present a security token to the Windows Azure Service Bus.

<system.serviceModel>

  <bindings>
    <!-- Application Binding -->
    <netTcpRelayBinding>
      <binding name="customBinding">
        <!-- Turn off client authentication -->
        <security relayClientAuthenticationType="None" />
    </netTcpRelayBinding>
  </bindings>

  <client>
    <!-- No behavior configuration is added to this endpoint as the client does not need to authenticate. -->
    <endpoint name="RelayEndpoint"
              contract="Microsoft.ServiceBus.Samples.IMyContract"
              binding="netTcpRelayBinding"
              bindingConfiguration="customBinding"
              address="ReplaceWithEndpointAddress" />
  </client>
  
  <services>
    <service name="Microsoft.ServiceBus.Samples.MyService">
      <!-- Keep address empty to use host base address, or -->
      <!-- replace with endpoint address. -->
      <endpoint name="RelayEndpoint"
                contract="Microsoft.ServiceBus.Samples.IMyContract"
                binding="netTcpRelayBinding"
                bindingConfiguration="customBinding"
                behaviorConfiguration="ReplaceWithEndpointBehaviorName"
                address="" />
    </service>
  </services>

  <behaviors>
    <endpointBehaviors>
      <!-- Add endpoint behavior here. -->
    </endpointBehaviors>
  </behaviors>

</system.serviceModel>

The following example illustrates the use of NetTcpRelayBinding programmatically with its default settings. The default settings of NetTcpRelayBinding for the end-to-end security mode and client authentication type are EndToEndSecurityMode.Transport and RelayClientAuthenticationType.RelayAccessToken respectively. For a complete working sample that uses the NetTcpRelayBinding, check out the samples in the SDK install directory under \Samples\ServiceBus\ExploringFeatures\Bindings\NetTcp.

This example starts by specifying the credentials the service and the client are expected to send to the Windows Azure Service Bus by creating an endpoint behavior. Next, it creates the binding, the service address, and starts the service host. After starting the service, a channel factory is created for the IMyChannel channel type that is used to generate a client channel to the service. Finally, the client channel is opened.

// Configure the credentials for the service and client endpoints through an endpoint behavior.
TransportClientEndpointBehavior relayCredentials = new TransportClientEndpointBehavior();
relayCredentials.CredentialType = TransportClientCredentialType.SharedSecret;
relayCredentials.Credentials.SharedSecret.IssuerName = issuerName;
relayCredentials.Credentials.SharedSecret.IssuerSecret = issuerSecret;

// Create the binding with default settings.
NetTcpRelayBinding binding = new NetTcpRelayBinding();        

// Get the service URI.
Uri serviceAddress = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace,
       String.Format(CultureInfo.InvariantCulture, "{0}/MyService/", session));

// Create the service host.
ServiceHost host = new ServiceHost(typeof(MyService), serviceAddress);
// Add the service endpoint with the NetTcpRelayBinding binding.
host.AddServiceEndpoint(typeof(IMyContract), binding, serviceAddress);
// Add the credentials through the endpoint behavior.
host.Description.Endpoints[0].Behaviors.Add(relayCredentials);
// Start the service.
host.Open();

// Create a channel factory for the specified channel type.
// This channel factory is used to create client channels to the service. 
// Each client channel the channel factory creates is configured to use the 
// NetTcpRelayBinding that is passed to the constructor of the channel factory.
ChannelFactory<IMyChannel> channelFactory = new ChannelFactory<IMyChannel>(
    binding, new EndpointAddress(serviceAddress));
channelFactory.Endpoint.Behaviors.Add(relayCredentials);

// Create and open the client channel.
IMyChannel channel = channelFactory.CreateChannel();
channel.Open();

The following example is similar to the previous example except that it uses NetTcpRelayBinding with custom settings. It turns off client authentication, which means that the client is not required to present a security token to the Windows Azure Service Bus. Since the client is not required to authenticate, no endpoint behavior for the credentials is added to the client channel. Note that the behavior is still added to the service endpoint because the service application always authenticates with the Windows Azure Service Bus.

// Configure the credentials for the service and client endpoints through an endpoint behavior.
TransportClientEndpointBehavior relayCredentials = new TransportClientEndpointBehavior();
relayCredentials.CredentialType = TransportClientCredentialType.SharedSecret;
relayCredentials.Credentials.SharedSecret.IssuerName = issuerName;
relayCredentials.Credentials.SharedSecret.IssuerSecret = issuerSecret;

// Create the binding with custom settings.
NetTcpRelayBinding binding = new NetTcpRelayBinding();        
// The client is not required to present a security token to the AppFabric Service Bus.
binding.Security.RelayClientAuthenticationType = RelayClientAuthenticationType.None;

// Get the service URI.
Uri serviceAddress = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace,
       String.Format(CultureInfo.InvariantCulture, "{0}/MyService/", session));

// Create the service host.
ServiceHost host = new ServiceHost(typeof(MyService), serviceAddress);
// Add the service endpoint with the NetTcpRelayBinding binding.
host.AddServiceEndpoint(typeof(IMyContract), binding, serviceAddress);
// Add the credentials through the endpoint behavior.
host.Description.Endpoints[0].Behaviors.Add(relayCredentials);
// Start the service.
host.Open();

// Create a channel factory for the specified channel type.
// This channel factory is used to create client channels to the service. 
// Each client channel the channel factory creates is configured to use the 
// NetTcpRelayBinding that is passed to the constructor of the channel factory.
ChannelFactory<IMyChannel> channelFactory = new ChannelFactory<IMyChannel>(
    binding, new EndpointAddress(serviceAddress));

// Create and open the client channel.
IMyChannel channel = channelFactory.CreateChannel();
channel.Open();

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft