销售电话: 1-800-867-1380

NetTcpRelayBinding 类

注:本页面内容可能不完全适用中国大陆地区运营的 Windows Azure服务。如要了解不同地区 Windows Azure 服务的差异, 请参考本网站.

提供适用于跨计算机通信的安全可靠绑定。

命名空间:  Microsoft.ServiceBus
程序集:  Microsoft.ServiceBus(在 Microsoft.ServiceBus.dll 中)

public class NetTcpRelayBinding : NetTcpRelayBindingBase, 
	IBindingRuntimePreferences

NetTcpRelayBinding 类型公开以下成员。

  名称说明
公共方法NetTcpRelayBinding()初始化 NetTcpRelayBinding 类的新实例。
公共方法NetTcpRelayBinding(String)使用指定的 XML 配置初始化 NetTcpRelayBinding 类的新实例。
公共方法NetTcpRelayBinding(EndToEndSecurityMode, RelayClientAuthenticationType)通过使用的安全类型和指定的中继客户端身份验证初始化 NetTcpRelayBinding 类的新实例。
公共方法NetTcpRelayBinding(EndToEndSecurityMode, RelayClientAuthenticationType, Boolean)通过使用的安全类型、客户端身份验证类型以及用于指示是否显式启用了可靠会话的值初始化 NetTcpRelayBinding 类的新实例。
受保护方法NetTcpRelayBinding(TcpRelayTransportBindingElement, BinaryMessageEncodingBindingElement, ReliableSessionBindingElement, NetTcpRelaySecurity)使用指定的传输、编码、会话信息和安全设置初始化 NetTcpRelayBinding 类的新实例。
页首

  名称说明
公共属性CloseTimeout (从 Binding 继承。)
公共属性ConnectionMode获取或设置连接模式:HybridRelayed (从 NetTcpRelayBindingBase 继承。)
公共属性EnvelopeVersion获取此绑定处理的消息所用的 SOAP 版本。 (从 NetTcpRelayBindingBase 继承。)
公共属性HostNameComparisonMode获取或设置主机名中使用的比较模式。 (从 NetTcpRelayBindingBase 继承。)
公共属性IsDynamic获取或设置中继绑定是否为动态。 (从 NetTcpRelayBindingBase 继承。)
公共属性ListenBacklog获取或设置可以挂起的最大排队连接请求数。 (从 NetTcpRelayBindingBase 继承。)
公共属性MaxBufferPoolSize获取或设置用于存储绑定处理的消息的缓冲区池的最大允许大小。 (从 NetTcpRelayBindingBase 继承。)
公共属性MaxBufferSize获取或设置一个值,用于指定在内存中存储消息所用的缓冲区的最大大小。 (从 NetTcpRelayBindingBase 继承。)
公共属性MaxConnections获取或设置一个值,用于控制要进行集区以便将来在客户端上重复使用的最大连接数,以及允许在服务器上等待调度的最大连接数。 (从 NetTcpRelayBindingBase 继承。)
公共属性MaxReceivedMessageSize获取或设置绑定处理的已接收消息的最大大小。 (从 NetTcpRelayBindingBase 继承。)
受保护属性MessageSecurityVersion获取消息安全性版本。 (从 NetTcpRelayBindingBase 继承。)
公共属性MessageVersion (从 Binding 继承。)
公共属性Name (从 Binding 继承。)
公共属性Namespace (从 Binding 继承。)
公共属性OpenTimeout (从 Binding 继承。)
公共属性ReaderQuotas获取或设置使用此绑定配置的终结点可处理的 SOAP 消息的复杂性限制。此属性不能为 null (从 NetTcpRelayBindingBase 继承。)
公共属性ReceiveTimeout (从 Binding 继承。)
公共属性ReliableSession获取一个对象,用于指示是否在 Windows Azure Service Bus 通道终结点之间建立了可靠会话。
公共属性Scheme获取传输的 URI 方案。 (从 NetTcpRelayBindingBase 继承。)
公共属性Security获取一个指定了安全类型的对象,该安全类型可用于通过此绑定配置的服务。 (从 NetTcpRelayBindingBase 继承。)
公共属性SendTimeout (从 Binding 继承。)
公共属性TransferMode获取或设置一个值,用于指示通过绑定配置的服务是否使用消息传输的流式模式和/或缓冲模式。 (从 NetTcpRelayBindingBase 继承。)
页首

  名称说明
