Microsoft .NET Services SDK - Service Bus - Http Relay "No Authentication" Sample

Overview

This sample demonstrates how to expose an HTTP service that does not require client user authentication.

Prerequisites

If you haven't already done so, please read the common prerequisites document that explains how to sign up for a Microsoft .NET Services account and how to configure your environment. It also contains important information about the default security settings for your environment that you need to be aware of.

Service

The service in this sample creates a simple RSS feed and returns it using the .NET Framework 3.5 RSS/Atom features and the extended 'Web-Style' service support.

Client

The client calls the syndication service and writes the feed contents to the console. We first collect the user to connect to:

static void Main(string[] args)
{
      Console.Write("Enter the name of the user you want to connect with: ");
      string serviceUserName = Console.ReadLine();
 

The client then prepares a request to the URI of the service.

      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceUri.ToString());

      Stream stream = response.GetResponseStream();
      XmlTextReader reader = new XmlTextReader(stream);
 
      Stream stream = response.GetResponseStream();
      XmlDocument doc = new XmlDocument();
      doc.Load(stream);

      Console.WriteLine("\nThese are the contents of your feed: ");
      Console.WriteLine(" ");
      Console.WriteLine(doc.SelectSingleNode("/rss/channel/title").InnerText);
      foreach (XmlElement item in doc.SelectNodes("/rss/channel/item"))
      {
        Console.WriteLine(item["title"].InnerText + ": " + item["description"].InnerText);
      }
}

The most interesting element in this sample is to be found in the service's configuration file. The 'allowUnauthenticatedAccess' setting controls whether or not a client is required to authenticate when accessing the HTTP service. The setting here is 'true', meaning that access is permitted to anyone. If the setting were 'false' (which would break the client portion of this sample, but still permit interactive access through the browser) clients would have to log in interactively presenting one of the credentials accepted by the Access Control Service.

 <webHttpRelayBinding>
     <binding name="default">
        <transport mode="None" r     <binding name="default">
        <security mode="None" relayClientAuthenticationType="None" />
     </binding>
</webHttpRelayBinding> 
Please perform the following steps to run the application:
  1. From a command shell, run the service (Service\bin\Debug\Service.exe)
  2. When prompted, select a CardSpace Information Card to authenticate with the STS (the Relay Service requires that the user be authenticated).  At this point, the service should indicate that it is listening at the configured address
  3. From another command shell, run the client (Client\bin\Debug\Client.exe)

Note: You can also point the browser to the HTTP URI given below to view the feed contents.

Expected Output – Service

Service address: http://servicebus.windows.net/services/<userName>/SyndicationService/
Press [Enter] to exit

Expected Output – Client

Enter the name of the user you want to connect with: 
 
These are the contents of your feed:
 
Microsoft .NET Services Feed
Day 1: Today I woke up and went to work. It was fun.
Day 2: Today I was sick. I didn't go to work. Instead I stayed home and wrote code all day.
Day 3: This is my third entry. Using Microsoft .NET Services is pretty cool!