This sample demonstrates how to use a simple web token credential to authenticate with the Service Bus.

The sample is similar to the Echo sample, with a few changes. Specifically, this sample adds a behavior in the ServiceHost (service) and ChannelFactory (client) applications.

Prerequisites

If you haven't already done so, please read the release notes document that explains how to sign up for a Windows Azure account and how to configure your environment.

Service

Please refer to the Echo sample for information about how the service is defined and configured.

The service authenticates with the Service Bus using a SimpleWebToken credential. It uses a helper method ComputeSimpleWebTokenString(string issuerName, string issuerSecret) to compute the string that is expected by TransportClientEndpointBehavior.

Client

Please refer to the Echo sample for information about how the client is defined and configured.

In this sample, both the client and the service use the same credential; therefore, no additional steps are required to grant the client access to listen or to send messages to the service through the Service Bus.  By default, a credential is granted with Listen, Send, and Manage privileges within its own Service Bus service namespace.  If a client is using a different credential than the service, a specific Access Control rule is needed for a client credential to gain Listen, Send or Manage privileges in the Service Bus service namespace for the service.  For more information about creating Access Control rules, please see the ManagementService sample from the Access Control Samples .

The client also authenticates with the Service Bus using a SimpleWebToken credential. It uses the same ComputeSimpleWebTokenString(string issuerName, string issuerSecret) method to compute the web token string.

Building and Running the Sample

First, build the solution in Visual Studio or from the command line. To run the application, do the following:

  1. From a command prompt, run the service (Service\bin\Debug\Service.exe).

  2. When prompted, type the service namespace, the issuer name (e.g. "owner") and the issuer secret key with which you want the service to run. When authorized, the service indicates that it is listening at the configured address.

  3. From another command prompt, run the client (Client\bin\Debug\Client.exe).

  4. When prompted, type the issuer name (e.g. "owner"), the issuer secret key and the service namespace with which you want the client to connect. Enter a line of text to send to the service, then press Enter.

  5. When finished, press Enter to exit the client and the service.

Expected Output – Service

Your Service Namespace: <service-namespace>
Your Issuer Name: <issuer-name>
Your Issuer Secret: <issuer-secret>
Service address: sb://<service-namespace>.servicebus.windows.net/SimpleWebTokenAuthenticationService/
Press [Enter] to exit
Echoing: a
Echoing: b
Echoing: c

Expected Output – Client

Your Service Namespace: <service-namespace>
Your Issuer Name: <issuer-name>
Your Issuer Secret: <issuer-secret>
Enter text to echo (or [Enter] to exit):
a
Server echoed: a
b
Server echoed: b
c
Server echoed: c


Did you find this information useful? Please send your suggestions and comments about the documentation.