受保护方法ApplyConfiguration将指定名称的相应配置元素中的设置应用到此绑定元素的当前实例。 (覆盖 NetTcpRelayBindingBase.ApplyConfiguration(String)。)
公共方法BuildChannelFactory<TChannel>(Object[]) (从 Binding 继承。)
公共方法BuildChannelFactory<TChannel>(BindingParameterCollection) (从 Binding 继承。)
公共方法BuildChannelListener<TChannel>(Object[]) (从 Binding 继承。)
公共方法BuildChannelListener<TChannel>(BindingParameterCollection) (从 Binding 继承。)
公共方法BuildChannelListener<TChannel>(Uri, Object[]) (从 Binding 继承。)
公共方法BuildChannelListener<TChannel>(Uri, BindingParameterCollection) (从 Binding 继承。)
公共方法BuildChannelListener<TChannel>(Uri, String, Object[]) (从 Binding 继承。)
公共方法BuildChannelListener<TChannel>(Uri, String, BindingParameterCollection) (从 Binding 继承。)
公共方法BuildChannelListener<TChannel>(Uri, String, ListenUriMode, Object[]) (从 Binding 继承。)
公共方法BuildChannelListener<TChannel>(Uri, String, ListenUriMode, BindingParameterCollection) (从 Binding 继承。)
公共方法CanBuildChannelFactory<TChannel>(Object[]) (从 Binding 继承。)
公共方法CanBuildChannelFactory<TChannel>(BindingParameterCollection) (从 Binding 继承。)
公共方法CanBuildChannelListener<TChannel>(Object[]) (从 Binding 继承。)
公共方法CanBuildChannelListener<TChannel>(BindingParameterCollection) (从 Binding 继承。)
公共方法CreateBindingElements使用绑定的绑定元素创建集合。 (覆盖 NetTcpRelayBindingBase.CreateBindingElements()。)
受保护方法CreateMessageSecurity为当前实例创建消息安全令牌。 (覆盖 NetTcpRelayBindingBase.CreateMessageSecurity()。)
公共方法Equals (从 Object 继承。)
受保护方法Finalize (从 Object 继承。)
公共方法GetHashCode (从 Object 继承。)
公共方法GetProperty<T> (从 Binding 继承。)
公共方法GetType (从 Object 继承。)
受保护方法IsBindingElementsMatch(TcpRelayTransportBindingElement, BinaryMessageEncodingBindingElement)确定指定的绑定元素是否与当前实例中绑定元素的默认值匹配。 (从 NetTcpRelayBindingBase 继承。)
受保护方法IsBindingElementsMatch(TcpRelayTransportBindingElement, BinaryMessageEncodingBindingElement, ReliableSessionBindingElement)返回一个值,用于确定指定的对象是否具有匹配的绑定元素。
受保护方法MemberwiseClone (从 Object 继承。)
公共方法ShouldSerializeName (从 Binding 继承。)
公共方法ShouldSerializeNamespace (从 Binding 继承。)
公共方法ToString (从 Object 继承。)
页首

  名称说明
受保护字段encoding当前实例的编码元素。编码与安全设置和传输设置共同构成了绑定的三个核心属性。 (从 NetTcpRelayBindingBase 继承。)
受保护字段transport当前实例的传输元素。传输设置与编码和安全性共同构成了绑定的三个核心属性。 (从 NetTcpRelayBindingBase 继承。)
页首

  名称说明
显式接口实现私有属性IBindingRuntimePreferences.ReceiveSynchronously获取一个值,用于指示是以同步方式还是异步方式处理传入请求。 (从 NetTcpRelayBindingBase 继承。)
页首

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

注意注意

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();

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。不保证所有实例成员都是线程安全的。
本文是否对您有所帮助?
(1500 个剩余字符)
感谢您的反馈

社区附加资源

添加
Microsoft 正在进行一项网上调查,以了解您对 MSDN 网站的意见。 如果您选择参加,我们将会在您离开 MSDN 网站时向您显示该网上调查。

是否要参加?
显示:
© 2015 Microsoft