导出 (0) 打印
全部展开

BasicHttpRelayBinding 类

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

代表一个绑定,客户端可使用该绑定来配置终结点,以便与符合 WS-I Basic Profile 1.1 且基于 ASMX 的 Web 服务和其他服务通信。

System.Object
  System.ServiceModel.Channels.Binding
    Microsoft.ServiceBus.BasicHttpRelayBinding

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

public class BasicHttpRelayBinding : Binding, 
	IBindingRuntimePreferences

BasicHttpRelayBinding 类型公开以下成员。

  名称说明
公共方法BasicHttpRelayBinding()初始化 BasicHttpRelayBinding 类的新实例。
公共方法BasicHttpRelayBinding(String)使用指定的配置初始化 BasicHttpRelayBinding 类的新实例。
公共方法BasicHttpRelayBinding(EndToEndBasicHttpSecurityMode, RelayClientAuthenticationType)使用绑定所用的指定安全类型以及客户端所用的身份验证类型初始化 BasicHttpRelayBinding 类的新实例。
页首

  名称说明
公共属性AllowCookies获取或设置一个值,用于确定客户端是否允许 Cookie。
公共属性CloseTimeout (从 Binding 继承。)
公共属性EnvelopeVersion获取此绑定处理的消息所用的 SOAP 版本。
公共属性HostNameComparisonMode获取或设置主机名的比较方式。
公共属性IsDynamic获取或设置绑定元素是否为动态。
公共属性MaxBufferPoolSize获取或设置用于存储绑定处理的 TCP 消息的缓冲区池的最大允许大小。
公共属性MaxBufferSize获取或设置从通道接收消息的缓冲区的最大大小。
公共属性MaxReceivedMessageSize获取或设置可在使用此绑定配置的通道上接收的消息的最大大小。
公共属性MessageEncoding获取或设置消息编码的类型。
公共属性MessageVersion (从 Binding 继承。)
公共属性Name (从 Binding 继承。)
公共属性Namespace (从 Binding 继承。)
公共属性OpenTimeout (从 Binding 继承。)
公共属性ProxyAddress获取或设置代理地址。
公共属性ReaderQuotas获取或设置阅读器配额。
公共属性ReceiveTimeout (从 Binding 继承。)
公共属性Scheme获取使用此绑定配置的通道和侦听器的 URI 传输方案。 (覆盖 Binding.Scheme。)
公共属性Security获取用于此绑定的安全绑定集合。
公共属性SendTimeout (从 Binding 继承。)
公共属性TextEncoding获取或设置消息文本使用的字符编码。
公共属性TransferMode获取或设置传输模式。
公共属性UseDefaultWebProxy获取或设置一个值,用于确定客户端是否使用默认 Web 代理。
页首

  名称说明
公共方法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返回当前绑定中包含的绑定元素的有序集合。 (覆盖 Binding.CreateBindingElements()。)
公共方法Equals (从 Object 继承。)
受保护方法Finalize (从 Object 继承。)
公共方法GetHashCode (从 Object 继承。)
公共方法GetProperty<T> (从 Binding 继承。)
公共方法GetType (从 Object 继承。)
受保护方法MemberwiseClone (从 Object 继承。)
公共方法ShouldSerializeName (从 Binding 继承。)
公共方法ShouldSerializeNamespace (从 Binding 继承。)
公共方法ToString (从 Object 继承。)
页首

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

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

The BasicHttpRelayBinding is closely aligned with the standard BasicHttpBinding in the .NET Framework. The key difference between the standard BasicHttpBinding and the BasicHttpRelayBinding is that the latter creates publicly reachable and, if desired, publicly discoverable HTTP listener endpoint listening on the cloud-based Windows Azure Service Bus, while the standard binding listens through the standard HTTP.sys listener on the local Windows computer.

With its default settings, the BasicHttpRelayBinding supports SOAP 1.1 messaging conforming to the WS-I Basic profile 1.1.

