How to: Configure a Service Bus Service Using a Configuration File
Once you have defined and implemented your Service Bus interface, you can configure the service. You can configure an Service Bus service programmatically or in an App.config file. Configuring your application in an App.config file lets you easily see what the configuration settings are, and let users easily modify the settings after deployment. Note that configuring an Service Bus application by using a configuration file is like configuring a Windows Communication Foundation (WCF) application, which is discussed in the topic Configuring Services Using Configuration Files, in the WCF documentation. Therefore,, the following discussion is a simplified overview of configuration techniques, with an emphasis on the unique features relevant to the Service Bus.
In addition to the issues discussed in Configuring a WCF Service to Register with the Service Bus, an Service Bus service must determine what type of authentication and transport security, if any, is required. Authentication security is the type of security necessary for a service to connect to the Service Bus. A service is always required to present authentication credentials to the Service Bus, usually in the form of a shared secret (that is, issuer name and secret) token. However, the service also determines what type of authentication credentials the client applications must use in order to connect to the service. By default, client authentication is set to RelayClientAuthenticationType.RelayAccessToken, which means that the client must present some form of authentication to the Service Bus. In the current version of Windows Azure, this is always another shared secret token. In contrast, transport security determines whether it must connect with some form of secure line. This is referred to as “end-to-end” security because it covers the whole connection between the service, the Service Bus, and the client. In contrast, client authentication covers only the required relationship to connect from the service to the Service Bus. By default, transport security is set to EndToEndSecurityMode.Transport, which means that security is provided using some form of secure transport, such as HTTPS. It is recommended that you keep the end-to-end security mode set to Transport unless you have a compelling reason to change it, as doing this might reduce the security level in your application. For more information about setting security, see Securing and Authenticating a Service Bus Connection
|The Service Bus uses the default configuration that you have specified in the App.config file. Therefore, you do not have to directly reference the configuration in your code. However, if you have multiple endpoints and bindings, you may want to explicitly state which configuration to use, in order to avoid confusion.|
The following procedure describes how to configure an Service Bus service by using an App.config file.
To configure a Service Bus service application by using an App.config file
To configure the endpoint for the service that uses the contract with a specified binding, create the App.config file. For example:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <!-- Application Service --> <service name="Microsoft.ServiceBus.Samples.EchoService"> <endpoint contract="Microsoft.ServiceBus.Samples.IEchoContract" binding="netTcpRelayBinding" address="sb://MyCodeSample.ServiceBus.Microsoft.com/EchoService" /> </service> </services> </system.serviceModel> </configuration>
Note the minimum parameters that are required to configure an endpoint: the service name, the contract that implements the service, the type of binding used, and the address. The service uses the default Transport and Authentication security parameters. Therefore, they are not explicitly declared. The address is explicitly declared here, although very often it is built programmatically using the URI type.
Once you have completed the steps that are required to configure an Service Bus service, you can add more endpoint and service-level configurations. For more information, see Configuring Services in the WCF documentation.
After you have finished configuring the service, you can host and run the application. For more information, see Building a Service for the Service Bus.