This topic has not yet been rated - Rate this topic

WebHttpRelayBinding Class

A binding used to configure endpoints for Web services that are exposed through HTTP requests instead of SOAP messages.

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

Namespace:  Microsoft.ServiceBus
Assembly:  Microsoft.ServiceBus (in Microsoft.ServiceBus.dll)
public class WebHttpRelayBinding : Binding, 
	IBindingRuntimePreferences

The WebHttpRelayBinding type exposes the following members.

  Name Description
Public method WebHttpRelayBinding() Initializes a new instance of the WebHttpRelayBinding class.
Public method WebHttpRelayBinding(String) Initializes a new instance of the WebHttpRelayBinding class using the specified configuration name.
Public method WebHttpRelayBinding(EndToEndWebHttpSecurityMode, RelayClientAuthenticationType) Initializes a new instance of the WebHttpRelayBinding class using the specified type of security and relay client authentication.
Top
  Name Description
Public property AllowCookies Gets or sets a value that specifies whether cookies are allowed in the messages sent via the WebHttpRelayBinding.
Public property CloseTimeout (Inherited from Binding.)
Public property EnvelopeVersion Gets the SOAP envelope version.
Public property MaxBufferPoolSize Gets or sets the maximum buffer pool size used by the transport.
Public property MaxBufferSize Gets or sets the maximum buffer size supported by the transport.
Public property MaxReceivedMessageSize Gets or sets the maximum allowable message size that can be received.
Public property MessageVersion (Inherited from Binding.)
Public property Name (Inherited from Binding.)
Public property Namespace (Inherited from Binding.)
Public property OpenTimeout (Inherited from Binding.)
Public property ProxyAddress Gets or sets a URI that contains the address of the proxy to use for HTTP requests.
Public property ReaderQuotas Gets or sets xml reader quotas on the messages processed.
Public property ReceiveTimeout (Inherited from Binding.)
Public property Scheme Gets the scheme for the endpoints used with the binding. (Overrides Binding.Scheme.)
Public property Security Gets the security settings for the current instance.
Public property SendTimeout (Inherited from Binding.)
Public property TransferMode Gets or sets the transfer mode.
Public property UseDefaultWebProxy Gets or sets a value that indicates whether the machine-wide proxy settings are used rather than the user specific settings.
Public property WriteEncoding Gets or sets the character encoding that is used to write the message text.
Top
  Name Description
Public method BuildChannelFactory<TChannel>(Object[]) (Inherited from Binding.)
Public method BuildChannelFactory<TChannel>(BindingParameterCollection) (Inherited from Binding.)
Public method BuildChannelListener<TChannel>(Object[]) (Inherited from Binding.)
Public method BuildChannelListener<TChannel>(BindingParameterCollection) (Inherited from Binding.)
Public method BuildChannelListener<TChannel>(Uri, Object[]) (Inherited from Binding.)
Public method BuildChannelListener<TChannel>(Uri, BindingParameterCollection) (Inherited from Binding.)
Public method BuildChannelListener<TChannel>(Uri, String, Object[]) (Inherited from Binding.)
Public method BuildChannelListener<TChannel>(Uri, String, BindingParameterCollection) (Inherited from Binding.)
Public method BuildChannelListener<TChannel>(Uri, String, ListenUriMode, Object[]) (Inherited from Binding.)
Public method BuildChannelListener<TChannel>(Uri, String, ListenUriMode, BindingParameterCollection) (Inherited from Binding.)
Public method CanBuildChannelFactory<TChannel>(Object[]) (Inherited from Binding.)
Public method CanBuildChannelFactory<TChannel>(BindingParameterCollection) (Inherited from Binding.)
Public method CanBuildChannelListener<TChannel>(Object[]) (Inherited from Binding.)
Public method CanBuildChannelListener<TChannel>(BindingParameterCollection) (Inherited from Binding.)
Public method CreateBindingElements Creates a collection with the binding elements for the binding. (Overrides Binding.CreateBindingElements().)
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetProperty<T> (Inherited from Binding.)
Public method GetType (Inherited from Object.)
Protected method MemberwiseClone (Inherited from Object.)
Public method ShouldSerializeName (Inherited from Binding.)
Public method ShouldSerializeNamespace (Inherited from Binding.)
Public method ToString (Inherited from Object.)
Top
  Name Description
Explicit interface implemetation Private property IBindingRuntimePreferences.ReceiveSynchronously Gets a value that indicates whether incoming requests are handled synchronously or asynchronously.
Top

The WebHttpRelayBinding is ideal for integrating simple non-WCF clients with Service Bus endpoints because it exposes REST endpoints for web services. Therefore, any client capable of REST-ful communication can interact with services (listeners) hosted in the Service Bus via the WebHttpRelayBinding. However, if more sophisticated security and reliability features are required, then WS2007HttpRelayBinding would be more appropriate.

The following example shows how to define and use WebHttpRelayBinding in an application configuration file. The binding in this example has client authentication turned off, which means that the client is not required to present a security token to the Service Bus.

<system.serviceModel>
  <bindings>
    <!-- Application Binding -->
    <webHttpRelayBinding>
      <binding name="customBinding">
        <!-- Turn off client authentication so that client does not need to present credential through browser or fiddler -->
        <security relayClientAuthenticationType="None" />
      </binding>
    </webHttpRelayBinding>
  </bindings>

  <services>
    <!-- Application Service -->
    <service name="Microsoft.ServiceBus.Samples.ImageService">
      <endpoint name="RelayEndpoint"
                contract="Microsoft.ServiceBus.Samples.IImageContract"
                binding="webHttpRelayBinding"
                bindingConfiguration="customBinding"
                behaviorConfiguration="sharedSecretClientCredentials"
                address="" />
    </service>
  </services>

  <behaviors>
    <!-- Specify service and endpoint behaviors here. -->
  </behaviors>

</system.serviceModel>

The following example illustrates the use of WebHttpRelayBinding programmatically with custom settings. The custom binding has client authentication turned off, which means that the client is not required to present a security token to the Service Bus. This example is a modified version of the WebHttp SDK sample, which specifies the binding for the service endpoint programmatically instead of specifying it in the application configuration file. The WebHttp SDK sample can be found in the SDK install directory under \Samples\ServiceBus\ExploringFeatures\Bindings\WebHttp.

This example starts by specifying the credentials the service application is expected to send to the Service Bus by creating an endpoint behavior. Next, it creates the binding, the service address, and starts the web service host. After starting the web service, the user can use a browser to get the image that the service exposes at the specified URL.

// 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.
WebHttpRelayBinding binding = new WebHttpRelayBinding();
binding.Security.RelayClientAuthenticationType = RelayClientAuthenticationType.None;

// Get the service URI.
Uri address = ServiceBusEnvironment.CreateServiceUri("https", serviceNamespace, "Image");

// Create the web service host.
WebServiceHost host = new WebServiceHost(typeof(ImageService), address);
// Add the service endpoint with the WebHttpRelayBinding binding.
host.AddServiceEndpoint(typeof(IImageContract), binding, address);
// Add the credentials through the endpoint behavior.
host.Description.Endpoints[0].Behaviors.Add(relayCredentials);
// Start the service.
host.Open();

Console.WriteLine("Copy the following address into a browser to see the image: ");
Console.WriteLine(address + "GetImage");
Console.WriteLine();
Console.WriteLine("Press [Enter] to exit");
Console.ReadLine();

host.Close();
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)