NetTcpRelayBinding Class
Provides a secure, reliable binding suitable for cross-computer communication.
System.ServiceModel.Channels.Binding
Microsoft.ServiceBus.NetTcpRelayBindingBase
Microsoft.ServiceBus.NetTcpRelayBinding
Namespace: Microsoft.ServiceBus
Assembly: Microsoft.ServiceBus (in Microsoft.ServiceBus.dll)
The NetTcpRelayBinding type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | NetTcpRelayBinding() | Initializes a new instance of the NetTcpRelayBinding class. |
![]() | NetTcpRelayBinding(String) | Initializes a new instance of the NetTcpRelayBinding class with a specified XML configuration. |
![]() | NetTcpRelayBinding(EndToEndSecurityMode, RelayClientAuthenticationType) | Initializes a new instance of the NetTcpRelayBinding class with the type of security used and relay client authentication specified. |
![]() | NetTcpRelayBinding(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. |
![]() | NetTcpRelayBinding(TcpRelayTransportBindingElement, BinaryMessageEncodingBindingElement, ReliableSessionBindingElement, NetTcpRelaySecurity) | Initializes a new instance of the NetTcpRelayBinding class using the specified transport, encoding, session information, and security settings. |
| Name | Description | |
|---|---|---|
![]() | CloseTimeout | (Inherited from Binding.) |
![]() | ConnectionMode | Gets or sets the connection mode: Hybrid or Relayed. (Inherited from NetTcpRelayBindingBase.) |
![]() | EnvelopeVersion | Gets the version of SOAP that is used for messages processed by this binding. (Inherited from NetTcpRelayBindingBase.) |
![]() | ListenBacklog | Gets or sets the maximum number of queued connection requests that can be pending. (Inherited from NetTcpRelayBindingBase.) |
![]() | MaxBufferPoolSize | Gets or sets the maximum size allowed for a buffer pool that stores messages processed by the binding. (Inherited from NetTcpRelayBindingBase.) |
![]() | MaxBufferSize | Gets or sets a value that specifies the maximum size of the buffer used to store messages in memory. (Inherited from NetTcpRelayBindingBase.) |
![]() | MaxConnections | 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.) |
![]() | MaxReceivedMessageSize | Gets or sets the maximum size for a received message that is processed by the binding. (Inherited from NetTcpRelayBindingBase.) |
![]() | MessageSecurityVersion | Gets the message security version. (Inherited from NetTcpRelayBindingBase.) |
![]() | MessageVersion | (Inherited from Binding.) |
![]() | Name | (Inherited from Binding.) |
![]() | Namespace | (Inherited from Binding.) |
![]() | OpenTimeout | (Inherited from Binding.) |
![]() | ReaderQuotas | 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.) |
![]() | ReceiveTimeout | (Inherited from Binding.) |
![]() | ReliableSession | Gets an object that indicates whether a reliable session is established between Windows Azure Service Bus channel endpoints. |
![]() | Scheme | Gets the URI scheme for the transport. (Inherited from NetTcpRelayBindingBase.) |
![]() | Security | Gets an object that specifies the type of security used with services configured with this binding. (Inherited from NetTcpRelayBindingBase.) |
![]() | SendTimeout | (Inherited from Binding.) |
![]() | TransferMode | 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.) |
| Name | Description | |
|---|---|---|
![]() | encoding | 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.) |
![]() | transport | 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.) |
| Name | Description | |
|---|---|---|
![]() ![]() | IBindingRuntimePreferences.ReceiveSynchronously | Gets a value that indicates whether incoming requests are handled synchronously or asynchronously. (Inherited from NetTcpRelayBindingBase.) |
Windows Azure Service Bus supports only Full Trust code access security.
Note |
|---|
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();

