Configuring a WCF Service to Register with the Service Bus
Configuring an application that uses the Windows Azure Service Bus requires that you set the following properties:
The name of the service you are exposing.
The interface (representing the service contract) your application either exposes or connects through.
The type of binding your application uses, which includes transport, security, and encoding settings.
The address at which the contract is available.
When using WCF you can set these properties in an WCF service or client application either programmatically or in an App.config file. However, it is usually best to specify the binding and address information declaratively in a configuration file, instead of imperatively in code unless your specific scenario requires it. Defining endpoints in code is usually not practical because the bindings and addresses for a deployed service are typically different from those used as the service is being developed. More generally, keeping the binding and addressing information out of the code enables them to change without having to recompile or redeploy the application.
Note that if you do not have the Windows Azure SDK installed on a particular computer the Machine.config file does not have the necessary extensions that enable the .NET run time to interpret Service Bus-specific information. While there are workarounds for this situation, it is usually easier to define your configuration in the code. (For more information about working to enable application configuration files, see the RelayConfigurationInstaller.exe Tool).
The following list contains the general scenarios for configuring an Service Bus application. For additional information about how to configure a WCF application, see Configuring Services in the WCF documentation.
This type of application is a WCF SOAP-based application that is configured to use the Service Bus as a secured relay to connect to other applications. The only differences required to use the Service Bus are the type of binding and the endpoint address. WCF applications that use the Service Bus use one of the relay bindings available in the Windows Azure SDK, bindings which have authentication and transport elements not present in the standard WCF bindings. Similarly, the endpoint address that is used for the service endpoint is an Service Bus URI based on the registered Service Bus namespace name (and may also have a different protocol scheme), whereas a regular WCF application uses an address based on the local host. Because these are the only two configuration differences, you can often – but not always – just reconfigure a currently existing WCF application to expose its services through the Service Bus
The topics in this documentation describe are two types of REST applications: those that use the WCF Web programming model and the Windows Azure SDK, and one that does not. However, the topics in this section only describe REST applications that use the Windows Azure SDK as a programming foundation. (REST-based applications that do not use the Windows Azure SDK can use the message buffer as a location to and from which to send and receive messages. For more information about about REST applications that use the message buffer, see Working with an AppFabric Service Bus Message Buffer.)
If your application does use the Windows Azure SDK, you can configure your application just as any other REST-based WCF service: you must use a relay binding that supports HTTP, such as WebHttpRelayBinding or WS2007HttpRelayBinding, and you must apply the appropriate WCF attributes to your interface, and confirm that your implementation can send and receive HTTP messages and events. For more information, see Designing a WCF Contract for the Service Bus.
Windows Azure-hosted Application
Because Windows Azure does not have the Windows Azure SDK installed it does not have the information necessary in its Machine.config file to identify configuration elements specific to Service Bus. If you must use an App.config file, you can include all of the necessary information into an App.config file by using the RelayConfigurationInstaller.exe Tool. However, whereas this enables you to use an App.config file together with Windows Azure, you may encounter duplication issues on your development computer. Therefore, we recommend that when you use Windows Azure, you configure your applications programmatically.
In addition, you must set your Windows Azure worker or Web role to Full Trust – this is required for all applications that use the Service Bus. This is not specified in the configuration file, but in the ServiceDefinition.csdef file. For more information, see How to: Configure a Windows Azure-Hosted Service Bus Service or Client Application.
In This Section