Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
NetTcpRelayBinding Class
Collapse the table of content
Expand the table of content

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

NameDescription
System_CAPS_pubmethodNetTcpRelayBinding()

Initializes a new instance of the NetTcpRelayBinding class.

System_CAPS_pubmethodNetTcpRelayBinding(EndToEndSecurityMode, RelayClientAuthenticationType)

Initializes a new instance of the NetTcpRelayBinding class with the type of security used and relay client authentication specified.

System_CAPS_pubmethodNetTcpRelayBinding(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.

System_CAPS_pubmethodNetTcpRelayBinding(String)

Initializes a new instance of the NetTcpRelayBinding class with a specified XML configuration.

System_CAPS_protmethodNetTcpRelayBinding(TcpRelayTransportBindingElement, BinaryMessageEncodingBindingElement, ReliableSessionBindingElement, NetTcpRelaySecurity)

Initializes a new instance of the NetTcpRelayBinding class using the specified transport, encoding, session information, and security settings.

NameDescription
System_CAPS_pubpropertyCloseTimeout

(Inherited from Binding.)

System_CAPS_pubpropertyConnectionMode

Gets or sets the connection mode: Hybrid or Relayed.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_pubpropertyEnvelopeVersion

Gets the version of SOAP that is used for messages processed by this binding.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_pubpropertyHostNameComparisonMode

Gets or sets the comparison mode used on the hostname.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_pubpropertyIsDynamic

Gets or sets whether the relay binding is dynamic.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_pubpropertyListenBacklog

Gets or sets the maximum number of queued connection requests that can be pending.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_pubpropertyMaxBufferPoolSize

Gets or sets the maximum size allowed for a buffer pool that stores messages processed by the binding.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_pubpropertyMaxBufferSize

Gets or sets a value that specifies the maximum size of the buffer used to store messages in memory.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_pubpropertyMaxConnections

Gets 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.)

System_CAPS_pubpropertyMaxReceivedMessageSize

Gets or sets the maximum size for a received message that is processed by the binding.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_protpropertyMessageSecurityVersion

Gets the message security version.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_pubpropertyMessageVersion

(Inherited from Binding.)

System_CAPS_pubpropertyName

(Inherited from Binding.)

System_CAPS_pubpropertyNamespace

(Inherited from Binding.)

System_CAPS_pubpropertyOpenTimeout

(Inherited from Binding.)

System_CAPS_pubpropertyReaderQuotas

Gets 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.)

System_CAPS_pubpropertyReceiveTimeout

(Inherited from Binding.)

System_CAPS_pubpropertyReliableSession

Gets an object that indicates whether a reliable session is established between Windows Azure Service Bus channel endpoints.

System_CAPS_pubpropertyScheme

Gets the URI scheme for the transport.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_pubpropertySecurity

Gets an object that specifies the type of security used with services configured with this binding.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_pubpropertySendTimeout

(Inherited from Binding.)

System_CAPS_pubpropertyTransferMode

Gets 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.)

NameDescription
System_CAPS_protmethodApplyConfiguration(String)

Applies the settings from the configuration element that corresponds to the specified name to the current instance of this binding element.(Overrides NetTcpRelayBindingBase.ApplyConfiguration(String).)

System_CAPS_pubmethodBuildChannelFactory<TChannel>(BindingParameterCollection)

(Inherited from Binding.)

System_CAPS_pubmethodBuildChannelFactory<TChannel>(Object[])

(Inherited from Binding.)

System_CAPS_pubmethodBuildChannelListener<TChannel>(BindingParameterCollection)

(Inherited from Binding.)

System_CAPS_pubmethodBuildChannelListener<TChannel>(Object[])

(Inherited from Binding.)

System_CAPS_pubmethodBuildChannelListener<TChannel>(Uri, BindingParameterCollection)

(Inherited from Binding.)

System_CAPS_pubmethodBuildChannelListener<TChannel>(Uri, Object[])

(Inherited from Binding.)

System_CAPS_pubmethodBuildChannelListener<TChannel>(Uri, String, BindingParameterCollection)

(Inherited from Binding.)

System_CAPS_pubmethodBuildChannelListener<TChannel>(Uri, String, ListenUriMode, BindingParameterCollection)

(Inherited from Binding.)

System_CAPS_pubmethodBuildChannelListener<TChannel>(Uri, String, ListenUriMode, Object[])

(Inherited from Binding.)

System_CAPS_pubmethodBuildChannelListener<TChannel>(Uri, String, Object[])

(Inherited from Binding.)

System_CAPS_pubmethodCanBuildChannelFactory<TChannel>(BindingParameterCollection)

(Inherited from Binding.)

System_CAPS_pubmethodCanBuildChannelFactory<TChannel>(Object[])

(Inherited from Binding.)

System_CAPS_pubmethodCanBuildChannelListener<TChannel>(BindingParameterCollection)

(Inherited from Binding.)

System_CAPS_pubmethodCanBuildChannelListener<TChannel>(Object[])

(Inherited from Binding.)

System_CAPS_pubmethodCreateBindingElements()

Creates a collection with the binding elements for the binding. (Overrides NetTcpRelayBindingBase.CreateBindingElements().)

System_CAPS_protmethodCreateMessageSecurity()

Creates the message security token for the current instance. (Overrides NetTcpRelayBindingBase.CreateMessageSecurity().)

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetProperty<T>(BindingParameterCollection)

(Inherited from Binding.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_protmethodIsBindingElementsMatch(TcpRelayTransportBindingElement, BinaryMessageEncodingBindingElement)

Determines whether the specified binding elements match the default values of the binding elements in the current instance.(Inherited from NetTcpRelayBindingBase.)

System_CAPS_protmethodIsBindingElementsMatch(TcpRelayTransportBindingElement, BinaryMessageEncodingBindingElement, ReliableSessionBindingElement)

Returns a value that determines whether the specified objects have matching binding elements.

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodToString()

(Inherited from Object.)

NameDescription
System_CAPS_protfieldencoding

The 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.)

System_CAPS_protfieldtransport

The 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.)

Service Bus supports only Full Trust code access security.

System_CAPS_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 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 Service Bus.

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 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, see the NetTcp Relayed sample.

This example starts by specifying the credentials the service and the client are expected to send to 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.TokenProvider = 
  TokenProvider.CreateSharedAccessSignatureTokenProvider(keyName, key);




// 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 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 Service Bus.

// Configure the credentials for the service and client endpoints through an endpoint behavior.
TransportClientEndpointBehavior relayCredentials = new TransportClientEndpointBehavior();
relayCredentials.TokenProvider = 
  TokenProvider.CreateSharedAccessSignatureTokenProvider(keyName, key);




// 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.

Return to top
Show:
© 2015 Microsoft