<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Will's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/willpe/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/willpe/feed.xml</link>
    <description>Thoughts on AppFabric, Azure and the Cloud</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:39:52 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Getting Started with the Service Bus Samples for Windows 8</title>
      <link>https://docs.microsoft.com/archive/blogs/willpe/getting-started-with-the-service-bus-samples-for-windows-8</link>
      <pubDate>Tue, 22 May 2012 10:20:00 GMT</pubDate>
      <dc:creator><![CDATA[willpe]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/willpe/2012/05/22/getting-started-with-the-service-bus-samples-for-windows-8/</guid>
      <description><![CDATA[As part of the Windows Azure Toolkit for Windows 8, we recently released a sample library for...]]></description>
      <content:encoded><![CDATA[<p>As part of the <a href="http://watwindows8.codeplex.com/">Windows Azure Toolkit for Windows 8</a>, we recently released a sample library for accessing Service Bus from Windows 8 metro style applications and a sample metro app demonstrating how to use some basic Service Bus functionality. In this post, we'll take a quick tour around the sample app, get an introduction to the sample library and examine in detail how the sample library works.</p>
<h5><b>Service Bus Sample Browser for Windows 8</b></h5>
<p>To help make getting started really easy, we've built the Service Bus Sample Browser for Windows 8 - this simple metro style application lets you explore and learn about service bus functionality interactively and always keeps you close to the code.</p>
<p>In every sample, bringing up the AppBar in the sample browser (Right Click with a Mouse, or swipe up from the bottom bezel with touch) will allow you to Copy Source Code from the sample to the clipboard for use in Visual Studio.</p>
<p>When you launch the sample browser, you'll find 3 simple samples included:</p>
<p><b>Simple Queues</b> <br />Service Bus Queues are durable First In, First Out message queues that permit communication between distributed applications or components. You can <a href="http://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/">learn more about Service Bus queues</a> on WindowsAzure.com. The pattern for using queues is straightforward: someone sends a message to the queue, someone else receives the message later.</p>
<p><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/13/25/3617.ServiceBusSamples1.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-13-25/3617.ServiceBusSamples1.png" /></p>
<p>In the Simple Queues sample, you can follow a simple example of how to use this messaging pattern within a Windows 8 metro style application.</p>
<p><b>Simple Topics</b> <br />Topics and Subscriptions in Service Bus support a publish/subscribe communication model - messages are Sent to a single topic and can then be Received by multiple subscribers. You can <a href="http://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/">learn more about Service Bus Topics</a> on WindowsAzure.com. Using topics is as simple as using queues - someone sends a message to the topic and each subscriber is able to receive a copy of that message later.</p>
<p><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/13/25/8831.ServiceBusSamples2.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-13-25/8831.ServiceBusSamples2.png" /></p>
<p>In the Simple Topics sample you'll create a Topic, add one or more subscribers to it then send and receive messages.<b></b></p>
<p><b>Peek Lock, Abandon and Complete</b> <br />Both Queues and Subscriptions support to different ways to receive messages. The first, Receive and Delete, removes the message from the queue or subscription when it is received - if the receiver fails to process the message, then its content is lost. The second, Peek Lock, makes the Receive and Delete operations two separate operations - first a messages is Peeked from the queue by the receiver, later the receiver can Complete the message (deleting it from the queue or subscription and marking it as processed) or Abandon the message (marking it as not completed or unprocessed). A message is returned to the queue or subscription if it is abandoned of its peek-lock times out (by default, the peek lock timeout is 30 seconds).</p>
<p>In the Peek Lock Sample, you try out peek locking yourself. Click each of the shapes to send it to a queue and then try receiving. When you've received a shape, select it to Complete or Abandon the message - Completed messages do not return to the Queue, while abandoned ones do. If you neither complete or abandon a message, you'll observe that it's lock expires and it is automatically returned to the queue.</p>
<h5><b>Sample Service Bus Library for Windows 8 - Microsoft.Samples.ServiceBus</b></h5>
<p>To get started download the <a href="http://watwindows8.codeplex.com/">Windows Azure Toolkit for Windows 8</a>.</p>
<p>To make it easier to consume the Service Bus REST API, we've built a sample library for Windows 8 which wraps common Service Bus primitives like Queue, Topic and Subscription - let's dive straight into some code to illustrate creating a queue, sending a message, receiving the message and deleting the queue. If you are new to the Service Bus, take a look at these how-to articles on <a href="http://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/">Service Bus Queues</a> and <a href="http://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/">Service Bus Topics</a>.</p>
<p>Since we'll be calling Service Bus over HTTP, we need to consider a couple of things:</p>
<ol>
<li><b>Request the Internet (Client) capability in your package manifest</b>: Service Bus is on the internet, so you'll need to make sure your application has permissions to access the network.</li>
<li><b>Calls to the network should always be asynchronous</b>: since a network call could take a little time to complete, you'll always want to use asynchronous IO. The Sample Service Bus Library helps out by exposing simple asynchronous methods for every operation.</li>
</ol>
<p>First up, we need a Token Provider. Token Providers are used by the library to request an authorization token from the Access Control Service (ACS) and attach that token to requests made to Service Bus. You can think of the Token Provider like a set of credentials - it specifies 'who' is trying to perform an action on a service bus resource:</p>
<p>TokenProvider tokenProvider = TokenProvider.CreateSharedSecretTokenProvider( <br />serviceNamespace: "Your Service Bus Namespace Name, e.g. contoso", <br />issuerName: "owner", <br />issuerSecret: "Your Service Bus Issuer Secret, e.g. b66Gxx...");</p>
<p>Next we'll create a queue - this super-simple call specifies the path of the queue to create and uses the default queue description. If you want to tweak the settings on the queue you're creating, you'll find a helpful overload accepting a Queue Description as a parameter:</p>
<p>Queue myQueue = await Queue.CreateAsync("MyQueue", tokenProvider);</p>
<p>With the queue created in Service Bus, we can go ahead and send a message. The samples library makes it simple to send plain text messages or messages whose body is a JSON formatted object. Here, we're just going to asynchronously send a plain text string as the body of the message:</p>
<p>await myQueue.SendAsync("Hello World!");</p>
<p>Receiving a message is just a simple - we'll attempt to receive from the queue using Receive and Delete semantics. If you want to use Peek Lock semantics, you'll find the PeekLockAsync method nearby. Having received the message, we'll extract the plain-text body:</p>
<p>BrokeredMessage message = await myQueue.ReceiveAndDeleteAsync(); <br />string greeting = message.GetBody&lt;string&gt;();</p>
<p>Finally, we're going to clean up after ourselves and delete the queue:</p>
<p>await Queue.DeleteAsync("MyQueue", tokenProvider);</p>
<p>So, there we go - just a few lines of code to create, send, receive and delete entities in Service Bus. In the Sample Service Bus Library for Windows 8, we've tried to ensure you have a simple API surface area to get started with and the full power of our REST API surface available when you want it. We're shipping this library as an open source licensed sample to give you the freedom and flexibility to dive deep into the code if you want to and tweak to your heart's content!</p>
<p>We're hopeful that the simplified API surface in the Sample Service Bus Library for Windows 8 makes it easy to get started building great Metro Style Apps that are connected with Service Bus - we've tried to reduce the total number of concepts you need to become familiar with to achieve typical scenarios and make it easier to learn about our advanced features as you need them - we're always keen to hear your feedback on how useful this sample library is to you, please let us know you thoughts on the discussion list for <a href="http://watwindows8.codeplex.com/">Windows Azure Toolkit for Windows 8</a>.</p>
<h5><b>Going Deep: How the Sample Service Bus Library for Windows 8 Works</b></h5>
<p>Service bus operations fall into one of two classes: Management or Runtime. Management operations are used to Create, Enumerate, Get and Delete service bus entities like Queues, Topics and Subscriptions; Runtime operations are used to Send and Receive messages. Firstly we'll dive deep into how the Sample Service Bus Library for Windows 8 implements Management Operations, and then we'll take a look at how Runtime Operations are implemented.</p>
<p><b>Management Operations: Create, Get, Enumerate and Delete</b> <br />The service bus namespace can be thought of as a set of ATOM Feeds, each describing entities that exist at paths beneath it. For example, if a Queue called 'Foo' exists at the Uri: <a href="https://contoso.servicebus.windows.net/Foo">https://contoso.servicebus.windows.net/Foo</a> then we would find an atom entry like this at that address:</p>
<p><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/13/25/1778.ServiceBusSampleCode.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-13-25/1778.ServiceBusSampleCode.png" /></p>
<p>Quickly looking over the markup, you'll notice the address of the queue (line 3), the name of the queue (line 4) and the description of the queue that exists here (line 12-25). This pattern is true throughout the namespace - all entities are represented as an XML Entity Description wrapped in an Atom Entry.</p>
<p>Managing service bus entities is achieved by performing RESTful operations on these feeds within a service bus namespace over HTTPS: To create an entity we issue an HTTP <b>PUT</b>, to get an entity we issue an HTTP <b>GET</b> and to delete an entity we issue an HTTP <b>DELETE</b>. Enumeration is performed by issuing an HTTP <b>GET</b> within the reserved <b>$Resources</b> collection at the root of the namespace (for example, <b>/$Resources/Queues</b>).</p>
<p>Each type of entity and sub entity that you can create is represented in a hierarchy of Resource Descriptions. These include the familiar Queue, Topic and Subscription Descriptions and more advanced entities like Rule Description, Rule Filter and Rule Action:</p>
<p><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/13/25/6253.ServiceBusSamples3.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-13-25/6253.ServiceBusSamples3.png" /></p>
<p>The Resource Description types encapsulate the Content of an Atom entry that represents a service bus entity - when serialized to XML (using the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx">DataContractSerializer</a>) and wrapped in an Atom entry, these types can be used to create, delete, list and represent entities in service bus.</p>
<p>Within the Sample Service Bus Library for Windows 8, a Resource Description can be expressed as an Atom Entry by calling the <b>AsSyndicationItem()</b> method; the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationitem.aspx">SyndicationItem</a> type is within <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.aspx">System.ServiceModel.Syndication</a> namespace which provides classes to work with both RSS and ATOM feeds. Similarly, a Resource Description can be extracted from an Atom Entry by using the static <b>ResourceDescription.Create&lt;T&gt;(SyndicationItem)</b> method and specifying the expected resource type as the type parameter, <b>T </b>(for example, <b>T</b> could be <b>QueueDescription</b>).</p>
<p>Understanding how we model the descriptions of various service bus entities (as <b>ResourceDescription</b>s) and how we convert those descriptions to and from Atom (using the <b>ResourceDescription.AsSyndicationItem()</b> and <b>ResourceDescription.Create&lt;T&gt;(SyndicationItem item)</b> methods) we're well prepared to see how the Create, Get, List and Delete operations are implemented. We'll use Queues to examine how management operations are implemented, but the logic for Topics, Subscriptions and Rules is extremely similar.</p>
<p>Let's take a look at creating a Queue:</p>
<p>Queue myQueue = await Queue.CreateAsync("Foo", tokenProvider);</p>
<p>When we call <b>Queue.CreateAsync,</b> we're going to perform the following operations:</p>
<ol>
<li>Create an instance of <b>QueueDescription</b> and specify <b>"Foo"</b> as the path;</li>
<li>Create a <b>NamespaceManager</b> for the service bus namespace specified in the <b>tokenProvider</b>;</li>
<li>Request that the <b>NamespaceManager</b> create a new Queue with the specified <b>QueueDescription</b>;</li>
<li>Within the <b>NamespaceManager</b>, wrap the <b>QueueDescription</b> in <b>Atom</b> by calling <b>AsSyndicationItem()</b>;</li>
<li>Request that a <b>SyndicationClient</b> create a new resource with the specified <b>SyndicationItem</b>;</li>
<li>The <b>SyndicationClient</b> requests an <b>Authorization Token</b> with the <b>TokenProvider</b>;</li>
<li>The <b>SyndicationClient</b> issues an <b>HTTP PUT</b> with the <b>SyndicationItem</b> as its body and the <b>Authorization Token</b> as a header;</li>
<li>The <b>HTTP Response</b> is read and loaded into a <b>SyndicationItem</b> by the <b>SyndicationClient</b>;</li>
<li>The <b>SyndicationItem</b> is returned to the <b>NamespaceManager</b>;</li>
<li>The <b>NamespaceManager</b> extracts the <b>Content</b> of the <b>SyndicationItem</b> as a <b>QueueDescription</b>;</li>
<li>The <b>QueueDescription</b> is returned to the calling <b>Queue.CreateAsync</b> method;</li>
<li>An instance of a <b>Queue</b> is created to encapsulate the newly created <b>QueueDescription.</b></li>
</ol>
<p>You can visualize the <b>Queue</b>, <b>NamespaceManager</b> and <b>SyndicationClient</b> as each adding a layer of information to the original intent to create a queue called foo before handing the request off to service bus:</p>
<p><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/13/25/1616.ServiceBusSamples4.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-13-25/1616.ServiceBusSamples4.png" /></p>
<p>The <b>Queue</b> is a convenience class that encapsulates a Queue's description and also operations like Send/Receive in one place. The <b>Queue</b> type uses a <b>NamespaceManager</b> to Create, List, Get and Delete entities in a Service Bus namespace. The <b>NamespaceManager</b> is responsible for figuring out the full URI that an HTTP Request should be issued against (using the <b>ServiceBusEnvironment</b>) and wrapping Resource Descriptions in Atom (using the <b>AsSyndicationItem</b> method) before using a <b>SyndicationClient</b> to create HTTP Calls. The <b>SyndicationClient</b> is responsible for getting an authorization token (using a <b>TokenProvider</b>) and making HTTP calls (using <b>HTTPClient</b>).</p>
<p>All management operations happen the same way - they're first issued against a high-level abstraction like Queue, Topic or Subscription, passed down to a Namespace Manager for addressing and conversion to Atom then handled by a Syndication Client to perform the actual raw HTTP Request against service bus.</p>
<p><b>Runtime Operations: Send, Receive, Peek Lock, Abandon and Complete</b> <br />Sending and receiving messages over HTTP is really simple. To send a message you issue an HTTP POST to the 'messages' collection of a Queue or Topic and to Receive (in receive and delete mode) you issue an HTTP DELETE to the head of the 'messages' collection of a Queue or Subscription. Peek locking is similarly achieved by issuing an HTTP POST to the head of the messages collection to create the peek lock; issuing an HTTP PUT to the lock location to abandon the message and issuing an HTTP DELETE to the lock location.</p>
<p>Service Bus Messages have Headers (like Sent Time, Message Id and Time-to-Live); user-specified message Properties and a body. Over HTTP, Headers are encapsulated as a JSON formatted structure in a reserved HTTP Header named <b>BrokerProperties</b>; user-specified message properties are encapsulated as plain HTTP Headers and the body of the service bus message is - you guessed it - the body of the HTTP Message. Sending a message to a queue is as simple as invoking <b>SendAsync</b> on that queue:</p>
<p>await myQueue.SendAsync("Hello, World!");</p>
<p>Let's take a look at a the HTTP trace for sending this message to get a better idea of what it looks like:</p>
<p><b>POST</b> <a href="https://contoso.servicebus.windows.net/Foo/Messages%20HTTP/1.1">https://contoso.servicebus.windows.net/Foo/Messages HTTP/1.1</a> <br /><b>Host</b>: contoso.servicebus.windows.net <br /><b>Authorization</b>: WRAP access_token="..." <br /><b>Content-Type</b>: text/plain <br /><b>Content-Length</b>: 13</p>
<p>Hello, World!</p>
<p>Receiving a message is similarly straightforward - this time we'll Receive and Delete from the head of the Queue:</p>
<p>BrokeredMessage message = await myQueue.ReceiveAndDeleteAsync();</p>
<p>And here's the corresponsing HTTP request and response traces:</p>
<p><b>DELETE</b> <a href="https://contoso.servicebus.windows.net/Foo/Messages/Head?timeout=30">https://contoso.servicebus.windows.net/Foo/Messages/Head?timeout=30</a> HTTP/1.1 <br /><b>Host</b>: contoso.servicebus.windows.net <br /><b>Authorization</b>: WRAP access_token="..." <br /><b>Content-Length</b>: 0</p>
<p>-</p>
<p><b>HTTP/1.1 200 OK</b> <br /><b>Transfer-Encoding</b>: chunked <br /><b>Content-Type</b>: text/plain <br /><b>Server</b>: Microsoft-HTTPAPI/2.0 <br /><b>BrokerProperties</b>: {"DeliveryCount":1,"MessageId":"62a7eceab7eb4d52ac741af5f44393ce","SequenceNumber":1,"TimeToLive":922337203685.47754} <br /><b>Date</b>: Mon, 04 Aug 2015 16:23:42 GMT</p>
<p>Hello, World!</p>
<p>You can see here the simple format of a service bus message over HTTP and start to identify some of the metadata available in the <b>BrokerProperties</b> header. Within the Sample Service Bus Library for Windows 8, the type <b>BrokeredMessage</b> is used as an encapsulation for a service bus message, its headers, properties and body. Let's walk through how the call to SendAsync actually works:</p>
<ol>
<li><b>SendAsync(string &hellip;) </b>is called indicating that a plain-text service bus message should be sent;</li>
<li>A new <b>BrokeredMessage</b> is constructed and writes the body of the message to a <b>Stream;</b></li>
<li>The Queue calls <b>SendAsync(BrokeredMessage)</b> on a <b>MessageSender</b> with the newly constructed message;</li>
<li>The <b>MessageSender</b> requests an <b>Authorization Token</b> with the <b>TokenProvider</b>;</li>
<li>The <b>MessageSender</b> issues an <b>HTTP POST </b>specifying the BrokeredMessage's BodyStream as its body;</li>
<li>HTTP Headers, including any <b>BrokerProperties</b>, user-specified message properties and the <b>Authorization</b> <b>Header</b> are appended to the request.</li>
<li>The <b>HTTP Response</b> is checked for an OK (200) status code.</li>
</ol>
<p>The message sender also supports sending more complex types as the body of a message by serializing them to JSON. A <b>MessageReceiver</b> is used in a similar fashion to receive messages from a Queue or Subscription.</p>
<p>Hopefully this quick whirlwind-tour of the Sample Service Bus Library for Windows 8 gives you some pointers to get started. We're really excited to hear your feedback on the library and see the awesome connected apps you build with it - lets us know what you're up to on the discussion list for <a href="http://watwindows8.codeplex.com/">Windows Azure Toolkit for Windows 8</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>AppFabric Service Bus on NuGet and CodePlex</title>
      <link>https://docs.microsoft.com/archive/blogs/willpe/appfabric-service-bus-on-nuget-and-codeplex</link>
      <pubDate>Wed, 25 May 2011 07:00:00 GMT</pubDate>
      <dc:creator><![CDATA[willpe]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/willpe/2011/05/25/appfabric-service-bus-on-nuget-and-codeplex/</guid>
      <description><![CDATA[Today, the Service Bus team is happy to announce a couple of initiatives to make it even easier to...]]></description>
      <content:encoded><![CDATA[
<p>Today, the Service Bus team is happy to announce a couple of initiatives to make it even easier to get started learning and using the Service Bus: the <a href="http://nuget.org/List/Packages/WindowsAzure.ServiceBus">AppFabric Service Bus NuGet Package</a> and the <a href="http://servicebus.codeplex.com/">Service Bus Samples CodePlex Site</a>. Both our Samples and SDK are still available as a <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=D89640FC-C552-446E-AEAD-B1E0D940F31B">download from MSDN</a>, but we're hopeful that these new choices might be simpler and more convenient.</p>
<h3>Service Bus on NuGet</h3>
<p><a href="http://nuget.org/">NuGet</a> is an open source package manager for .Net which is integrated into Visual Studio and makes it simple to install and update libraries. While traditionally you would need to download an install an SDK before using it within your projects, NuGet adds a new 'Add Library Package Reference' option to Visual Studio which downloads, configures and updates the references you select automatically. The <a href="http://nuget.org/List/Packages/WindowsAzure.ServiceBus">Service Bus NuGet Package</a> contains two DLL files and configuration information needed to use the AppFabric May CTP - you can use this package <b>instead of</b> needing to download and install the Windows Azure AppFabric SDK v2.0 CTP May 2011 Update. Give it a try and let us know what you think in the <a href="http://social.msdn.microsoft.com/Forums/en-US/appfabricctp">AppFabric CTP Forums</a>.</p>
<h3>Service Bus Samples on CodePlex</h3>
<p>We're also excited today to offer you a new way to find and browse our library of sample code at our new <a href="http://servicebus.codeplex.com">CodePlex</a> site. We'll be using the CodePlex site to help get more samples, tools and utilities out into your hands early and often. You can <a href="http://servicebus.codeplex.com/SourceControl/BrowseLatest">Browse the Source Code</a> online or Download a copy if you prefer. Our CodePlex site licenses sample code to you under the open <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache 2.0 License</a> - we're hopeful that makes it easier to re-use, re-distribute and share our sample code and tools. We'll be adding more code to the site regularly and would love to hear your <a href="http://social.msdn.microsoft.com/Forums/en-US/appfabricctp">feedback</a> on the things you'd like to see us share.</p>
<p>As always, we're constantly hoping to hear from you about how we're doing - are CodePlex and NuGet useful delivery vehicles for you, or do you prefer to download and install the SDK and Samples? Please <a href="http://social.msdn.microsoft.com/Forums/en-US/appfabricctp">let us know</a> on the forums!</p>]]></content:encoded>
    </item>
    <item>
      <title>Using the Service Bus via REST / HTTP</title>
      <link>https://docs.microsoft.com/archive/blogs/willpe/using-the-service-bus-via-rest-http</link>
      <pubDate>Wed, 18 May 2011 05:26:00 GMT</pubDate>
      <dc:creator><![CDATA[willpe]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/willpe/2011/05/18/using-the-service-bus-via-rest-http/</guid>
      <description><![CDATA[The new Service Bus Durable Messaging features introduced with the May 2011 CTP are really cool,...]]></description>
      <content:encoded><![CDATA[
<p>The <a href="http://blogs.msdn.com/b/appfabric/archive/2011/05/14/announcing-the-windows-azure-appfabric-ctp-may-and-june-releases.aspx">new Service Bus Durable Messaging features</a> introduced with the May 2011 CTP are really cool, and what's even better than a slew of new messaging features added to the AppFabric is the fact that many of them are accessible from clients on any platform using HTTP. In this post, I'm going to introduce you to using the Service Bus REST endpoint for Messaging; some of it might remind you of the <a href="http://blogs.msdn.com/b/willpe/archive/2010/11/01/getting-started-with-service-bus-v2-october-ctp-connection-points.aspx">October CTP</a>, we'll be using Queues (so taking a look at <a href="http://blogs.msdn.com/b/appfabric/archive/2011/05/17/an-introduction-to-service-bus-queues.aspx">David's post</a> from Tuesday could be a good idea), and getting to grips with <a href="http://blogs.msdn.com/b/willpe/archive/2011/05/12/getting-access-control-service-tokens-via-http.aspx">How Access Control Tokens work over HTTP</a> would be a great primer, too.</p>
<h3>A Preface to the RESTful Service Bus</h3>
<p>Typically, users of the Service Bus download and install the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=D89640FC-C552-446E-AEAD-B1E0D940F31B">AppFabric SDK</a>, add a reference to <i>Microsoft.ServiceBus</i> and/or <i>Microsoft.ServiceBus.Messaging</i> and use the <a href="http://msdn.microsoft.com/en-us/library/microsoft.servicebus.servicebusnamespaceclient.aspx">ServiceBusNamespaceClient</a> to perform management operations (creating, enumerating and deleting any queues, topics or subscriptions) or the <a href="http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.messagingfactory.aspx">MessagingFactory</a> to Send and Receive messages. Details like addressing and security are taken care of by the SDK: there's no need to get or renew Access Control Service tokens and no need to interact directly with the service - you just use the SDK. With the REST endpoint, you get a little closer to the metal which - in this geek's humble opinion - can be at least a little bit more fun! </p>
<p>Wherever possible, you'll want to use our SDK. It sheilds you from some of the underlying complexity of the service, may help to protect you as features change in future and - frankly - it's just a lot easier. That said, there are plenty of times when you won't be able to use the SDK, for example: when working on a non desktop .Net Framework version (like Windows Phone 7 or Silverlight); when working on non-microsoft platforms (like iOS, Android, Java, PHP or Ruby); and when working with older versions of the .Net Framework.</p>
<p>For convenience and consistency, the code samples in this post are shown in C# - that's not because you'd be writing in C# when using the Service Bus from iOS, PHP or Ruby, of course! I want to focus today on showing some of the basics of using our REST API from a language that many of you will be familiar with. That said, you can look forward to future posts in a wider variety of languages showing the awesome things you can do with Service Bus across platforms and devices.</p>
<p>There are 5 things I'll be covering in this post to get you started - please leave your feedback on areas you'd like have more detail, examples and guidance either in the comments (below) or the <a href="http://social.msdn.microsoft.com/Forums/en-US/appfabricctp/">AppFabric CTP Forums</a>. </p>
<ol>
<li>Get a security token from the Access Control Service </li>
<li>Create a Queue in your service namespace </li>
<li>Send a Message to the Queue </li>
<li>Receive the Message from the Queue </li>
<li>Delete the Queue </li>
</ol>
<p>We're going to be busy - so make sure you have an account set up at the <a href="https://portal.appfabriclabs.com/">AppFabric Labs Portal</a> and Lets Get Started!</p>
<h3>Getting and Using a Security Token</h3>
<p>Last Week, I provided some guidance on <a href="http://blogs.msdn.com/b/willpe/archive/2011/05/12/getting-access-control-service-tokens-via-http.aspx">Getting and Understanding an Access Control Service Token via HTTP</a>, so I won't provide a huge level of detail today on the topic. Suffice to say, the service bus requires that you present a WRAP access token in the HTTP Authorization Header, like this: </p>
<pre class="code"><span class="keyword">Authorization</span>: <span class="string">WRAP access_token="<i>&lt;Your Token Here&gt;</i>"</span></pre>
<p>Firstly, we'll get a token from ACS using the Issuer Name and Key which you can look up in the <a href="https://portal.appfabriclabs.com/">AppFabric Portal</a>: </p>
<pre class="code"><span class="keyword">string</span> serviceNamespace = <span class="string">"contoso"</span>;
<span class="keyword">string</span> issuerName  = <span class="string">"owner"</span>;
<span class="keyword">string</span> issuerPassword = <span class="string">"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa="</span>;

<span class="keyword">string</span> acsBaseAddress = <span class="string">"https://"</span> + serviceNamespace + <span class="string">"-sb.accesscontrol.appfabriclabs.com/"</span>;

<span class="comment">// Note that the scheme is Http</span>
<span class="keyword">string</span> relyingPartyAddress = <span class="string">"http://"</span> + serviceNamespace + <span class="string">".servicebus.appfabriclabs.com/"</span>;

<span class="comment">// Create the body of the Post Request, formatted as a HTTP Form</span>
<span class="keyword">string</span> postData = <span class="string">"wrap_scope="</span> + <span class="user-type">Uri</span>.EscapeDataString(relyingPartyAddress) +
                  <span class="string">"&amp;wrap_name="</span> + <span class="user-type">Uri</span>.EscapeDataString(issuerName) +
                  <span class="string">"&amp;wrap_password="</span> + <span class="user-type">Uri</span>.EscapeDataString(issuerPassword);

<span class="keyword">string</span> authorizationToken;
<span class="keyword">using</span> (<span class="user-type">WebClient</span> acsWebClient = new<span></span> <span class="user-type">WebClient</span>())
{
    <span class="comment">// The response contains the access token and its expiry time formatted as an HTTP 
    // Form like: wrap_access_token=&lt;token&gt;&amp;wrap_expiry_time=2000</span>
    <span class="keyword">string</span> response = acsWebClient.UploadString(acsAddress, <span class="string">"POST"</span>, postData);

    <span class="keyword">string</span>[] tokenVariables = response.Split(<span class="string">'&amp;'</span>);
    <span class="keyword">string</span>[] tokenVariable = tokenVariables[0].Split(<span class="string">'='</span>);
    authorizationToken = <span class="user-type">Uri</span>.UnescapeDataString(tokenVariable[1]);
}</pre>
<p>The access token contains its expiry time (currently defaulting to 20 minutes), and you can keep using the same token over-and-over again until it expires. However, once the expiry time elapses you'll need to request a fresh token from the Access Control Service. Now we'll go ahead and create a WebClient to use for our calls to the service bus; we initialize it by correctly setting the Authorization header - you need this header to be present in any call you make to the service bus.</p>
<pre class="code"><span class="user-type">WebClient</span> webClient = <span class="keyword">new</span> <span class="user-type">WebClient</span>();
webClient.Headers[<span class="string">"Authorization"</span>] = <span class="string">"WRAP access_token=\""</span> + authorizationToken + <span class="string">"\""</span>;</pre>
<h3>Creating a new Queue</h3>
<p>In the October CTP, we introduced the idea of Namespace Management: an explicit, RESTful interface to Create, Enumerate and Delete durable Service Bus entities (in the May CTP these are: Queues, Topics and Subscriptions). That concept carries through to the May CTP with just a couple of changes. You still use the established RESTful pattern (HTTP GET to retrieve/enumerate; HTTP PUT to create; HTTP DELETE to remove) to interact with Atom Feeds and Entries; we've simplified things by combining the Management Namespace (formerly https://&lt;your-namespace&gt;-mgmt.servicebus.appfabriclabs.com/) with the Service Namespace (still https://&lt;your-namespace&gt;.servicebus.appfabriclabs.com) though.</p>
<p>A queue can exist anywhere in your service namespace - you create it by putting the description of the queue to a 'vacant' uri in your namespace. We'll need to specify the correct content type for the request (<b>Content-Type: application/atom+xml</b>) then issue an <b>HTTP PUT</b> to the Uri of the new queue (using the secure, https scheme) containing the Atom Entry which defines it:</p>
<pre class="code"><span class="comment">// Note that the scheme is Https</span>
<span class="keyword">string</span> serviceAddress = <span class="string">"https://"</span> + serviceNamespace + <span class="string">".servicebus.appfabriclabs.com/"</span>;

<span class="keyword">string</span> queueName = <span class="string">"MyFirstQueue"</span>;
<span class="keyword">string</span> putData = <span class="string">@"&lt;entry xmlns=""http://www.w3.org/2005/Atom""&gt;
                     &lt;title type=""text""&gt;"</span> + queueName + <span class="string">@"&lt;/title&gt;
                     &lt;content type=""application/xml""&gt;
                       &lt;QueueDescription xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"" /&gt;
                     &lt;/content&gt;
                   &lt;/entry&gt;"</span>;

<span class="keyword">string</span> queueAddress = serviceAddress + queueName;

webClient.Headers[<span class="string">"Content-Type"</span>] = <span class="string">"application/atom+xml"</span>;
<span class="keyword">string</span> response = webClient.UploadString(queueAddress, <span class="string">"PUT"</span>, putData);</pre>
<p>The response to the request contains the Atom Entry for your newly created Queue (below) including all of the settable properties of the <a href="http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.queuedescription.aspx">Queue Description</a>. Updates to existing queues are not allowed, but you can include any of these properties in the Queue Description when you are creating a new queue.</p>
<pre class="xml code">&lt;<span class="element">entry</span> <span class="attribute">xmlns</span>="http://www.w3.org/2005/Atom"&gt;
  &lt;<span class="element">id</span>&gt;https://willpe.servicebus.appfabriclabs.com/MyFirstQueue&lt;/<span class="element">id</span>&gt;
  &lt;<span class="element">title</span> <span class="attribute">type</span>="text"&gt;<span class="element-content">MyFirstQueue</span>&lt;/<span class="element">title</span>&gt;
  &lt;<span class="element">published</span>&gt;<span class="element-content">2011-05-17T20:26:00Z</span>&lt;/<span class="element">published</span>&gt;
  &lt;<span class="element">updated</span>&gt;<span class="element-content">2011-05-17T20:26:00Z</span>&lt;/<span class="element">updated</span>&gt;
  &lt;<span class="element">author</span>&gt;
    &lt;<span class="element">name</span>&gt;<span class="element-content">willpe</span>&lt;/<span class="element">name</span>&gt;
  &lt;/<span class="element">author</span>&gt;
  &lt;<span class="element">link</span> <span class="attribute">rel</span>="self" <span class="attribute">href</span>="https://willpe.servicebus.appfabriclabs.com/MyFirstQueue"/&gt;
  &lt;<span class="element">content</span> <span class="attribute">type</span>="application/xml"&gt;
    &lt;<span class="element">QueueDescription</span> <span class="attribute">xmlns</span>="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect" <span class="attribute">xmlns:i</span>="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;<span class="element">LockDuration</span>&gt;<span class="element-content">PT30S</span>&lt;/<span class="element">LockDuration</span>&gt;
      &lt;<span class="element">MaxQueueSizeInBytes</span>&gt;<span class="element-content">104857600</span>&lt;/<span class="element">MaxQueueSizeInBytes</span>&gt;
      &lt;<span class="element">RequiresDuplicateDetection</span>&gt;<span class="element-content">false</span>&lt;/<span class="element">RequiresDuplicateDetection</span>&gt;
      &lt;<span class="element">RequiresSession</span>&gt;<span class="element-content">false</span>&lt;/<span class="element">RequiresSession</span>&gt;
      &lt;<span class="element">DefaultMessageTimeToLive</span>&gt;<span class="element-content">P10675199DT2H48M5.4775807S</span>&lt;/<span class="element">DefaultMessageTimeToLive</span>&gt;
      &lt;<span class="element">DeadLetteringOnMessageExpiration</span>&gt;<span class="element-content">false</span>&lt;/<span class="element">DeadLetteringOnMessageExpiration</span>&gt;
      &lt;<span class="element">DuplicateDetectionHistoryTimeWindow</span>&gt;<span class="element-content">PT10M</span>&lt;/<span class="element">DuplicateDetectionHistoryTimeWindow</span>&gt;
    &lt;/<span class="element">QueueDescription</span>&gt;
  &lt;/<span class="element">content</span>&gt;
&lt;/<span class="element">entry</span>&gt;</pre>
<h3>Sending a Message to the Queue</h3>
<p>Sending a message using the REST endpoint is really simple: just HTTP Post the body of the message to the Queue's incoming messages uri with the Authorization header in place (specifying the correct content type for the message's body):</p>
<pre class="code"><span class="keyword">string</span> messageBody = "Hello World!";
<span class="keyword">string</span> sendAddress = serviceAddress + queueName + <span class="string">"/Messages"</span>;

webClient.Headers[<span class="string">"Content-Type"</span>] = <span class="string">"text/plain"</span>;
webClient.UploadString(sendAddress, <span class="string">"POST"</span>, messageBody);</pre>
<h3>Receiving a Message from the Queue</h3>
<p>Messages can be received with either <b>Peek Lock</b> or <b>Receive And Delete</b> semantics; both are supported via REST, but for now we'll use Receive and Delete. Receiving in this mode is as simple as issuing a HTTP Delete request to the Head of the Message Queue with a receive timeout:</p>
<pre class="code"><span class="keyword">string</span> receiveAddress = serviceAddress + queueName + <span class="string">"/Messages/Head?timeout=30"</span>;
<span class="keyword">string</span> receivedMessageBody = webClient.UploadString(receiveAddress, <span class="string">"DELETE"</span>, <span class="keyword">string</span>.Empty);</pre>
<p>The receivedMessageBody contains the plain text sent earlier (neat!) - you can also take a look at the Response Headers to find more properties of the message:</p>
<pre class="code"><span class="keyword">X-MS-MESSAGE-ID</span>: <span class="string">d78afc3299b54ab2bd0e97b183ab1f77</span>
<span class="keyword">X-MS-DELIVERY-COUNT</span>: <span class="string">0</span>
<span class="keyword">X-MS-SEQUENCE-NUMBER</span>: <span class="string">2</span>
<span class="keyword">X-MS-SIZE</span>: <span class="string">12</span>
<span class="keyword">Content-Type</span>: <span class="string">text/plain</span></pre>
<h3>Deleting the Queue</h3>
<p>Finally, it's time to delete the queue; this is acheived by a simple HTTP Delete to the Queue's Address:</p>
<pre class="code">webClient.UploadString(queueAddress, <span class="string">"DELETE"</span>, <span class="keyword">string</span>.Empty);</pre>
<p>So, there we have it - a quick introduction to using the new REST features of AppFabric Service Bus Messaging. There's lots more you can do, and I'll be covering more of the features next week but it's never too early to send the team your feedback - visit the <a href="http://social.msdn.microsoft.com/Forums/en-US/appfabricctp/">AppFabric CTP Forum</a> and tell us what you think!</p>
<p>In particular, we'd love to hear from you around how you'll be using HTTP in Applications you build:</p>
<ul>
<li>Which platforms and devices are you considering using Service Bus from? </li>
<li>Which feature(s) of the Service Bus are most important for us to support over HTTP to make your applications successful? </li>
</ul>
<p><b>Take the <a href="http://www.surveygizmo.com/s/547134/service-bus-survey-5-18-2011">HTTP Feature Survey</a> to help shape the future of Service Bus!</b></p>]]></content:encoded>
    </item>
    <item>
      <title>Getting Access Control Service Tokens via HTTP</title>
      <link>https://docs.microsoft.com/archive/blogs/willpe/getting-access-control-service-tokens-via-http</link>
      <pubDate>Wed, 11 May 2011 16:59:59 GMT</pubDate>
      <dc:creator><![CDATA[willpe]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/willpe/2011/05/11/getting-access-control-service-tokens-via-http/</guid>
      <description><![CDATA[Some people like to say that French is the language of love. Others - mainly those with more...]]></description>
      <content:encoded><![CDATA[  <p>Some people like to say that French is the language of love. Others - mainly those with more interest in slipping you a network stack than an afrodisiac - will tell you that HTTP is the protocol equivalent. The AppFabric Service Bus loves HTTP too, and it also loves Security: in this post, I'm going to show you how to get - and understand - a security token from the Access Control Service via HTTP.</p><b>Claims Based Auth 101</b>  <p>To gain access to the service bus, you need to present a <a href="http://wrap-wg.googlegroups.com/attach/38c3c90481d6065c/WRAP-v0.9.7.1.pdf?view=1&part;=4">WRAP Access Token</a> [PDF] in the HTTP Authorization Header for each of your calls. The content for that header is acquired from the access control service by presenting an assertion (like a signed Simple Web Token or a Username and Password pair) as a simple HTTP request; the response contains a set of claims (like who you are, where the token came from, how long the token lasts and which permissions the bearer has) which are signed to ensure authenticity.</p> <p>Before we get started, you'll want to head over to the <a href="https://portal.appfabriclabs.com/">AppFabric Labs Portal</a>. If you aren't signed up, take a moment to create a free account - once you're in click on the Service Bus node on the left and click the 'View' button on the right marked 'Default Issuer'. Note down the details (Issuer Name/Key) from here because you'll need them later.</p><b>Service Namespaces, Issers and Keys</b>  <p>When you create a new Service Bus Namespace, a default identity is established in the namespace's associated Access Control Service namespace. This identity has both Shared Secret and Password credentials available - you can see those credentials by logging in to Access Control Management at <b>https://<i>[Your-Service-Namespace]</i>-sb.accesscontrol.appfabriclabs.com/v2/mgmt/web/ServiceIdentity</b> and clicking on 'owner' ('owner' is the name of the default service identity created when your account was provisioned). When your account is provisioned, the same key is used for both the Issuer Password credential and the Issuer Secret Key credential - this won't always be true as you create more issuers, passwords and secret keys: you don't need to have both a password and a secret key for an issuer, and if you do have both they don't need to be the same.</p><pre class="code"><span class="keyword">string</span> serviceNamespace = <span class="string">"contoso"</span>;
<span class="keyword">string</span> issuerName  = <span class="string">"owner"</span>;
<span class="keyword">string</span> issuerPassword = <span class="string">"&lt;Enter Your Key Here&gt;"</span>;</pre>
<p>You can request a token from ACS using either the password or the shared secret - here is how they differ:</p>
<ol>
<li>A <b>Username and Password</b> are presented to ACS as credentials, if they match the stored values, an auth. token is returned. 
<li>A <b>Shared Secret</b> is used to sign a set of claims which are presented to ACS. If the signature is valid for the presented claims, an auth. token is returned. </li></ol>
<p>Regardless of how you request a token, you'll need to use the WRAPv0.9 ACS Endpoint for your Namespace (note the <b><u>'-sb'</u></b> suffix attached to the service namespace) and the Uri for your Service Bus service namespace <b><u>using the HTTP:// scheme</u></b> (even though, for security purposes, the service bus is only accessible over https, tokens must be requested for http). </p><pre class="code"><span class="keyword">string</span> acsEndpoint = <span class="string">"https://"</span> + serviceNamespace + <span class="string">"-sb.accesscontrol.appfabriclabs.com/WRAPv0.9/"</span>; 
<span class="keyword">string</span> relyingPartyAddress = <span class="string">"http://"</span> + serviceNamespace + <span class="string">".servicebus.appfabriclabs.com/"</span>;</pre>

<b>Method 1: Acquiring a Token with a Username and Password</b> Getting a token using a username and password is really simple - just post a collection of values to the ACS Endpoint including the Relying Party Address ('wrap_scope'), the Issuer Name ('wrap_name') and the Issuer Password ('wrap_password'). The collection of response variables includes the token (but we'll get to that later!): <pre class="code"><span class="user-type">NameValueCollection</span> postData = <span class="keyword">new</span> <span class="user-type">NameValueCollection</span>
    {
        { <span class="string">"wrap_scope"</span>, relyingPartyAddress },
        { <span class="string">"wrap_name"</span>, issuerName },
        { <span class="string">"wrap_password"</span>, issuerPassword },
    };

<span class="user-type">WebClient</span> webClient = <span class="keyword">new</span> <span class="user-type">WebClient</span>();
<span class="keyword">byte</span>[] responseBuffer = webClient.UploadValues</span>(acsEndpoint, "POST", postData);
<span class="keyword">string</span> response = <span class="user-type">Encoding</span>.UTF8.GetString(responseBuffer);</pre>

<p><b>Method 2: Acquiring a Token with a Shared Secret</b></p>The process with a Shared Secret is similar but has another step - we'll still post the Relying Party Address ('wrap_scope'), but instead of posting a username and password we'll send a Signed Simple Web Token ('wrap_assertion') along with a Token Format Identifier ('wrap_assertion_format', equal to 'SWT'). The token is simply a string containing the Issuer Name (in the format, Issuer={0}) signed with a HMACSHA256: 
<pre class="code">
<span class="keyword">byte</span>[] issuerSecretBytes = <span class="user-type">Convert</span>.FromBase64String(issuerSecret);
<span class="keyword">string</span> token = <span class="string">&quot;Issuer=&quot;</span> + <span class="user-type">Uri</span>.EscapeDataString(issuerName);
<span class="keyword">string</span> signature;

<span class="keyword">using</span> (<span class="user-type">HMACSHA256</span> sha256 = <span class="keyword">new</span> <span class="user-type">HMACSHA256</span>(issuerSecretBytes))
{
    <span class="keyword">byte</span>[] signatureBytes = sha256.ComputeHash(<span class="user-type">Encoding</span>.UTF8.GetBytes(token));
    signature = <span class="user-type">Convert</span>.ToBase64String(signatureBytes);
}

<span class="keyword">string</span> signedToken = token + <span class="string">&quot;&HMACSHA256=&quot;</span> + Uri.EscapeDataString(signature);
</pre>
<p>
With the signed token computed, we construct a collection of post data and send it as before:
</p>
 <pre class="code"><span class="user-type">NameValueCollection</span> postData = <span class="keyword">new</span> <span class="user-type">NameValueCollection</span>
    {
        { <span class="string">"wrap_scope"</span>, relyingPartyAddress },
        { <span class="string">"wrap_assertion_format"</span>, <span class="string">"SWT"</span>},
        { <span class="string">"wrap_assertion"</span>, signedToken },
    };

<span class="user-type">WebClient</span> webClient = <span class="keyword">new</span> <span class="user-type">WebClient</span>();
<span class="keyword">byte</span>[] responseBuffer = webClient.UploadValues</span>(acsEndpoint, "POST", postData);
<span class="keyword">string</span> response = <span class="user-type">Encoding</span>.UTF8.GetString(responseBuffer);</pre>

<p>
Now that we've seen how to get a token (in one of two excitingly similar ways) let's take a look at the response.
</p>

<b>Understanding the Token</b>
<p>The response is formatted as a Http Form (name1=value1&name2=value2) like this (the sensitive details have been scrubbed to protect the innocent):</p>
<pre class="code">
<span class="keyword">wrap_access_token</span>=
<span class="string">net.windows.servicebus.action%3dListen%252cManage%252cSend%26http%253a%252f%252fschemas.microsoft.com%252faccesscontrolservice%252f2010%252f07%252fclaims%252fidentityprovider%3dhttps%253a%252f%252fwillpe-blog-sb.accesscontrol.appfabriclabs.com%252f%26Audience%3dhttp%253a%252f%252fwillpe-blog.servicebus.appfabriclabs.com%252f%26ExpiresOn%3d1305157180%26Issuer%3dhttps%253a%252f%252fwillpe-blog-sb.accesscontrol.appfabriclabs.com%252f%26HMACSHA256%3daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%253d</span>
&amp;<span class="keyword">wrap_access_token_expires_in</span>=
<span class="string">1199</span></pre>
<p>The WRAP Access Token is the piece of this response that we need. It's Url Encoded (i.e. it can be decoded using Uri.UnescapeDataString):</p>
<pre class="code">
<span class="keyword">net.windows.servicebus.action</span>=Listen,Manage,Send</span>
&<span class="keyword">http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider</span>=<span class="string">https://willpe-blog-sb.accesscontrol.appfabriclabs.com/</span>
&<span class="keyword">Audience</span>=<span class="string">http://willpe-blog.servicebus.appfabriclabs.com/</span>
&<span class="keyword">ExpiresOn</span>=<span class="string">1305157806</span>
&<span class="keyword">Issuer</span>=<span class="string">https://willpe-blog-sb.accesscontrol.appfabriclabs.com/</span>
&<span class="keyword">HMACSHA256</span>=<span class="string">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=</span>
</pre>
<p>The token contains 5 claims and a signature:</p>
<ul>
<li><b>net.windows.servicebus.action</b>: The permissions this token grants (in this case, Listen, Send and Manage)</li>
<li><b>http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider</b>: The authority that actually identified the user (ACS, Active Directory, Facebook, etc)</li>
<li><b>Audience</b>: The url that this token applies to</li>
<li><b>ExpiresOn</b>: The time that this token is valid until; expressed as a unix file time (that is the number of seconds past January 1, 1970 at 12:00:00 am (UTC))</li>
<li><b>Issuer</b>: The Security Token Service which issued this security token (ACS)</li>
<li><b>HMACSHA256</b>: The token signature</li>
</ul>
<p>In your application, you can use these values to figure out when to renew a token, how the user was authenticated and which actions the user is permitted to perform.</p>]]></content:encoded>
    </item>
    <item>
      <title>Some Thoughts on Test Frameworks</title>
      <link>https://docs.microsoft.com/archive/blogs/willpe/some-thoughts-on-test-frameworks</link>
      <pubDate>Fri, 04 Feb 2011 16:53:45 GMT</pubDate>
      <dc:creator><![CDATA[willpe]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/willpe/2011/02/04/some-thoughts-on-test-frameworks/</guid>
      <description><![CDATA[It might not be the sexiest of topics, but building, consuming, extending and debugging Test...]]></description>
      <content:encoded><![CDATA[ <p>It might not be the sexiest of topics, but building, consuming, extending and debugging Test Frameworks is a large part of any <a href="http://microsoftjobsblog.com/test/">SDET</a>'s day. Traditional wisdom teaches us to write abstraction layers - often many of them - to shield test cases from changes in the system under test: in API testing this often means creating scenario-focussed wrappers over the product; when testing UI this might mean adding layers of automation on top of the actual controls a user would interact with. We generally refer to these abstractions as Test Frameworks - they allow us to write test cases at a much higher level and reduce the maintenance burden of fixing test cases as a system under development inevitably changes.</p> <p>Recently when struggling through a set of changes to one such framework, it struck me that we pour a lot of time and effort into these frameworks: would life be simpler, tests better and productivity higher without our obviously needed framework-friend? Maybe.</p> <p>Firstly- we're building these frameworks to <b>hide changes in the system under test</b>. Aren't changes in the product exactly one of the things we'd like to be detecting? In simple tests and certainly tests of APIs, small changes which break tests might be pretty relevant for a feature tester to look at, but in higher-level, end-to-end scenarios, we're probably better off having these changes hidden. So, if our end-to-end, high level scenarios benefit from frameworks, what level of investment do we want to make in them? It probably depends on what portion of the test plan is comprised of end-to-end tests.</p> <p>Another use of frameworks is to hide complexity in the product itself - consider an API where we need to instantiate an object, make a method call to initialize it, then execute an operation on it in order to achieve some customer scenario: <pre class="code">var iceCreamMachine = iceCreamTruck.CreateIceCreamMachine(Flavors.Chocolate);
iceCreamMachine.TurnOn();
var treat = iceCreamMachine.MakeIceCream();</pre>
Since spreading code like this all over our test cases is going to get messy, we add this <b>Helper Method</b> to the test framework:
<pre class="code">T MakeTreat<t>(IceCreamTruck truck, Flavors flavor) where T : Treat...</t></pre>
It's great, it works and it makes our test code look a lot nicer. There's certainly no reason not to do this, but ask yourself this: <b>If <i>I</i> want this helper method to make writing my code easier and cleaner, wouldn't <i>my customers</i> want it too?</b></p>
<p>We can add these abstractions and wrappers because we ignore or assume details: the system under test often allows a great deal of flexibility, often more than is required for the test cases in question. As the suite grows, more of the products 'knobs and levers' are altered by tests, meaning that more options creep into our wrappers too: sometimes this is a 'helper' class with more properties than the class it's helping you to use; sometime's its a 'helper' method with 15 oddly named parameters. Often - despite the best intentions of the framework's original designers - it becomes more complicated than the product it tests and is always less well documented.</p>
<p><i>I came to a basic conclusion: <b>Test Frameworks are fun to write, but that doesn't always mean it's the right thing to do!</b></i></p>
<p>When dealing with the sordid topic of abstractions, it's worthwhile to remember a 1987 essay by Frederick P. Brooks Jr., <a href="http://virtualschool.edu/mon/SoftwareEngineering/BrooksNoSilverBullet.html">No Silver Bullet</a>, in which we're all reminded that <i>"The complexity of software is an essential property, not an accidental one. Hence, descriptions of a software entity that abstract away its complexity often abstract away its essence."</i> - translating this roughly into test parlance: <b>Avoid abstracting away the thing you're trying to test</b>.</p>
<p>In general development, any learned software engineer will tell you that readability of code is really important: for every time a line of code is written, it is read many, many times. Optimize for the time spent reading, not the time spent writing. In test, I'd like to propose something similar: <b>for every time a test case is written, it will be read and maintained several times, but executed and investigated an order of magnitude more.</b> Maybe we should start optimizing our tests for the times that they fail. After all, a test case is surely at its most useful when failing, since it is hinting at a defect in the product being tested. As soon as a test fails, I usually run through three steps of analysis:
<ol>
	<li>What does this test <b>actually do</b>?</li>
	<li>Is the framework working property? <b>Is this a framework issue?</b></li> 
	<li>What do the <b>repro steps</b> for this bug look like?</li>
</ol>
</p>
<p>Often, the exception actually thrown by the test case is fairly general - it's usually coming from somewhere deep in the test framework and doesn't give much clue to what's actually happened or what the expected outcome of the failing operation was supposed to be. Consider these two exception messages, this from a test framework:</p>
<pre class="code">The expected 'TastesIckyException' was not thrown.</pre>
<p>... and this one from a test case:
<pre class="code">Calling MakeIceCream with custom composite flavor 'Mango' and 'Bacon' should fail, 
because mixing sweet and savoury ice creams together is not allowed.</pre>
<p>There's really not much difference between those two messages, but the second tells you a little more: the test was trying to use custom flavors; the test was using 'composite' flavors; the test was not expecting Mango and Bacon to be a valid flavor. You instantly have some idea about what the test is supposed to be doing and where the failure(s) might be.</p>
<p>In the first case, above, you'd need to dig into the framework to figure out what's going on - is the wrong overload of MakeIceCream() being called? Is the IceCreamMachine correctly configured with Mango and Bacon? Is it the right type of machine? Consider a second test case that looks like this:</p>
<pre class="code">var flavors = new CompositeFlavor(Flavors.Mango, Flavors.Bacon);
var iceCreamMachine = iceCreamTruck.CreateIceCreamMachine(flavors);
iceCreamMachine.TurnOn();
try
{
    var treat = iceCreamMachine.MakeIceCream();
    Fail("Calling MakeIceCream with the custom composite...")
}
catch (TastesIckyException e)
{
    Log.Expected(e);
}</pre>
<p>It's pretty obvious what's going on here, and has a nice side-effect. The test method describes the repro steps. A dev can read these and see:
<ul>
	<li>We're using a CompositeFlavor</li>
	<li>We're passing it into CreateIceCreamMachine</li>
	<li>We call an overload of MakeIceCream() with no parameters</li>
	<li>We expected a TastesIckyException</li>
	<li>The problem is that sweet and savory can't be used together in an ice cream flavor</li>
</ul>
When your test case looks like your repro steps would, a developer can easily determine what the problem is, where it might be and what the expected outcome is; You can easily figure out what the expected outcome of the test is and why it's failing; Both of you save time.</p>
<p>Obviously, this is a fairly trivial - and specific - example. However, it's lead me to think about three things when writing new tests:
<ol>
	<li>Write tests which look like the repro steps you'd want to hand off to a developer;</li>
	<li>Explicitly encode the Expected and Actual outcomes of your test directly into the test case;</li>
	<li>File bugs about the 'Helper Methods' you need to add to make using the product more pleasant - your customers will thank you!</li>
</ol>
</p>
<p>And lastly: it goes without saying that re-use isn't a bad thing, neither are common libraries or frameworks. We'll always benefit from common code, abstraction and toolkits - just consider how, where and why you're using them.
</p></p>]]></content:encoded>
    </item>
    <item>
      <title>Getting Started with Service Bus v2 (October CTP) - Connection Points</title>
      <link>https://docs.microsoft.com/archive/blogs/willpe/getting-started-with-service-bus-v2-october-ctp-connection-points</link>
      <pubDate>Mon, 01 Nov 2010 15:13:41 GMT</pubDate>
      <dc:creator><![CDATA[willpe]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/willpe/2010/11/01/getting-started-with-service-bus-v2-october-ctp-connection-points/</guid>
      <description><![CDATA[Last week at PDC we released a Community Technology Preview (CTP) of a new version of Windows Azure...]]></description>
      <content:encoded><![CDATA[<p>Last week at PDC we released a Community Technology Preview (CTP) of a new version of <a href="http://portal.appfabriclabs.com/">Windows Azure AppFabric</a> Service Bus. You can download the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d89640fc-c552-446e-aead-b1e0d940f31b&amp;displaylang=en">SDK, Samples and Help</a> on the Microsoft Download Center. There’s plenty new in this release and the first is the notion of <strong>Explicit Connection Point Management</strong>. In v1 whenever you started up a service and relayed it through the cloud over service bus we just quietly cooperated – this seems like a great idea until you think about a couple of advanced scenarios: Firstly: what happens when your service is offline but a sender (client) tries to connect to it? Well, we don’t know if the service is offline or the address is wrong (and there’s no way to differentiate); there’s no way to determine what’s a valid service connection point and what isn’t. There’s also no way to specify metadata about the service that connects (this is a HTTP endpoint, this endpoint is only Oneway). Also, you might have noticed that we added support for Anycast in v2 – how can you determine which connection points are Unicast (one listener/server and many senders/clients) and which are unicast (many load-balanced listeners and many clients)? That’s what connection points are for.</p>  <p>A Connection Point defines the metadata for a Service Bus connection. This includes the <strong>Shape</strong> (Duplex, RequestReply, Http or Oneway) and <strong>Maximum Number of Listeners</strong> and the <strong>Runtime Uri</strong> which acts as the service endpoint. Connection Points are managed as an Atom Feed using standard REST techniques. You’ll find the feed at the Connection Point Management Uri (<a href="https://&lt;YourServiceNamespace&gt;-mgmt.servicebus.appfabriclabs.com/Resources/ConnectionPoints">-mgmt.servicebus.appfabriclabs.com/Resources/ConnectionPoints&quot;&gt;https://&lt;YourServiceNamespace&gt;-mgmt.servicebus.appfabriclabs.com/Resources/ConnectionPoints</a>)<sup>1</sup> and it’ll look at little bit like this:</p>  <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><font size="2"><span style="color: "><font color="#0000ff"><font style="font-size: ">&lt;</font></font></span><font style="font-size: "><span style="color: "><font color="#a31515">feed</font></span><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">xmlns</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">http://www.w3.org/2005/Atom</font></span><font color="#000000">&quot;</font></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160; &lt;</span></font><span style="color: "><font color="#a31515">title</font></span><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">type</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">text</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000">ConnectionPoints</font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">title</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160; &lt;</span></font><span style="color: "><font color="#a31515">subtitle</font></span><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">type</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">text</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000">This is the list of ConnectionPoints currently available</font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">subtitle</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160; &lt;</span></font><span style="color: "><font color="#a31515">id</font></span><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000">https://willpe-blog-mgmt.servicebus.appfabriclabs.com/Resources/ConnectionPoints</font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">id</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160; &lt;</span></font><span style="color: "><font color="#a31515">updated</font></span><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000">2010-11-01T20:53:53Z</font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">updated</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160; &lt;</span></font><span style="color: "><font color="#a31515">generator</font></span><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000">Microsoft Windows Azure AppFabric - Service Bus</font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">generator</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160; &lt;</span></font><span style="color: "><font color="#a31515">link</font></span><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">rel</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">self</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">&#160;<br />        </font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><strong><span style="color: "><font color="#ff0000">href</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">https://willpe-blog-mgmt.servicebus.appfabriclabs.com/Resources/ConnectionPoints</font></span><font color="#000000">&quot;</font></strong></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">/&gt;</span><br /><span style="color: ">&#160; &lt;</span></font><span style="color: "><font color="#a31515">entry</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160;&#160;&#160; &lt;</span></font><span style="color: "><font color="#a31515">id</font></span><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000">https://willpe-blog-mgmt.servicebus.appfabriclabs.com/Resources/ConnectionPoints(TestConnectionPoint)</font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">id</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160;&#160;&#160; &lt;</span></font><span style="color: "><font color="#a31515">title</font></span><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">type</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">text</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000"><strong>TestConnectionPoint</strong></font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">title</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160;&#160;&#160; &lt;</span></font><span style="color: "><font color="#a31515">published</font></span><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000">2010-11-01T20:51:11Z</font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">published</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160;&#160;&#160; &lt;</span></font><span style="color: "><font color="#a31515">updated</font></span><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000">2010-11-01T20:51:11Z</font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">updated</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160;&#160;&#160; &lt;</span></font><span style="color: "><font color="#a31515">link</font></span><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">rel</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">self</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">&#160;<br />          </font></span><strong><span style="color: "><font color="#ff0000">href</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">https://willpe-blog-mgmt.servicebus.appfabriclabs.com/Resources/ConnectionPoints(TestConnectionPoint)</font></span><font color="#000000">&quot;</font></strong></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">/&gt;</span><br /><span style="color: ">&#160;&#160;&#160; &lt;</span></font><span style="color: "><font color="#a31515">link</font></span><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">rel</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">alternate</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#ff0000"><br />          <strong>href</strong></font></span><strong><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">sb://willpe-blog.servicebus.appfabriclabs.com/services/testconnectionpoint</font></span><font color="#000000">&quot;</font></strong></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">/&gt;</span><br /><span style="color: ">&#160;&#160;&#160; &lt;</span></font><span style="color: "><font color="#a31515">content</font></span><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">type</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">application/xml</font></span><font color="#000000">&quot;</font></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160; <strong>&lt;</strong></span></font><strong><span style="color: "><font color="#a31515">ConnectionPoint</font></span><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">xmlns</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;&quot;</font><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">xmlns:xsd</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">http://www.w3.org/2001/XMLSchema</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">&#160;</font></span><span style="color: "><font color="#ff0000">xmlns:xsi</font></span><span style="color: "><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span style="color: "><font color="#0000ff">http://www.w3.org/2001/XMLSchema-instance</font></span><font color="#000000">&quot;</font></strong></font></font><font face="Consolas"><font size="2"><strong><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span></font><span style="color: "><font color="#a31515">MaxListeners</font></span><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000">2</font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">MaxListeners</font></span></strong></font></font><font face="Consolas"><font size="2"><strong><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span></font><span style="color: "><font color="#a31515">ChannelShape</font></span><span style="color: "><font color="#0000ff">&gt;</font></span><font color="#000000">RequestReply</font><span style="color: "><font color="#0000ff">&lt;/</font></span><span style="color: "><font color="#a31515">ChannelShape</font></span></strong></font></font><font face="Consolas"><font size="2"><strong><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160; &lt;/</span></font><span style="color: "><font color="#a31515">ConnectionPoint</font></span></strong></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><strong><span style="color: ">&gt;</span><br /></strong><span style="color: ">&#160;&#160;&#160; &lt;/</span></font><span style="color: "><font color="#a31515">content</font></span></font></font><font face="Consolas"><font size="2"><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&#160; &lt;/</span></font><span style="color: "><font color="#a31515">entry</font></span></font></font></font><font face="Consolas"><font size="2"><font style="font-size: "><font color="#0000ff"><span style="color: ">&gt;</span><br /><span style="color: ">&lt;/</span></font><span style="color: "><font color="#a31515">feed</font></span></font><span style="color: "><font style="font-size: " color="#0000ff">&gt;</font></span></font></font></pre>

<p>Writing some code to get your list of connection points is easy – in the rest of this post, I’ll show you how to (very simply) List, Create and Delete connection points. Before getting started, make sure that you’ve installed the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d89640fc-c552-446e-aead-b1e0d940f31b&amp;displaylang=en">October 2010 Windows Azure AppFabric SDK</a> then create a new .Net Framework 4.0 (Full) Console Application in Visual Studio 2010.</p>

<ol>
  <li>Add a reference to the <strong>Microsoft.ServiceBus.Channels</strong> assembly (its in the GAC, or at <em>C:\Program Files\Windows Azure AppFabric SDK\V2.0\Assemblies\Microsoft.ServiceBus.Channels.dll</em> if you need to find it on disk) </li>

  <li>Add 3 string constant containing your Service Namespace, Default Issuer Name and Default Issuer Key. You can get this information over at the <a href="http://portal.appfabriclabs.com/">Windows Azure AppFabric Portal</a>: 

    <br />

    <br /><font face="Consolas"><font size="2"><font style="font-size: "><span style="color: "><font color="#0000ff">&#160;&#160;&#160; private</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">const</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> serviceNamespace = </font><span style="color: "><font color="#a31515">&quot;&lt;YourServiceNamespace&gt;&quot;</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#000000">; 
            <br /></font><span style="color: "><font color="#0000ff">&#160;&#160;&#160; private</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">const</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> username = </font><span style="color: "><font color="#a31515">&quot;owner&quot;</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="2"><font color="#000000">; 
            <br /></font><span style="color: "><font color="#0000ff">&#160;&#160;&#160; private</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">const</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> password = </font><span style="color: "><font color="#a31515">&quot;base64base64base64base64base64base64base64==&quot;</font></span><font color="#000000">; 
            <br /></font></font></font></font></li>

  <li>Now define the hostname of your service bus management service (you can find this in the <a href="http://portal.appfabriclabs.com/">portal</a>, too): 

    <br />

    <br /><font size="2"><font face="Consolas"><span style="color: "><font color="#0000ff"><font style="font-size: ">&#160;&#160;&#160; private</font></font></span><font style="font-size: "><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">static</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">readonly</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> ManagementHostName = serviceNamespace + </font><span style="color: "><font color="#a31515">&quot;-mgmt.servicebus.appfabriclabs.com&quot;</font></span><font color="#000000">;</font></font></font> 

      <br /></font><!--endfragment--></!--endfragment--></li>
</ol>

<p>Access to Service Bus Management is controlled by the Access Control Service. You’ll need to present the ‘<em>net.windows.servicebus.action</em>’ claim with a value ‘<em>Manage</em>’ in order to have permission to Create, Read and Delete connection points. The default issuer (owner) is configured to have this permission by default when you provision a new account.</p>

<p>We’ll need to go ahead and get a Simple Web Token from the Access Control Service for our request. Note that, by default, the realm (relying party address) used for service bus management has the <strong>http</strong> scheme: you must retrieve a token for the management service using a Uri with the default port and http scheme even though you will in fact connect to the service over https:</p>

<ol>
  <li>Get an auth token from ACS<sup>2</sup> for the management service’s realm (remember, this must specify an <strong>http</strong> scheme): 

    <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><font size="2"><span style="color: "><font color="#0000ff"><font style="font-size: ">    string</font></font></span><font style="font-size: "><font color="#000000"> authToken = GetAuthToken(</font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">Uri</font></span><font color="#000000">(</font><span style="color: "><font color="#a31515">&quot;http://&quot;</font></span><font color="#000000"> + ManagementHostName + </font><span style="color: "><font color="#a31515">&quot;/&quot;</font></span><font color="#000000">));</font></font></font></font></pre>
  </li>

  <li>Add the token to the Authorization Header of a new WebClient and download the feed: – note that here we specify <strong>https</strong>)&#160; <br />

    <br /><font face="Consolas"><font size="2"><font color="#000000"><font style="font-size: ">&#160;&#160;&#160; </font></font><font style="font-size: "><span style="color: "><font color="#0000ff">using</font></span><font color="#000000"> (</font><span style="color: "><font color="#2b91af">WebClient</font></span><font color="#000000"> client = </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">WebClient</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#000000">()) 
            <br />&#160;&#160;&#160; { 

            <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; client.Headers.Add(</font><span style="color: "><font color="#2b91af">HttpRequestHeader</font></span><font color="#000000">.Authorization, </font><span style="color: "><font color="#a31515">&quot;WRAP access_token=\&quot;&quot;</font></span><font color="#000000"> + authToken + </font><span style="color: "><font color="#a31515">&quot;\&quot;&quot;</font></span></font></font><font face="Consolas"><font size="2"><font color="#000000">); 
            <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: "><font color="#0000ff">var</font></span><font color="#000000"> feedUri = <span style="color: "><font color="#a31515">&quot;https://&quot;</font></span><font color="#000000"> + ManagementHostName + </font><span style="color: "><font color="#a31515">&quot;/Resources/ConnectionPoints&quot;;</font></span></font></font></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#000000"> 
            <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">var</font></span><font color="#000000"> connectionPoints = client.DownloadString(feedUri</font></font></font></font><font face="Consolas"><font style="font-size: "><font size="2"><font color="#000000">); 
            <br />

            <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">Console</font></span></font><font color="#000000" size="2">.WriteLine(connectionPoints); 
          <br />&#160;&#160;&#160; } </font></font></font></li>
</ol>

<p>Compile and run the app to see your current connection points (probably none). Now lets go ahead and create a Connection Point – to do this we just Post an Atom entry to the ConnectionPoint Management service. You can achieve this using classes from the System.ServiceModel.Syndication namespace<sup>3</sup> but for clarity and simplicity we’ll stick to just using a big old block of xml encoded as a string – its not pretty this way, but it gets the job done!</p>

<ol>
  <li>Define the properties of the new Connection Point – you need to specify a name (alphanumeric), the maximum number of listeners, a channel shape (Duplex, Http, Oneway or RequestReply) and the endpoint address (sometimes called a Runtime Uri) for the service: 
    <br />

    <br /><font face="Consolas"><font size="2"><font color="#000000"><font style="font-size: ">&#160;&#160;&#160; </font></font><font style="font-size: "><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> connectionPointName = </font><span style="color: "><font color="#a31515">&quot;TestConnectionPoint&quot;</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#000000">; 
            <br /></font></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#000000">&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">int</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="2"><font color="#000000"> maxListeners = 2; 
            <br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> channelShape = </font><span style="color: "><font color="#a31515">&quot;RequestReply&quot;</font></span><font color="#000000">; 
            <br /></font></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#000000">&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">Uri</font></span><font color="#000000"> endpointAddress = </font><span style="color: "><font color="#2b91af">ServiceBusEnvironment</font></span><font color="#000000">.CreateServiceUri( 
            <br /></font></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><span style="color: "><font color="#a31515"><font style="font-size: "><font face="Consolas"><font size="2"><span style="color: "><font color="#a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></font></font></font>&quot;sb&quot;</font></span><font color="#000000">, serviceNamespace, </font><span style="color: "><font color="#a31515">&quot;/services/TestConnectionPoint&quot;</font></span></font></font><font face="Consolas"><font size="2"><font color="#000000">); 
            <br />

            <br /></font></font></font></font></li>

  <li>Now, go ahead and define the new Atom Entry for the connection point. Note how the name is set as the entry’s title and the endpoint address is set as an alternate link for the entry. 
    <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><font size="2"><font color="#000000"><font style="font-size: ">&#160;&#160;&#160; </font></font><font style="font-size: "><span style="color: "><font color="#0000ff">var</font></span><font color="#000000"> entry = </font></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#a31515"><span style="color: ">@&quot;&lt;entry xmlns=&quot;&quot;http://www.w3.org/2005/Atom&quot;&quot;&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;id&gt;uuid:04d8d317-511c-4946-bc1d-6f49b6f66385;id=3&lt;/id&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;title type=&quot;&quot;text&quot;&quot;&gt;&quot;</span></font><font color="#000000"> + connectionPointName + </font></font></font><font face="Consolas"><font size="2"><font color="#a31515"><span style="color: ">@&quot;&lt;/title&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;link rel=&quot;&quot;alternate&quot;&quot; href=&quot;&quot;&quot;</span></font><font color="#000000"> + endpointAddress + </font></font></font><font face="Consolas"><font size="2"><font color="#a31515"><span style="color: ">@&quot;&quot;&quot; /&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;updated&gt;2010-11-01T20:44:08Z&lt;/updated&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;content type=&quot;&quot;application/xml&quot;&quot;&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;ConnectionPoint xmlns:i=&quot;&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&quot; xmlns=&quot;&quot;&quot;&quot;&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;MaxListeners&gt;&quot;</span></font><font color="#000000"> + maxListeners + </font></font></font><font face="Consolas"><font size="2"><font color="#a31515"><span style="color: ">@&quot;&lt;/MaxListeners&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;ChannelShape&gt;&quot;</span></font><font color="#000000"> + channelShape + </font></font></font></font><font face="Consolas"><font style="font-size: "><font size="2"><font color="#a31515"><span style="color: ">@&quot;&lt;/ChannelShape&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/ConnectionPoint&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/content&gt;</span><br /><span style="color: ">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/entry&gt;&quot;</span></font><font color="#000000">;</font></font></font></font></pre>
  </li>

  <li>Create a HttpWebRequest, add the ACS Auth Token, set the Http Method to Post and configure the content type as ‘<em>application/atom+xml</em>’: 

    <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><font style="font-size: "><font size="2"><span style="color: "><font color="#0000ff">    var</font></span><font color="#000000"> request = </font><span style="color: "><font color="#2b91af">HttpWebRequest</font></span><font color="#000000">.Create(</font><span style="color: "><font color="#a31515">&quot;https://&quot;</font></span><font color="#000000"> + ManagementHostName + </font><span style="color: "><font color="#a31515">&quot;/Resources/ConnectionPoints&quot;</font></span><font color="#000000">) </font><span style="color: "><font color="#0000ff">as</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">HttpWebRequest</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#000000">;<br />&#160;&#160;&#160; request.Headers.Add(</font><span style="color: "><font color="#2b91af">HttpRequestHeader</font></span><font color="#000000">.Authorization, </font><span style="color: "><font color="#a31515">&quot;WRAP access_token=\&quot;&quot;</font></span><font color="#000000"> + authToken + </font><span style="color: "><font color="#a31515">&quot;\&quot;&quot;</font></span></font></font><font face="Consolas"><font size="2"><font color="#000000">);<br />&#160;&#160;&#160; request.ContentType = </font><span style="color: "><font color="#a31515">&quot;application/atom+xml&quot;</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="2"><font color="#000000">;<br />&#160;&#160;&#160; request.Method = </font><span style="color: "><font color="#a31515">&quot;POST&quot;</font></span><font color="#000000">;</font></font></font></font></pre>
  </li>

  <li>Finally, write the new atom entry to the request stream and retrieve the response. You’ll discover an atom entry describing your newly created connection point in that response: 
    <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><font size="2"><font color="#000000"><font style="font-size: ">&#160;&#160;&#160; </font></font><font style="font-size: "><span style="color: "><font color="#0000ff">using</font></span><font color="#000000"> (</font><span style="color: "><font color="#0000ff">var</font></span><font color="#000000"> writer = </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">StreamWriter</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#000000">(request.GetRequestStream()))<br />&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; writer.Write(entry);<br />&#160;&#160;&#160; }<br /> <br />&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">WebResponse</font></span></font></font><font face="Consolas"><font size="2"><font color="#000000"> response = request.GetResponse();<br />&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">Stream</font></span></font></font><font face="Consolas"><font size="2"><font color="#000000"> responseStream = response.GetResponseStream();<br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">var</font></span><font color="#000000"> connectionPoint = </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">StreamReader</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="2"><font color="#000000">(responseStream).ReadToEnd();<br />&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">Console</font></span><font color="#000000">.WriteLine(connectionPoint);</font></font></font></font></pre>
  </li>
</ol>

<p>If you re-run your application now, you’ll see that you’ve created a connection point which is listed in the feed we retrieved earlier. The last thing to do now is clean up after ourselves by issuing a delete against the resource we just created:</p>

<ol>
  <li>Connection Point management addresses are similar to <a href="http://www.odata.org/developers/protocols/uri-conventions#AddressingEntries">OData</a> addresses – we address the specific connection point to delete by appending the connection point management Uri with the name of the item to delete in parenthesis: 

    <br />

    <br /><font face="Consolas"><font size="2"><span style="color: "><font color="#0000ff"><font style="font-size: ">&#160;&#160;&#160; var</font></font></span><font style="font-size: "><font color="#000000"> connectionPointManagementAddress&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; = </font><span style="color: "><font color="#a31515">&quot;https://&quot;</font></span><font color="#000000"> + ManagementHostName + </font><span style="color: "><font color="#a31515">&quot;/Resources/ConnectionPoints(&quot;</font></span><font color="#000000"> + connectionPointName + </font><span style="color: "><font color="#a31515">&quot;)&quot;</font></span><font color="#000000">;</font></font></font></font> 

    <br /></li>

  <li>Add the ACS auth token to the header of a WebClient and issue a <em>Delete</em> against the entry: 

    <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><font size="2"><span style="color: "><font color="#0000ff"><font style="font-size: ">    using</font></font></span><font style="font-size: "><font color="#000000"> (</font><span style="color: "><font color="#2b91af">WebClient</font></span><font color="#000000"> client = </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">WebClient</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="2"><font color="#000000">())<br />&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160; client.Headers.Add(</font><span style="color: "><font color="#2b91af">HttpRequestHeader</font></span><font color="#000000">.Authorization, </font><span style="color: "><font color="#a31515">&quot;WRAP access_token=\&quot;&quot;</font></span><font color="#000000"> + authToken + </font><span style="color: "><font color="#a31515">&quot;\&quot;&quot;</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="2"><font color="#000000">);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; client.UploadString(connectionPointManagementAddress, </font><span style="color: "><font color="#a31515">&quot;DELETE&quot;</font></span><font color="#000000">, </font><span style="color: "><font color="#0000ff">string</font></span></font><font color="#000000" size="2">.Empty);<br />&#160;&#160;&#160; }</font></font></font></pre>
  </li>
</ol>

<p>So, there we go: Listing, Creating and Deleting Connection Points. Download the full example from Skydrive:</p>
<center><iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-f417b199bb8eca27.office.live.com/embedicon.aspx/.Public/Blog/ConnectionPoints.zip" frameborder="0" marginwidth="0" scrolling="no"></iframe></center>

<p>___ </p>

<p><sup>1</sup> You’ll need to have a WRAP token in the Http Authorization Header to access this resource, so you can’t just navigate to it in a browser.</p>

<p><sup>2</sup> Read more about the Access Control Service at Justin Smith’s blog. Sample code to retrieve a token is included in the download at the end of this post.</p>

<p><sup>3</sup> An example of using the Syndication primitives to manipulate connection points is available in the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d89640fc-c552-446e-aead-b1e0d940f31b&amp;displaylang=en">October 2010 Windows Azure AppFabric Sample</a> ‘ManagementOperations’</p>]]></content:encoded>
    </item>
    <item>
      <title>Windows Authentication, ADFS and the Access Control Service</title>
      <link>https://docs.microsoft.com/archive/blogs/willpe/windows-authentication-adfs-and-the-access-control-service</link>
      <pubDate>Mon, 25 Oct 2010 11:56:17 GMT</pubDate>
      <dc:creator><![CDATA[willpe]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/willpe/2010/10/25/windows-authentication-adfs-and-the-access-control-service/</guid>
      <description><![CDATA[Its just a few weeks ago that I started looking in more detail at the Windows Azure AppFabric Access...]]></description>
      <content:encoded><![CDATA[<p>Its just a few weeks ago that I started looking in more detail at the <a href="http://portal.appfabriclabs.com/">Windows Azure AppFabric Access Control Service</a> (or just ACS to its friends) and one of the first things I wanted to figure out was how to federate between my on-premise Active Directory domain and ACS. With a few pointers, its not too tricky, but I figured I’d walk you through the whole process anyhow!</p>  <p>I’m going to assume that you’ve got an account set up with AppFabric Labs (<a href="http://portal.appfabric.labs.com">http://portal.appfabric.labs.com</a>) and an Active Directory domain installed too – if you don’t (or you want play about on a test domain) then just spin up a <a href="http://www.microsoft.com/windowsserver2008/en/us/virtual-hard-drive.aspx">VM running Windows Server 2008 (or R2)</a> and <a href="http://technet.microsoft.com/en-us/library/cc755059(WS.10).aspx">Install Active Directory Domain Services</a>.</p>  <p>Here’s what we’ll do:</p>  <ol>   <li>Download and Install <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=118c3588-9070-426a-b655-6cec0a92c10b&amp;displaylang=en">Active Directory Federation Services</a> (ADFS) v2.0 </li>    <li>Configure a certificate to use with ADFS </li>    <li>Setup ADFS and enable Endpoints for Windows Authentication </li>    <li>Establish a Trust relationship from ADFS to ACS </li>    <li>Provision a Service Namespace&#160; X.509 Certificate in ACS </li>    <li>Establish a Trust relationship from ACS to ADFS </li>    <li>Create Rules to pass through claims from ADFS to the Relying Party Application via ACS </li>    <li>Use the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=eb9c345f-e830-40b8-a5fe-ae7a864c4d76&amp;displaylang=en">Windows Identity Foundation</a> (WIF) to get a SAML token from ADFS </li>    <li>Submit the SAML token to ACS to retrieve a set of claims as a SWT token </li> </ol>  <p><strong>Download and Install ADFS v2</strong></p>  <ol>   <li>Download the appropriate version of the ADFS v2 update from the <a href="http://www.microsoft.com/downloads/en/details.aspx?familyId=118C3588-9070-426A-B655-6CEC0A92C10B&amp;hash=quA8ErERAs1emw5OYr3veGAzKaOtoVMhZ2gbuOFkLsBIs3H1Cd29vIAxrZiPGu7Gba24wnHuNGXPzvxp8mcryg%3d%3d">Microsoft Download Center</a>. </li>    <li>Install ADFS, you’ll probably want to Install a <strong>Federation Server.</strong> </li>    <li>When setup completes, launch the AD FS 2.0 management console. </li> </ol>  <p><strong>Create a Self-Signed SSL Certificate</strong></p>  <p>Before you can configure ADFS you’ll need an SSL Certificate configured on your machine – if you have one already, skip ahead to the next step. Otherwise take you can setup a self-signed (untrusted) certificate using IIS. It goes without saying that you shouldn’t use a self-signed certificate in a production environment!</p>  <ol>   <li>Open the IIS Management Console </li>    <li>In the Connections pane on the left hand side, select your server </li>    <li>Double click on Server Certificates then select ‘Create Self-Signed Certificate’ from the actions pane on the right:      <br />      <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/07/11/metablogapi/6685.image_714AC500.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-07-11-metablogapi/6685.image_5F00_714AC500.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; float: ; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/07/11/metablogapi/8322.image_thumb_353E834B.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-07-11-metablogapi/8322.image_5F00_thumb_5F00_353E834B.png" width="639" height="227" /></a>       <br /></li>    <li>Type a name for the certificate – I’ve named mine ‘Self-Signed Certificate’ (creative, huh?) </li> </ol>  <p><strong>Configure ADFS and Enable Windows Authentication Endpoints</strong></p>  <ol>   <li>From the <strong>AD FS 2.0 Management</strong> console, start the <strong>Server Configuration Wizard</strong>       <ol>       <li>Create a <strong>New Federation Service</strong> on a <strong>Stand-alone federation server</strong>. </li>        <li>In the third step, choose your <strong>Self-Signed Certificate</strong> – of course, if you already have a trusted, chained certificate for your server, you should use that instead! </li>        <li>Click <strong>Finish</strong> and ADFS will compete the configuration of your new Federation Server </li>     </ol>   </li>    <li>Next, we’ll enable some Endpoints to allow us to retrieve SAML tokens from ADFS using our Windows Credentials. We’ll do this over the WS-Trust 1.3 Protocol using Transport Security with a Message Credential.      <ol>       <li>Expand the <strong>Service</strong> element of the navigation pane (left) and select <strong>Endpoints</strong> </li>        <li>Scroll down the list and select the <strong>/adfs/services/trust/13/windowsmixed</strong> endpoint – right click and <strong>Enable</strong> it.           <br />          <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/07/11/metablogapi/6114.image_3AACF3EF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-07-11-metablogapi/6114.image_5F00_3AACF3EF.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/07/11/metablogapi/8836.image_thumb_1A25B43D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-07-11-metablogapi/8836.image_5F00_thumb_5F00_1A25B43D.png" width="641" height="70" /></a>           <br /></li>        <li>You’ll be alerted that you need to restart the AD FS 2.0 Service – open up the Services manager (services.msc) and restart the AD FS 2.0 Windows Service. You can read more about the various available <a href="http://technet.microsoft.com/en-us/library/adfs2-help-endpoints(WS.10).aspx">ADFS endpoints on TechNet</a>. </li>     </ol>   </li> </ol>  <p><strong>Establish a Trust relationship from ADFS to ACS</strong></p>  <p>So, ADFS is now acting as an STS (Security Token Service) for your Active Directory domain, this means that you’re ready to setup federated authentication with other STSs or Identity Providers like the Windows Azure AppFabric Access Control Service (ACS). To do that, we need to establish a bidirectional trust relationship between ADFS and ACS – this allows your ACS project to process incoming tokens from your Active Directory and ensure that Active Directory trusts ACS and will issue tokens for use with it. We’ll be using AppFabric Labs for this – its free, so go <a href="https://portal.appfabriclabs.com/Default.aspx?wa=wsignin1.0">Sign Up</a> for an account if you don’t have one already.</p>  <ol>   <li>Visit the <a href="http://portal.appfabriclabs.com/">Windows Azure AppFabric Portal</a>. Click on your project to bring up a list of your service namespaces, then choose ‘<strong>Access Control</strong>’ from the service namespace you want to issue tokens for from ADFS:       <br />      <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/07/11/metablogapi/3058.image_1D579C25.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-07-11-metablogapi/3058.image_5F00_1D579C25.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/07/11/metablogapi/5518.image_thumb_7C64297D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-07-11-metablogapi/5518.image_5F00_thumb_5F00_7C64297D.png" width="648" height="143" /></a>       <br /></li>    <li>On the next page, click the big, orange ‘<strong>Manage</strong>’ button to view the Access Control Service management UI. On the left, you’ll see a set of links directing you to common ACS Administrative tasks: </li>    <li>To add a new Identity Provider to your ACS Service Namespace you (unsuprisingly) use the <strong>Identity Providers</strong> link </li>    <li>Choose ‘<strong>Add Identity Provider</strong>’ </li>    <li>Since we just spent a while setting up ADFS, you’ll want to Add a ‘<strong>Microsoft Active Directory Federation Services 2.0</strong>’ Identity Provider </li>    <li>Choose a sensible display name (or a wacky one if like, its really up to you) </li>    <li>Upload some Federation Metadata.      <ul>       <li><em>If (like me) you’re using an ADFS installation which doesn’t have an Internet Facing IP Address (i.e., there’s no way to access your ADFS server from the public internet) then you’ll want to save a copy of your federation metadata as a UTF-8 Xml file and use the upload button. You can find the metadata at </em><a href="https://[Your-ADFS-Server]/FederationMetadata/2007-06/FederationMetadata.xml"><strong><em>https://[Your-ADFS-Server]/FederationMetadata/2007-06/FederationMetadata.xml</em></strong></a><em>.</em> </li>     </ul>   </li>    <li>Specify a login-link name (the Display Name is probably a good choice!) </li>    <li>Click ‘<strong>Save</strong>’ </li>    <li>You’re returned to the list of Identity Providers, but now it contains your ADFS STS – simple, huh? </li> </ol>  <p>Next, we need to perform a very similar process on your ADFS server, establishing a trust relationship back to ACS.</p>  <p><strong>Establish a Trust relationship from ACS to ADFS</strong></p>  <p>ADFS won’t issue tokens for use against the Access Control Service if it doesn’t trust it – we’ll need to configure a default signing certificate in ACS, generate some Federation Metadata and share that with our ADFS instance to finish off the establishment of this trust relationship.</p>  <ol>   <li>Use the steps above to get to the <strong>Access Control Management</strong> page for your service namespace. </li>    <li>In the ‘<strong>Develop</strong>’ area, click on ‘<strong>Application Integration</strong>’ </li>    <li>Towards the bottom of this page, you’ll see an Endpoint Reference for <strong>WS-Federation Metadata</strong> – copy and paste the link into your address bar and hit enter. </li>    <li>At this point, you’ll either see some Federation Metadata or – more likely – a wonderful error message, if you don’t see the error, skip ahead to Step 15:      <br />      <br />      <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/07/11/metablogapi/3542.image_5B70B6D6.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-07-11-metablogapi/3542.image_5F00_5B70B6D6.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/07/11/metablogapi/2860.image_thumb_48BBBD1F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-07-11-metablogapi/2860.image_5F00_thumb_5F00_48BBBD1F.png" width="437" height="128" /></a>       <br /></li>    <li>This happens because you don’t have a default certificate configured for signing – we’ll go upload one and then gain access to our precious metadata. </li>    <li>Go back to the <strong>Access Control Management</strong> page and click <strong>Certificates and Keys</strong> </li>    <li>You need to <strong>Add a Token Signing Certificate</strong>, so click on the relevant link </li>    <li>Ensure that X.509 is selected as the certificate type and enter a name. </li>    <li>You’ll need to generate a certificate which you can do using the MakeCert tool which is part of the Windows SDK (if you have VS2010, you already have this installed, just start a Visual Studio Command Prompt and type ‘MakeCert’.      <ul>       <li><em>MakeCert.exe -r -pe -n &quot;CN=<strong>&lt;Your-Service-Namespace&gt;</strong>.accesscontrol.appfabriclabs.com&quot; -sky exchange -ss my</em> </li>     </ul>   </li>    <li>In the same command prompt window, use CertUtil to find and then export the certificate you just created:      <ol>       <li>Run CertUtil to retrieve details of the certificate that was just created. Note down the <strong>SHA1 Cert Hash</strong> (it’s a hex string like: b4 24 b5 c2 ef 40 5c 26 76 38 12 02 95 c1 56 5f 18 25 4f):           <ul>           <li><em>CertUtil -user -store My <strong>&lt;Your-Service-Namespace&gt;</strong>.accesscontrol.appfabriclabs.com</em> </li>         </ul>       </li>        <li>Run CertUtil again to export the private key. You need to specify a password, the SHA1 hash and a filename for the PFX that will be created:          <ul>           <li><em>CertUtil -user –p <strong>&lt;Some-Password&gt;</strong> –exportpfx “<strong>&lt;Your-SHA1-Cert-Hash&gt;</strong>” <strong>&lt;Output-Filename.pfx&gt;</strong></em> </li>         </ul>       </li>     </ol>   </li>    <li>Back at the portal, upload the private key (.pfx) file you just creates and enter the password you specified to CertUtil </li>    <li>In the <strong>Used For</strong> field, specify <strong>Service Namespace</strong> </li>    <li>Click <strong>Save</strong> </li>    <li>Browse back to the metadata URL from step 4: this time, no error and lots of lovely metadata! </li>    <li>If your ADFS server doesn’t have internet access, save this federation metadata to file and transfer it to the ADFS Server </li>    <li>Login to your ADFS Server and Start the <strong>AD FS 2.0 Management Console</strong>. </li>    <li>In the Console Tree (Left), right click on ‘<strong>Relying Party Trusts</strong>’ under the ‘Trust Relationships’ node and choose ‘<strong>Add Relying Party Trust</strong>’. </li>    <li>A wizard pops up, skip past the welcome page to ‘Select Data Source’ and either enter the URI of your federation metadata (something like: <a href="https://&lt;Your-Service-Namespace&gt;.accesscontrol.appfabriclabs.com/FederationMetadata/2007-06/FederationMetadata.xml">.accesscontrol.appfabriclabs.com/FederationMetadata/2007-06/FederationMetadata.xml&quot;&gt;https://&lt;Your-Service-Namespace&gt;.accesscontrol.appfabriclabs.com/FederationMetadata/2007-06/FederationMetadata.xml</a>)&#160; or upload the xml document if you saved it in step 15. </li>    <li>Specify a display name and choose your issuance rules policy – for simplicity’s sake I’m going to select ‘<strong>Permit All Users to Access this Relying Party</strong>’ </li>    <li>On the next page, confirm all the data you’ve entered and hit finish. </li> </ol>  <p>When you’re done, leave the ‘Open the Edit Claim Rules dialog’ option checked – we’ll use this dialog to add some rules to this trust relationship allowing data to flow from Active Directory and into ACS. To get back to this dialog, right click on the Relying Party Trust for ACS and click <strong>‘Edit Claim Rules’</strong></p>  <ol>   <li>On the <strong>Issuance Transform Rules</strong> tab, click <strong>Add Rule</strong>. </li>    <li>Select <strong>‘Pass Through or Filter an Incoming Claim’</strong> as the template to use and click Next </li>    <li>Now we’ll configure a claim (i.e. piece of identity data like role membership, username, etc.) to be passed through to ACS – just select the claim from the drop down list, specify a name and click Finish:      <br />      <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/07/11/metablogapi/0815.image_60DF277A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-07-11-metablogapi/0815.image_5F00_60DF277A.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/07/11/metablogapi/2134.image_thumb_74F84403.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-07-11-metablogapi/2134.image_5F00_thumb_5F00_74F84403.png" width="520" height="277" /></a>       <br /></li>    <li>Repeat steps 1-thru-3 to add additional claims to pass thru to ACS (if you feel like it!) </li> </ol>  <p>At this point, some congratulations are in order: you’ve installed and configured ADFS, you’ve created and uploaded a certificate to allow signing of your ACS Federation Metadata, you’ve established a bi-directional trust relationship between ADFS and ACS and you’ve specified some claims which can be passed through to the Access Control Service. There’s just a little more work ahead of you before you can perform that first piece of federated, claims-based authentication.</p>  <ol>   <li>Head back over to the Windows Azure AppFabric portal and get yourself back to the Access Control Service Management page we’ve been using in the past couple of sections. This time, click the ‘<strong>Rule Groups</strong>’ link. </li>    <li>Select the rule group you want to modify.      <ul>       <li><em>Rule Groups define how claims from one party are transformed by the Access Control Service before being passed on to another (for example, only passing through the ‘First name’ claim from Facebook or ADFS to a service located at a specific Url). You associate Rule Groups with Realms (that is, the URI of a resource which is secured by the Access Control Service) on the Replying Party Application page. By default, there’s just one Rule Group and just one Relying Party Application. Feel free to add more!</em> </li>     </ul>   </li>    <li>Add a rule to the rule group with the ‘<strong>Add Rule</strong>’ link- we’re going to configure the windows account name to pass through, but you can repeat this process to forward or transform as many claims as you want/need (full name, email address, etc.). </li>    <li>Specify the incoming claim details in the ‘<strong>If…</strong>’ section. In the <strong>Claims Issuer</strong> area, choose your new ADFS Identity Provider, next choose the <strong>Input claim type</strong> that you want to pass through. I’m going to pass through the Windows Account Name which has the type <em>‘</em><a title="http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname" href="http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname"><em>http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname</em></a><em>’</em>. I’m going to accept any input claim value. </li>    <li>Since we’re just going to pass through this claim (the Windows Account Name), select ‘<strong>Pass through</strong>’ in both the Output Claim Type and Output Claim Value sections. You could (of course) perform more complex rule processing here if you chose to. </li>    <li>Click the <strong>Save</strong> Button </li> </ol>  <p>We’re almost done. Now that we’ve established a claims processing rule (pass through the Windows Account Name) associated with our newly trusted identity provider (your Active Directory Federation Server) we can fire up Visual Studio and write some code. In this next section, we’ll get a SAML Token from ADFS and exchange it for a SWT token via the access control service. Once you’ve got the Simple Web Token (SWT) the Authentication World becomes Your Oyster – go and use it to auth against web services/sites or anything else!</p>  <p><strong>Use the </strong><strong>Windows Identity Foundation</strong><strong> to get a SAML token from ADFS </strong></p>  <p>There are a couple of things we need to do to get a token from ADFS. Firstly, we’ll need to validate that Self-Signed Certificate we created a while ago for securing SSL traffic to and from the ADFS server, secondly we’ll use the Windows Identity Foundation to request the token from an ADFS endpoint.</p>  <ol>   <li>Download and Install the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=EB9C345F-E830-40B8-A5FE-AE7A864C4D76">Windows Identity Foundation</a> (WIF) and <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c148b2df-c7af-46bb-9162-2c9422208504">Windows Identity Foundation SDK</a>. </li>    <li>Create a new .Net Framework 4.0 Console Application in Visual Studio 2010 </li>    <li>Add References to the <strong>Microsoft.IdentityModel</strong>, <strong>System.IdentityModel</strong> and <strong>System.ServiceModel</strong> assemblies. </li>    <li>Add a method, , to validate the SSL Certificate from ADFS (since the certificate we’re using isn’t chained to a root certification authority we’ll need to explicitly say that its OK to trust). Use the code below, but be sure to replace my ADFS server name (vm-willpe-adfs.willpe.sb) with the fully qualified DNS domain name of your ADFS Server:      <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><font size="1"><span style="color: "><font color="#0000ff"><font style="font-size: ">private</font></font></span><font style="font-size: "><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">static</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">bool</font></span><font color="#000000"> RemoteCertificateValidationCallback(</font><span style="color: "><font color="#0000ff">object</font></span><font color="#000000"> sender, </font><span style="color: "><font color="#2b91af">X509Certificate</font></span><font color="#000000"> certificate, </font><span style="color: "><font color="#2b91af">X509Chain</font></span><font color="#000000"> chain, </font><span style="color: "><font color="#2b91af">SslPolicyErrors</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="1"><font color="#000000"> sslPolicyErrors)<br />{<br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">return</font></span><font color="#000000"> sslPolicyErrors == </font><span style="color: "><font color="#2b91af">SslPolicyErrors</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="1"><font color="#000000">.None<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; || </font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000">.Equals(certificate.Issuer, </font><span style="color: "><font color="#a31515">&quot;CN=vm-willpe-adfs.willpe.sb&quot;</font></span><font color="#000000">, </font><span style="color: "><font color="#2b91af">StringComparison</font></span></font><font color="#000000" size="1">.InvariantCultureIgnoreCase);<br />}</font></font></font></pre>
  </li>

  <li>Next, we'll override the default Certificate Validation Callback - add this line to the Main method of Program.cs 
    <pre style="line-height: normal; list-style-type: disc; font-family: "><font size="1"><font face="Consolas"><span style="color: "><font color="#2b91af"><font style="font-size: ">ServicePointManager</font></font></span><font style="font-size: " color="#000000">.ServerCertificateValidationCallback += RemoteCertificateValidationCallback;</font></font><br /></font></pre>
  </li>

  <li>Now we need to make some calls into the Windows Identify Foundation to request a SAML token from ADFS. There are a couple of things to note here. First up, when we enabled endpoints in ADFS, we selected a WS-Trust 1.3 Endpoint with Windows Authentication and Mixed Mode security. This means that we need to use version 1.3 of WS-Trust, specify Windows Credentials and use Transport Security with a Message Credential when connecting. We’ll also have to use the full URL to the endpoint we enabled in ADFS. Here’s the code to create a WS-Trust Channel factory compatible with this endpoint. As usual, don’t forget to change my ADFS hostname (vm-willpe-adfs) to yours: 
    <br />

    <pre style="line-height: normal; list-style-type: disc; font-family: "><br /><font face="Consolas"><font size="1"><font style="font-size: "><span style="color: "><font color="#0000ff">var</font></span><font color="#000000"> stsUrl = </font><span style="color: "><font color="#a31515">&quot;https://vm-willpe-adfs/adfs/services/trust/13/windowsmixed&quot;</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="1"><font color="#000000">;<br /><br /></font><span style="color: "><font color="#2b91af">WSTrustChannelFactory</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000"> trustChannelFactory =<br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">WSTrustChannelFactory</font></span><font color="#000000">(</font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">WindowsWSTrustBinding</font></span><font color="#000000">(</font><span style="color: "><font color="#2b91af">SecurityMode</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">.TransportWithMessageCredential),<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">EndpointAddress</font></span><font color="#000000">(</font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">Uri</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">(stsUrl)));<br /><br /></font></font></font></font><font style="font-size: "><font face="Consolas"><font size="1"><font color="#000000">trustChannelFactory.TrustVersion = </font><span style="color: "><font color="#2b91af">TrustVersion</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">.WSTrust13;<br /> <br />trustChannelFactory.Credentials.Windows.ClientCredential.Domain = </font><span style="color: "><font color="#a31515">&quot;&lt;&lt;Your NetBios Domain Name Here &gt;&gt;</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">;<br />trustChannelFactory.Credentials.Windows.ClientCredential.UserName = </font><span style="color: "><font color="#a31515">@&quot;&lt;&lt;Your Domain Username Here&gt;&gt;&quot;</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="1"><font color="#000000">;<br />trustChannelFactory.Credentials.Windows.ClientCredential.Password = </font><span style="color: "><font color="#a31515">@&quot;&lt;&lt;Your Domain Password Here&gt;&gt;&quot;</font></span><font color="#000000">;</font></font></font></font></pre>
  </li>

  <li>With a trust channel factory instantiated and configured, you can use a RequestSecurityToken to make the token request. Note that you’ll need to specify the Url that the token applies to – this is going to be your ACS Management Url: 
    <br />

    <br />

    <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><span style="color: "><font color="#0000ff"><font style="font-size: " size="1">var</font></font></span><font style="font-size: "><font size="1"><font color="#000000"> acsUrl = </font><span style="color: "><font color="#a31515">&quot;https://willpe-blog.accesscontrol.appfabriclabs.com/&quot;</font></span></font><font color="#000000" size="1">;<br /><br /></font></font></font><span style="color: "><font color="#2b91af" face="Consolas"><font style="font-size: " size="1">RequestSecurityToken</font></font></span><font style="font-size: "><font face="Consolas"><font size="1"><font color="#000000"> rst =<br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">RequestSecurityToken</font></span><font color="#000000">(</font><span style="color: "><font color="#2b91af">WSTrust13Constants</font></span><font color="#000000">.</font><span style="color: "><font color="#2b91af">RequestTypes</font></span><font color="#000000">.Issue, </font><span style="color: "><font color="#2b91af">WSTrust13Constants</font></span><font color="#000000">.</font><span style="color: "><font color="#2b91af">KeyTypes</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">.Bearer);<br />rst.AppliesTo = </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">EndpointAddress</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">(acsUrl);<br />rst.TokenType = Microsoft.IdentityModel.Tokens.</font><span style="color: "><font color="#2b91af">SecurityTokenTypes</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="1"><font color="#000000">.Saml2TokenProfile11;<br /> </font><br /><span style="color: "><font color="#2b91af">WSTrustChannel</font></span><font color="#000000"> channel = (</font><span style="color: "><font color="#2b91af">WSTrustChannel</font></span><font color="#000000">)trustChannelFactory.CreateChannel();</font><br /><span style="color: "><font color="#2b91af">GenericXmlSecurityToken</font></span><font color="#000000"> token = channel.Issue(rst) </font><span style="color: "><font color="#0000ff">as</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">GenericXmlSecurityToken</font></span><font color="#000000">;</font><br /><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> tokenString = token.TokenXml.OuterXml;</font><br /><span style="color: "><font color="#0000ff">return</font></span><font color="#000000"> tokenString;</font></font></font></font></pre>
  </li>

  <li>Putting it all together, you’ll want to add the method ‘GetSamlToken’ to Program.cs:&#160; <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><font size="1"><span style="color: "><font color="#0000ff"><font style="font-size: ">private</font></font></span><font style="font-size: "><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">static</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> GetSamlToken(</font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> domain, </font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> userName, </font><span style="color: "><font color="#0000ff">string</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="1"><font color="#000000"> password)<br />{<br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">var</font></span><font color="#000000"> acsUrl = </font><span style="color: "><font color="#a31515">&quot;https://willpe-blog.accesscontrol.appfabriclabs.com/&quot;</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">;<br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">var</font></span><font color="#000000"> stsUrl = </font><span style="color: "><font color="#a31515">&quot;https://vm-willpe-adfs/adfs/services/trust/13/windowsmixed&quot;</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">;<br /> <br />&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">WSTrustChannelFactory</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000"> trustChannelFactory =<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">WSTrustChannelFactory</font></span><font color="#000000">(</font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">WindowsWSTrustBinding</font></span><font color="#000000">(</font><span style="color: "><font color="#2b91af">SecurityMode</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">.TransportWithMessageCredential),<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">EndpointAddress</font></span><font color="#000000">(</font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">Uri</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">(stsUrl)));<br /> <br />&#160;&#160;&#160; trustChannelFactory.TrustVersion = </font><span style="color: "><font color="#2b91af">TrustVersion</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">.WSTrust13;<br />&#160;&#160;&#160; trustChannelFactory.Credentials.Windows.ClientCredential.Domain = domain;<br />&#160;&#160;&#160; trustChannelFactory.Credentials.Windows.ClientCredential.UserName = userName;<br />&#160;&#160;&#160; trustChannelFactory.Credentials.Windows.ClientCredential.Password = password;<br /> <br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">try</font></span><br /></font></font><font face="Consolas"><font size="1"><font color="#000000">&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">RequestSecurityToken</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000"> rst =<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">RequestSecurityToken</font></span><font color="#000000">(</font><span style="color: "><font color="#2b91af">WSTrust13Constants</font></span><font color="#000000">.</font><span style="color: "><font color="#2b91af">RequestTypes</font></span><font color="#000000">.Issue, </font><span style="color: "><font color="#2b91af">WSTrust13Constants</font></span><font color="#000000">.</font><span style="color: "><font color="#2b91af">KeyTypes</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">.Bearer);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; rst.AppliesTo = </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">EndpointAddress</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">(acsUrl);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; rst.TokenType = Microsoft.IdentityModel.Tokens.</font><span style="color: "><font color="#2b91af">SecurityTokenTypes</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">.Saml2TokenProfile11;<br /> <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">WSTrustChannel</font></span><font color="#000000"> channel = (</font><span style="color: "><font color="#2b91af">WSTrustChannel</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">)trustChannelFactory.CreateChannel();<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">GenericXmlSecurityToken</font></span><font color="#000000"> token = channel.Issue(rst) </font><span style="color: "><font color="#0000ff">as</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">GenericXmlSecurityToken</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">string</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000"> tokenString = token.TokenXml.OuterXml;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">return</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="1"><font color="#000000"> tokenString;<br />&#160;&#160;&#160; }<br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">finally</font></span><br /></font><font color="#000000" size="1">&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; trustChannelFactory.Close();<br />&#160;&#160;&#160; }<br />}</font></font></font></pre>
  </li>
</ol>

<p>Add a line to the Main method to call GetSamlToken and verify that you get a nice, chunky XML token back from ADFS. With just a couple more lines of code, all of that markup will become a Simple Web Token.</p>

<p><strong>Submit the SAML token to ACS to retrieve a set of claims as a SWT token </strong></p>

<p>The hard work is over now – all we need to do is submit the SAML token we retrieved to ACS and get a Simple Web Token in response. With that token, you’re good to authenticate against any (properly configured) resource secured by the AppFabric Access Control Service.</p>

<ol>
  <li>Add the method GetSimpleWebToken(string samlToken) to Program.cs </li>

  <li>Retrieve your ACS STS Uri from the portal, it’s probably something like: <a href="https://[Your-Service-Namespace].accesscontrol.appfabriclabs.com/WRAPv0.9/">https://[Your-Service-Namespace].accesscontrol.appfabriclabs.com/WRAPv0.9/</a> </li>

  <li>Upload the SAML Token to ACS. You need to specify the Scope (that is, the ‘Applies To’/’Expected Audience’ Url or the address of the resource which this token is to be used against), the assertion format (SAML in this case) and the assertion itself. I’m using this token to authenticate directly against the ACS management service, so my parameters look like this: 
    <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><font size="1"><span style="color: "><font color="#2b91af"><font style="font-size: ">NameValueCollection</font></font></span><font style="font-size: "><font color="#000000"> parameters = </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">NameValueCollection</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="1"><font color="#000000">();<br />parameters.Add(</font><span style="color: "><font color="#a31515">&quot;wrap_scope&quot;</font></span><font color="#000000">, </font><span style="color: "><font color="#a31515">&quot;https://willpe-blog.accesscontrol.appfabriclabs.com/mgmt&quot;</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">);<br />parameters.Add(</font><span style="color: "><font color="#a31515">&quot;wrap_assertion_format&quot;</font></span><font color="#000000">, </font><span style="color: "><font color="#a31515">&quot;SAML&quot;</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="1"><font color="#000000">);<br />parameters.Add(</font><span style="color: "><font color="#a31515">&quot;wrap_assertion&quot;</font></span><font color="#000000">, samlToken);</font></font></font></font></pre>
  </li>

  <li>Then we’ll simply upload these values to the Access Control Service and extract the SWT token from the response. Putting it all together, the GetSimpleWebToken method looks like this: 
    <pre style="line-height: normal; list-style-type: disc; font-family: "><font face="Consolas"><font size="1"><span style="color: "><font color="#0000ff"><font style="font-size: ">private</font></font></span><font style="font-size: "><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">static</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> GetSwtToken(</font><span style="color: "><font color="#0000ff">string</font></span></font></font></font><font style="font-size: "><font face="Consolas"><font size="1"><font color="#000000"> samlToken)<br />{<br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">var</font></span><font color="#000000"> appliesTo = </font><span style="color: "><font color="#a31515">&quot;https://willpe-blog.accesscontrol.appfabriclabs.com/mgmt&quot;</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">;<br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">var</font></span><font color="#000000"> acsStsUrl = </font><span style="color: "><font color="#a31515">&quot;https://willpe.accesscontrol.appfabriclabs.com/WRAPv0.9/&quot;</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">;<br /> <br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">try</font></span><br /></font></font><font face="Consolas"><font size="1"><font color="#000000">&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">WebClient</font></span><font color="#000000"> client = </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">WebClient</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">();<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; client.BaseAddress = acsStsUrl;<br /> <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#2b91af">NameValueCollection</font></span><font color="#000000"> parameters = </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">NameValueCollection</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">();<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; parameters.Add(</font><span style="color: "><font color="#a31515">&quot;wrap_scope&quot;</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">, appliesTo);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; parameters.Add(</font><span style="color: "><font color="#a31515">&quot;wrap_assertion_format&quot;</font></span><font color="#000000">, </font><span style="color: "><font color="#a31515">&quot;SAML&quot;</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; parameters.Add(</font><span style="color: "><font color="#a31515">&quot;wrap_assertion&quot;</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">, samlToken);<br /> <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">byte</font></span><font color="#000000">[] responseBytes = client.UploadValues(</font><span style="color: "><font color="#a31515">&quot;&quot;</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">, parameters);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> response = </font><span style="color: "><font color="#2b91af">Encoding</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">.UTF8.GetString(responseBytes);<br /> <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">return</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">Uri</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">.UnescapeDataString(response<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Split(</font><span style="color: "><font color="#a31515">'&amp;'</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">)<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Single(value =&gt; value.StartsWith(</font><span style="color: "><font color="#a31515">&quot;wrap_access_token=&quot;</font></span><font color="#000000">, </font><span style="color: "><font color="#2b91af">StringComparison</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">.OrdinalIgnoreCase))<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Split(</font><span style="color: "><font color="#a31515">'='</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000">)[1]);<br />&#160;&#160;&#160; }<br />&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">catch</font></span><font color="#000000"> (</font><span style="color: "><font color="#2b91af">WebException</font></span></font></font><font face="Consolas"><font size="1"><font color="#000000"> wex)<br />&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">string</font></span><font color="#000000"> value = </font><span style="color: "><font color="#0000ff">new</font></span><font color="#000000">&#160;</font><span style="color: "><font color="#2b91af">StreamReader</font></span></font></font></font><font face="Consolas"><font style="font-size: "><font size="1"><font color="#000000">(wex.Response.GetResponseStream()).ReadToEnd();<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><span style="color: "><font color="#0000ff">throw</font></span></font><font color="#000000" size="1">;<br />&#160;&#160;&#160; }<br />}</font></font></font></pre>
  </li>
</ol>

<p>So, there we go – we’ve installed and configured ADFS, Created a Trust Relationship between the AppFabric Access Control Service and your new ADFS Instance, we configured ACS to accept incoming claims from the Active Directory Identity Provider and pass-through the Windows Account name. Then we used WIF to get swap our Windows Credentials for a SAML token which we sent to ACS to get a Simple Web Token. The result? A little string like this:</p>

<blockquote>
  <p>http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname=<b>WILLPE\Test</b> 

    <br />&amp;http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider=<b>http://VM-WILLPE-ADFS.willpe.sb/adfs/services/trust</b> 

    <br />&amp;Audience=<b>https://willpe-blog.accesscontrol.appfabriclabs.com/mgmt</b> 

    <br />&amp;ExpiresOn=<b>1288060895</b> 

    <br />&amp;Issuer=<b>https://willpe-blog.accesscontrol.appfabriclabs.com/</b> 

    <br />&amp;HMACSHA256=[Base64-Hash-Code]</p>
</blockquote>

<p>You can download the full sample from SkyDrive – feel free to leave any comments/questions below or find me on Twitter (<a href="https://twitter.com/willpe">@willpe</a>)</p>
<center><iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-f417b199bb8eca27.office.live.com/embedicon.aspx/.Public/Blog/AcsFederationSample.zip" frameborder="0" marginwidth="0" scrolling="no"></iframe></center>

<p>I hope this helps,</p>

<p>Will</p>]]></content:encoded>
    </item>
    <item>
      <title>How to figure out when your ACS Auth Token Expires</title>
      <link>https://docs.microsoft.com/archive/blogs/willpe/how-to-figure-out-when-your-acs-auth-token-expires</link>
      <pubDate>Tue, 12 Oct 2010 10:13:00 GMT</pubDate>
      <dc:creator><![CDATA[willpe]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/willpe/2010/10/12/how-to-figure-out-when-your-acs-auth-token-expires/</guid>
      <description><![CDATA[If you&rsquo;re using the Windows Azure AppFabric Access Control Service (ACS) you&rsquo;ve probably...]]></description>
      <content:encoded><![CDATA[<p>If you&rsquo;re using the <a href="http://portal.appfabriclabs.com">Windows Azure AppFabric Access Control Service</a> (ACS) you&rsquo;ve probably encountered a Simple Web Token (SWT) accessed via the Web Resource Authorization Protocol (WRAP). Doing this recently, I wanted to figure out when my token expired (so that I could cache it until a couple of minutes before expiry, improving my app's performance) &ndash; you might find this snippet useful if you want to figure out when a SWT token expires:</p>
<p><span style="font-family: ; font-size: ; mso-fareast-font-family: 'Times New Roman'"><span style="font-family: Consolas;"><span><span style="font-size: x-small;"><span style="color: "><span style="color: #808080;">&nbsp;&nbsp;&nbsp; ///</span></span><span style="color: "><span style="color: #008000;">&nbsp;</span></span><span style="color: "><span style="color: #808080;">&lt;summary&gt;</span></span>             <br /><span style="color: #000000;">&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #808080;">///</span></span><span style="color: "><span style="color: #008000;"> Gets the UTC time that the specified token expires.</span></span>             <br /><span style="color: #000000;">&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #808080;">///</span></span><span style="color: "><span style="color: #008000;">&nbsp;</span></span><span style="color: "><span style="color: #808080;">&lt;/summary&gt;</span></span>             <br /><span style="color: #000000;">&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #808080;">///</span></span><span style="color: "><span style="color: #008000;">&nbsp;</span></span><span style="color: "><span style="color: #808080;">&lt;param name="token"&gt;</span></span><span style="color: "><span style="color: #008000;">An Access Token from the Access Control Service .</span></span><span style="color: "><span style="color: #808080;">&lt;/param&gt;</span></span>             <br /><span style="color: #000000;">&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #808080;">///</span></span><span style="color: "><span style="color: #008000;">&nbsp;</span></span><span style="color: "><span style="color: #808080;">&lt;returns&gt;</span></span><span style="color: "><span style="color: #008000;">The time that the token expires as a UTC DateTime.</span></span><span style="color: "><span style="color: #808080;">&lt;/returns&gt;</span></span>             <br /><span style="color: #000000;">&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #0000ff;">public</span></span><span style="color: #000000;">&nbsp;</span><span style="color: "><span style="color: #0000ff;">static</span></span><span style="color: #000000;">&nbsp;</span><span style="color: "><span style="color: #2b91af;">DateTime</span></span><span style="color: #000000;"> GetExpiryTime(</span><span style="color: "><span style="color: #0000ff;">string</span></span></span></span></span><span><span style="font-family: Consolas;"><span style="color: #000000; font-size: x-small;"> token)            <br />&nbsp;&nbsp;&nbsp; {             <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></span><span style="font-family: Consolas;"><span style="font-size: x-small;"><span style="color: "><span style="color: #0000ff;"><span>var</span></span></span><span><span style="color: #000000;"> swt = token.Substring(</span><span style="color: "><span style="color: #a31515;">"wrap_access_token=\""</span></span><span style="color: #000000;">.Length, token.Length - (</span><span style="color: "><span style="color: #a31515;">"wrap_access_token=\""</span></span></span></span></span><span><span style="font-family: Consolas;"><span style="font-size: x-small;"><span style="color: #000000;">.Length + 1));            <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #0000ff;">var</span></span><span style="color: #000000;"> tokenValue = </span><span style="color: "><span style="color: #2b91af;">Uri</span></span></span></span><span style="font-family: Consolas;"><span style="font-size: x-small;"><span style="color: #000000;">.UnescapeDataString(swt);            <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #0000ff;">var</span></span><span style="color: #000000;"> properties = (</span><span style="color: "><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> prop </span><span style="color: "><span style="color: #0000ff;">in</span></span><span style="color: #000000;"> tokenValue.Split(</span><span style="color: "><span style="color: #a31515;">'&amp;'</span></span></span></span><span style="font-family: Consolas;"><span style="font-size: x-small;"><span style="color: #000000;">)            <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #0000ff;">let</span></span><span style="color: #000000;"> pair = prop.Split(</span><span style="color: "><span style="color: #0000ff;">new</span></span><span style="color: #000000;">[] { </span><span style="color: "><span style="color: #a31515;">'='</span></span></span></span><span style="font-family: Consolas;"><span style="font-size: x-small;"><span style="color: #000000;"> }, 2)            <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #0000ff;">select</span></span><span style="color: #000000;">&nbsp;</span><span style="color: "><span style="color: #0000ff;">new</span></span></span></span><span style="font-family: Consolas;"><span style="font-size: x-small;"><span style="color: #000000;"> { Name = pair[0], Value = pair[1] })            <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ToDictionary(p =&gt; p.Name, p =&gt; p.Value);             <br />&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #0000ff;">var</span></span><span style="color: #000000;"> expiresOnUnixTicks = </span><span style="color: "><span style="color: #0000ff;">int</span></span><span style="color: #000000;">.Parse(properties[</span><span style="color: "><span style="color: #a31515;">"ExpiresOn"</span></span></span></span><span style="font-family: Consolas;"><span style="font-size: x-small;"><span style="color: #000000;">]);            <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #0000ff;">var</span></span><span style="color: #000000;"> epochStart = </span><span style="color: "><span style="color: #0000ff;">new</span></span><span style="color: #000000;">&nbsp;</span><span style="color: "><span style="color: #2b91af;">DateTime</span></span><span style="color: #000000;">(1970, 01, 01, 0, 0, 0, 0, </span><span style="color: "><span style="color: #2b91af;">DateTimeKind</span></span></span></span></span><span style="font-family: Consolas;"><span><span style="font-size: x-small;"><span style="color: #000000;">.Utc);            <br />&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: "><span style="color: #0000ff;">return</span></span><span style="color: #000000;"> epochStart.AddSeconds(expiresOnUnixTicks);</span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><span style="font-family: ; font-size: ; mso-fareast-font-family: 'Times New Roman'"><span><span style="font-family: Consolas;"><span style="color: "><span style="color: #0000ff;"></span></span></span></span><span style="font-family: Consolas;"><span><span style="color: #000000; font-size: x-small;">&nbsp;&nbsp;&nbsp; }</span></span></span></span></p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><span style="font-family: ; font-size: ; mso-fareast-font-family: 'Times New Roman'"><span style="font-family: Consolas; color: #000000; font-size: x-small;"></span></span></p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt">&nbsp;</p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt">The code takes an access token from ACS (of the format <em>wrap_access_token=&rdquo;[Insert-SWT-Here]&rdquo;</em>) and extracts the &lsquo;ExpiresOn&rsquo; value from the SWT. According to the <a href="http://lists.w3.org/Archives/Public/public-xg-socialweb/2010Feb/att-0055/draft-hardt-oauth-wrap-01.html#anchor56">OAuth WRAP Spec</a>, this is a Unix time (i.e., the number of seconds past January 1, 1970 at 12am) expressed as a UTC time. So, don&rsquo;t forget that if you want to figure out when the token expires in your <strong>local</strong> time zone, you&rsquo;ll need to convert it using the TimeZone type:</p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt">&nbsp;</p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><span style="font-family: Consolas; color: #000000; font-size: x-small;"></span></p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><span style="font-family: Consolas;"><span style="font-size: x-small;"><span style="color: #000000;"><span>&nbsp;&nbsp;&nbsp; </span></span><span><span style="color: "><span style="color: #2b91af;">Console</span></span><span style="color: #000000;">.WriteLine(</span><span style="color: "><span style="color: #a31515;">"Your auth token expires at {0}."</span></span><span style="color: #000000;">, </span><span style="color: "><span style="color: #2b91af;">TimeZone</span></span><span style="color: #000000;">.CurrentTimeZone.ToLocalTime(</span><span style="color: "><span style="color: #0000ff;">this</span></span><span style="color: #000000;">.AuthTokenExpiry));</span></span></span></span>     </p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt">&nbsp;</p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt">I hope this helps,</p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt">&nbsp;</p>
<p class="MsoNormal" style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt">Will</p>]]></content:encoded>
    </item>
    <item>
      <title>The Fibonnaci Sequence using C# Iterators</title>
      <link>https://docs.microsoft.com/archive/blogs/willpe/the-fibonnaci-sequence-using-c-iterators</link>
      <pubDate>Wed, 07 Apr 2010 13:05:46 GMT</pubDate>
      <dc:creator><![CDATA[willpe]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/willpe/2010/04/07/the-fibonnaci-sequence-using-c-iterators/</guid>
      <description><![CDATA[.code {color: #000; font-family: consolas, 'Courier New', courier, monospace; font-size:...]]></description>
      <content:encoded><![CDATA[<style>




.code {color: #000; font-family: consolas, 'Courier New', courier, monospace; font-size: 10pt}</style>  <p>Iterators in C# are probably one of the least understood and most wonderful features the language has. They were added in C# 2.0 and are the magic that gives LINQ its <a href="http://blogs.msdn.com/charlie/archive/2007/12/09/deferred-execution.aspx">Deferred Execution</a> goodness. Anyway, I was needing an arbitrary length list of Guids today (although, with the <a href="http://weblogs.asp.net/leftslipper/archive/2010/04/01/last-guid-used-up-new-scottguid-unique-id-to-replace-it.aspx">recent shortage</a>, perhaps ScottGuIDs would have been a better choice) and used this cute little few-liner to get what I wanted:</p>  <blockquote>   <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9f44c71e-6b72-4e7d-a6ef-11aa706967aa" class="wlWriterEditableSmartContent"> <div class="code"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#2b91af">IEnumerable</span>&lt;<span style="color:#2b91af">Guid</span>&gt; Guids<br> {<br>     <span style="color:#0000ff">get</span><br>     {<br>         <span style="color:#0000ff">while</span> (<span style="color:#0000ff">true</span>)<br>         {<br>             <span style="color:#0000ff">yield</span> <span style="color:#0000ff">return</span> <span style="color:#2b91af">Guid</span>.NewGuid();<br>         }<br>     }<br> }</div> </div> </div>    <p></p> </blockquote>  <p>From there you can easily get yourself a list of, say, 5 Guids using LINQ’s <a href="http://msdn.microsoft.com/en-us/library/bb300906.aspx">Take Extension</a> Method:</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b65d3f3f-aadb-4090-bb7c-88323090c94d" class="wlWriterEditableSmartContent"> <div class="code"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> myGuids = <span style="color:#0000ff">this</span>.Guids.Take(5);</div> </div> </div> Obviously, this made me want to generate some more interesting sequences, like Fibonnaci’s:   <blockquote></blockquote>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d65cdba0-ce38-4a99-8e1f-d312a0acd3bf" class="wlWriterEditableSmartContent"> <div class="code"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#2b91af">IEnumerable</span>&lt;<span style="color:#0000ff">int</span>&gt; Fibonnaci<br> {<br>     <span style="color:#0000ff">get</span><br>     {<br>         <span style="color:#0000ff">int</span> first = 0;<br>         <span style="color:#0000ff">yield</span> <span style="color:#0000ff">return</span> first;<br> <br>         <span style="color:#0000ff">int</span> second = 1;<br>         <span style="color:#0000ff">yield</span> <span style="color:#0000ff">return</span> second;<br> <br>         <span style="color:#0000ff">while</span> (<span style="color:#0000ff">true</span>)<br>         {<br>             <span style="color:#0000ff">int</span> next = first + second;<br>             first = second;<br>             second = next;<br> <br>             <span style="color:#0000ff">yield</span> <span style="color:#0000ff">return</span> next;<br>         }<br>     }<br> }</div> </div> </div>  <p></p>  <p>Pretty terse, right?</p>]]></content:encoded>
    </item>
    <item>
      <title>European Tech Talk Tour</title>
      <link>https://docs.microsoft.com/archive/blogs/willpe/european-tech-talk-tour</link>
      <pubDate>Fri, 21 Nov 2008 07:00:00 GMT</pubDate>
      <dc:creator><![CDATA[willpe]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/willpe/2008/11/21/european-tech-talk-tour/</guid>
      <description><![CDATA[For a few days this autumn (or is it Winter now?) I’ll be out and about talking to great uni...]]></description>
      <content:encoded><![CDATA[<P>For a few days this autumn (or is it Winter now?) I’ll be out and about talking to great uni students about Microsoft Codename ‘M’, and some of the fantastic technical opportunities for graduates at Microsoft. Here are some resources:</P>
<P><STRONG>Apply for a Position at Microsoft</STRONG></P>
<BLOCKQUOTE>
<UL>
<LI><A target=_blank href="http://www.microsoft.com/college/ft_swandhwdev.mspx#pm" mce_href="http://www.microsoft.com/college/ft_swandhwdev.mspx#pm">Description of the Program Manager Role</A> </LI>
<LI><A target=_blank href="http://www.microsoft.com/college/ft_swandhwdev.mspx#sde" mce_href="http://www.microsoft.com/college/ft_swandhwdev.mspx#sde">Description of the Software Development Engineer Role</A> </LI>
<LI><A target=_blank href="http://www.microsoft.com/college/ft_swandhwdev.mspx#sdet" mce_href="http://www.microsoft.com/college/ft_swandhwdev.mspx#sdet">Description of the Software Development Engineer in Test Role</A> </LI>
<LI><A target=_blank href="http://mdcc.dk/" mce_href="http://mdcc.dk">Learn about Microsoft Development Center Copenhagen (MDCC)</A> </LI></UL></BLOCKQUOTE>
<P>If you’d like to apply then use one of then send your CV/Resumé to us. Don’t forget to tell as about the things that really make you stand apart from your peers like your best university and individual projects or jobs!</P>
<BLOCKQUOTE>
<P><STRONG>Full Time: </STRONG><A href="mailto:MSGradCV@microsoft.com" mce_href="mailto:MSGradCV@microsoft.com">MSGradCV@microsoft.com</A> <BR><STRONG>Intern: </STRONG><A href="mailto:InternCV@microsoft.com" mce_href="mailto:InternCV@microsoft.com">InternCV@microsoft.com</A> </P></BLOCKQUOTE>
<P><STRONG></STRONG></P>
<P><STRONG>Codename ‘M’ Resources</STRONG></P>
<BLOCKQUOTE>
<UL>
<LI>Video: <A target=_blank href="https://channel9.msdn.com/pdc2008/TL23/" mce_href="https://channel9.msdn.com/pdc2008/TL23/">A Lap Around Oslo</A>&nbsp;</LI>
<LI>Video: <A target=_blank href="https://channel9.msdn.com/pdc2008/TL27/" mce_href="https://channel9.msdn.com/pdc2008/TL27/">Oslo: The Language</A></LI>
<LI>Video: <A target=_blank href="https://channel9.msdn.com/pdc2008/TL31/" mce_href="https://channel9.msdn.com/pdc2008/TL31/">Textual DSLs</A></LI>
<LI>Video: <A target=_blank href="https://channel9.msdn.com/pdc2008/TL28/" mce_href="https://channel9.msdn.com/pdc2008/TL28/">Repository and Models</A></LI></UL></BLOCKQUOTE>
<P mce_keep="true">&nbsp;</P>
<BLOCKQUOTE>
<UL>
<LI><A target=_blank href="http://msdn.microsoft.com/oslo" mce_href="http://msdn.microsoft.com/oslo">‘Oslo’ Developer Center</A></LI>
<LI><A target=_blank href="http://connect.microsoft.com/oslo" mce_href="http://connect.microsoft.com/oslo">‘Oslo’ Feedback and Bugs (Microsoft Connect)</A>&nbsp;</LI>
<LI><A target=_blank href="http://code.msdn.microsoft.com/oslo/Release/ProjectReleases.aspx?ReleaseId=1707" mce_href="http://code.msdn.microsoft.com/oslo/Release/ProjectReleases.aspx?ReleaseId=1707">Download: ‘Oslo’ SDK</A></LI>
<LI><A target=_blank href="http://martinfowler.com/bliki/Oslo.html" mce_href="http://martinfowler.com/bliki/Oslo.html">Martin Fowler’s Take on ‘M’</A></LI></UL></BLOCKQUOTE>
<P>When using these resources, please remember that this is a <STRONG>really</STRONG> early preview. That means its all likely to change, its not ready for production and there are likely plenty of bugs! To help shape the future of modeling on our platform, <EM>please</EM> send your feedback using Connect!</P>
<P><STRONG>Replay the London Event</STRONG></P>
<BLOCKQUOTE>
<P>I’ll be uploading the meeting recording from the London student partners event soon – please check back!</P>
<P>For now, you can grab the slide deck from skydrive.</P>
<CENTER><IFRAME style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 240px; PADDING-RIGHT: 0px; HEIGHT: 66px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginHeight=0 src="http://cid-7041d30b1cc4ad99.skydrive.live.com/embedrowdetail.aspx/Public/SlideDecks/Europe%20MTC%20FY09.pptx" frameBorder=0 marginWidth=0 scrolling=no></IFRAME></CENTER></BLOCKQUOTE>
<P>If you’ve got any questions or comments, just post a comment, and I’ll get back to you asap!</P>]]></content:encoded>
    </item>
  </channel>
</rss>