Services using the BasicHttpRelayBinding register their endpoints on the Windows Azure Service Bus using the "http" or "https" URI scheme. Client channels created using the BasicHttpRelayBinding use HTTP/HTTPS on the default TCP ports 80 and 443 as the transport mechanism to talk to the respective endpoint in the Windows Azure Service Bus cloud. The data channel is SSL-protected if the endpoint URI scheme is "https" and the Security.Mode property is set to one of the EndToEndBasicHttpSecurityMode values: Transport or TransportWithMessageCredential.

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

<system.serviceModel>

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

  <client>
    <!-- Application Endpoint -->
    <endpoint name="RelayEndpoint"
              contract="Microsoft.ServiceBus.Samples.IMyContract"
              binding="basicHttpRelayBinding"
              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="basicHttpRelayBinding" 
                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 BasicHttpRelayBinding. It turns off the security mode and client authentication, which means that SOAP messages are sent unsecured and that the client is not required to present a security token to the Windows Azure Service Bus.

<system.serviceModel>

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

  <client>
    <!-- Application Endpoint -->
    <!-- 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="basicHttpRelayBinding"
              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="basicHttpRelayBinding" 
                bindingConfiguration="customBinding"
                behaviorConfiguration="ReplaceWithEndpointBehaviorName"
                address="" />
    </service>
  </services>

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

</system.serviceModel>

The following example illustrates the use of BasicHttpRelayBinding programmatically with its default settings. The default settings of BasicHttpRelayBinding for the end-to-end security mode and client authentication type are EndToEndSecurityMode.Transport and RelayClientAuthenticationType.RelayAccessToken respectively.

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 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.
BasicHttpRelayBinding binding = new BasicHttpRelayBinding();

// Get the service address.
// Use the https scheme because by default the binding uses SSL for transport security.
Uri address = ServiceBusEnvironment.CreateServiceUri("https", serviceNamespace, "MyService");

// Create the service host.
ServiceHost host = new ServiceHost(typeof(MyService), address);
// Add the service endpoint with the BasicHttpRelayBinding.
host.AddServiceEndpoint(typeof(IMyContract), binding, address);
// 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 
// BasicHttpRelayBinding that is passed to the constructor of the channel. factory.ChannelFactory<IMyChannel> channelFactory = new ChannelFactory<IMyChannel>(
    binding, new EndpointAddress(address));
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 BasicHttpRelayBinding with custom settings. It turns off the SSL security mode and client authentication, which means that SOAP messages are sent unsecured and that the client is not required to present a security token to the Windows Azure Service Bus. Because SSL is turned off, the http scheme is used in the service address. Also, 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 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.
BasicHttpRelayBinding binding = new BasicHttpRelayBinding();
// SOAP messages are not SSL-protected.
binding.Security.Mode = EndToEndSecurityMode.None;
// The client is not required to present a security token to the
// AppFabric Service Bus.
binding.Security.RelayClientAuthenticationType = RelayClientAuthenticationType.None;

// Get the service address.
// Use the http scheme because SSL security is turned off in our binding.
Uri address = ServiceBusEnvironment.CreateServiceUri("http", serviceNamespace, "MyService");

// Create the service host.
ServiceHost host = new ServiceHost(typeof(MyService), address);
// Add the service endpoint with the BasicHttpRelayBinding.
host.AddServiceEndpoint(typeof(IMyContract), binding, address);
// 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.
// We do not add the endpoint behavior with the credentials to the channel 
// factory because client authentication is turned off in the binding used.
// This channel factory is used to create client channels to the service. 
// Each client channel the channel factory creates is configured to use the 
// BasicHttpRelayBinding that is passed to the constructor of the channel. factory.ChannelFactory<IMyChannel> channelFactory = new ChannelFactory<IMyChannel>(
    binding, new EndpointAddress(address));

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

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。不保证所有实例成员都是线程安全的。

社区附加资源

显示:
© 2015 Microsoft