Export (0) Print
Expand All

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 extends Binding implements IBindingRuntimePreferences

The WebHttpRelayBinding type exposes the following members.

  NameDescription
Public methodWebHttpRelayBinding()Initializes a new instance of the WebHttpRelayBinding class.
Public methodWebHttpRelayBinding(String)Initializes a new instance of the WebHttpRelayBinding class using the specified configuration name.
Public methodWebHttpRelayBinding(EndToEndWebHttpSecurityMode, RelayClientAuthenticationType)Initializes a new instance of the WebHttpRelayBinding class using the specified type of security and relay client authentication.
Top

  NameDescription
Public propertyAllowCookiesGets or sets a value that specifies whether cookies are allowed in the messages sent via the WebHttpRelayBinding.
Public propertyCloseTimeout (Inherited from Binding.)
Public propertyContentTypeMapperGets or sets the content type mapper.
Public propertyEnvelopeVersionGets the SOAP envelope version.
Public propertyHostNameComparisonModeGets or sets the comparison mode used on the host name.
Public propertyIsDynamicGets or sets whether the relay binding is dynamic.
Public propertyMaxBufferPoolSizeGets or sets the maximum buffer pool size used by the transport.
Public propertyMaxBufferSizeGets or sets the maximum buffer size supported by the transport.
Public propertyMaxReceivedMessageSizeGets or sets the maximum allowable message size that can be received.
Public propertyMessageVersion (Inherited from Binding.)
Public propertyName (Inherited from Binding.)
Public propertyNamespace (Inherited from Binding.)
Public propertyOpenTimeout (Inherited from Binding.)
Public propertyProxyAddressGets or sets a URI that contains the address of the proxy to use for HTTP requests.
Public propertyReaderQuotasGets or sets xml reader quotas on the messages processed.
Public propertyReceiveTimeout (Inherited from Binding.)
Public propertySchemeGets the scheme for the endpoints used with the binding. (Overrides Binding.Scheme.)
Public propertySecurityGets the security settings for the current instance.
Public propertySendTimeout (Inherited from Binding.)
Public propertyTransferModeGets or sets the transfer mode.
Public propertyUseDefaultWebProxyGets or sets a value that indicates whether the machine-wide proxy settings are used rather than the user specific settings.
Public propertyWriteEncodingGets or sets the character encoding that is used to write the message text.
Top

  NameDescription
Public methodBuildChannelFactory(TChannel)(Object[]) (Inherited from Binding.)
Public methodBuildChannelFactory(TChannel)(BindingParameterCollection) (Inherited from Binding.)
Public methodBuildChannelListener(TChannel)(Object[]) (Inherited from Binding.)
Public methodBuildChannelListener(TChannel)(BindingParameterCollection) (Inherited from Binding.)
Public methodBuildChannelListener(TChannel)(Uri, Object[]) (Inherited from Binding.)
Public methodBuildChannelListener(TChannel)(Uri, BindingParameterCollection) (Inherited from Binding.)
Public methodBuildChannelListener(TChannel)(Uri, String, Object[]) (Inherited from Binding.)
Public methodBuildChannelListener(TChannel)(Uri, String, BindingParameterCollection) (Inherited from Binding.)
Public methodBuildChannelListener(TChannel)(Uri, String, ListenUriMode, Object[]) (Inherited from Binding.)
Public methodBuildChannelListener(TChannel)(Uri, String, ListenUriMode, BindingParameterCollection) (Inherited from Binding.)
Public methodCanBuildChannelFactory(TChannel)(Object[]) (Inherited from Binding.)
Public methodCanBuildChannelFactory(TChannel)(BindingParameterCollection) (Inherited from Binding.)
Public methodCanBuildChannelListener(TChannel)(Object[]) (Inherited from Binding.)
Public methodCanBuildChannelListener(TChannel)(BindingParameterCollection) (Inherited from Binding.)
Public methodCreateBindingElementsCreates a collection with the binding elements for the binding. (Overrides Binding.CreateBindingElements().)
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetProperty(T) (Inherited from Binding.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodShouldSerializeName (Inherited from Binding.)
Public methodShouldSerializeNamespace (Inherited from Binding.)
Public methodToString (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate propertyIBindingRuntimePreferences.ReceiveSynchronouslyGets 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 Windows Azure 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 Windows Azure 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 Windows Azure 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.

Community Additions

ADD
Show:
© 2014 Microsoft