匯出 (0) 列印
全部展開

NetTcpRelayBinding 類別

提供適合用於跨電腦通訊之安全、可靠的繫結。

命名空間:  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。)
公用屬性IsDynamicGets or sets whether the relay binding is dynamic. (繼承自 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<(Of <<'(TChannel>)>>)(array<Object>[]()[][]) (繼承自 Binding。)
公用方法BuildChannelFactory<(Of <<'(TChannel>)>>)(BindingParameterCollection) (繼承自 Binding。)
公用方法BuildChannelListener<(Of <<'(TChannel>)>>)(array<Object>[]()[][]) (繼承自 Binding。)
公用方法BuildChannelListener<(Of <<'(TChannel>)>>)(BindingParameterCollection) (繼承自 Binding。)
公用方法BuildChannelListener<(Of <<'(TChannel>)>>)(Uri, array<Object>[]()[][]) (繼承自 Binding。)
公用方法BuildChannelListener<(Of <<'(TChannel>)>>)(Uri, BindingParameterCollection) (繼承自 Binding。)
公用方法BuildChannelListener<(Of <<'(TChannel>)>>)(Uri, String, array<Object>[]()[][]) (繼承自 Binding。)
公用方法BuildChannelListener<(Of <<'(TChannel>)>>)(Uri, String, BindingParameterCollection) (繼承自 Binding。)
公用方法BuildChannelListener<(Of <<'(TChannel>)>>)(Uri, String, ListenUriMode, array<Object>[]()[][]) (繼承自 Binding。)
公用方法BuildChannelListener<(Of <<'(TChannel>)>>)(Uri, String, ListenUriMode, BindingParameterCollection) (繼承自 Binding。)
公用方法CanBuildChannelFactory<(Of <<'(TChannel>)>>)(array<Object>[]()[][]) (繼承自 Binding。)
公用方法CanBuildChannelFactory<(Of <<'(TChannel>)>>)(BindingParameterCollection) (繼承自 Binding。)
公用方法CanBuildChannelListener<(Of <<'(TChannel>)>>)(array<Object>[]()[][]) (繼承自 Binding。)
公用方法CanBuildChannelListener<(Of <<'(TChannel>)>>)(BindingParameterCollection) (繼承自 Binding。)
公用方法CreateBindingElements利用繫結的繫結元素建立集合。 (覆寫 NetTcpRelayBindingBase..::..CreateBindingElements()()()()。)
受保護的方法CreateMessageSecurity建立目前執行個體的訊息安全性權杖。 (覆寫 NetTcpRelayBindingBase..::..CreateMessageSecurity()()()()。)
公用方法Equals (繼承自 Object。)
受保護的方法Finalize (繼承自 Object。)
公用方法GetHashCode (繼承自 Object。)
公用方法GetProperty<(Of <<'(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) 成員都是執行緒安全的。並不是所有的執行個體成員都保證可以用於所有的執行緒。

社群新增項目

新增
顯示:
© 2014 Microsoft