<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Clemens Vasters, Bldg 42 : Queues</title><link>http://blogs.msdn.com/clemensv/archive/tags/Queues/default.aspx</link><description>Tags: Queues</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>.NET Services March 2009 CTP - Service Bus Routers and Queues - Part 5: The Queue API for the rest of us</title><link>http://blogs.msdn.com/clemensv/archive/2009/04/06/net-services-march-2009-ctp-service-bus-routers-and-queues-part-5-the-queue-api-for-the-rest-of-us.aspx</link><pubDate>Tue, 07 Apr 2009 00:38:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9535412</guid><dc:creator>clemensv</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/clemensv/comments/9535412.aspx</comments><wfw:commentRss>http://blogs.msdn.com/clemensv/commentrss.aspx?PostID=9535412</wfw:commentRss><wfw:comment>http://blogs.msdn.com/clemensv/rsscomments.aspx?PostID=9535412</wfw:comment><description>&lt;P&gt;In Parts &lt;A href="http://vasters.com/clemensv/PermaLink,guid,413c6128-a6a6-4894-9cc9-701ffb674ab0.aspx"&gt;3&lt;/A&gt; and &lt;A href="http://vasters.com/clemensv/PermaLink,guid,4aefc36e-4476-4543-9574-13727c8f615d.aspx"&gt;4&lt;/A&gt; of this series I’ve explained the REST protocol for the .NET Service Bus Queue capability. If that looked a little too complicated for your taste and you’d rather clean with a simple API surface, here’s the API that you’ll prefer. &lt;/P&gt;
&lt;P&gt;We’ve got two simple classes in the SDK (in the Microsoft.ServiceBus assembly/namespace) that do the job. The &lt;EM&gt;QueueManagementClient&lt;/EM&gt; allows you to create, renew and delete queues in/from the .NET Service Bus namespace:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; QueueManagementClient
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2: {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3:    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; QueueClient CreateQueue(TransportClientEndpointBehavior credential, 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4:                                          Uri queueUri, QueuePolicy queuePolicy);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  5:    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; DeleteQueue(TransportClientEndpointBehavior credential, 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  6:                                   Uri queueUri);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  7:    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; QueueClient GetQueue(TransportClientEndpointBehavior credential, 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  8:                                       Uri queueUri);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  9:    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; QueuePolicy GetQueuePolicy(TransportClientEndpointBehavior credential, 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 10:                                             Uri queueUri);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 11:    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; DateTime RenewQueue(TransportClientEndpointBehavior credential, 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 12:                                      Uri queueUri, TimeSpan requestedExpiration);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 13: }&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;The most striking difference between this API (and the underlying SOAP protocol for which we still owe you some docs) and the REST API/Protocol is that there’s only a single URI to deal with. The WS-Transfer aligned protocol to manage the policy, the “Queue Transfer” protocol used to dequeue messages, and the “Enqueue” protocol to add messages to the queue are all overlaid over the exact same URI.&lt;/P&gt;
&lt;P&gt;The only somewhat ugly element here is the &lt;EM&gt;TransportClientEndpointBehavior&lt;/EM&gt; that’s our awkwardly named credentials container. That class was meant to evolve into something else and then we changed our mind at some point, which is how the baby got stuck with that name. We’ll give that a prettier moniker in one of the next CTPs and as part of an overhaul of the .NET Access Control integration into Service Bus.&lt;/P&gt;
&lt;P&gt;The function of the methods themselves should be quite obvious. You can create a queue by applying a &lt;A href="http://vasters.com/clemensv/PermaLink,guid,0f64f592-7239-42fc-aed2-f0993701c5f6.aspx"&gt;policy&lt;/A&gt;, you can delete a queue, attach to an existing queue, get the latest queue policy, and renew (extend the lifetime) of a queue. For completeness, here’s CreateQueue in context:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: Uri queueUri = ServiceBusEnvironment.CreateServiceUri("&lt;SPAN style="COLOR: #8b0000"&gt;sb&lt;/SPAN&gt;", solutionName, "&lt;SPAN style="COLOR: #8b0000"&gt;/MyQueue/&lt;/SPAN&gt;");
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3: QueuePolicy queuePolicy = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; QueuePolicy();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4: queuePolicy.ExpirationInstant = DateTime.UtcNow + TimeSpan.FromHours(1);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  5: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  6: QueueClient client = QueueManagementClient.CreateQueue(credential, queueUri, queuePolicy);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  7: queuePolicy = client.GetPolicy(); &lt;SPAN style="COLOR: #008000"&gt;// get effective policy&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;The &lt;EM&gt;QueueClient&lt;/EM&gt; class allows interaction with a Queue. QueueClient instances cannot be created directly, but must be created via the QueueManagementClient factory.&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;sealed&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; QueueClient
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2: {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; DeleteLockedMessage(Message message);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; DeleteQueue();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  5:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; DateTime GetExpiration();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  6:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; QueuePolicy GetPolicy();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  7:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; Message PeekLock();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  8:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; Message PeekLock(TimeSpan timeout);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  9:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IEnumerable&amp;lt;Message&amp;gt; PeekLockMultiple(&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; maxMessages);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 10:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IEnumerable&amp;lt;Message&amp;gt; PeekLockMultiple(&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; maxMessages, TimeSpan timeout);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 11:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; Purge();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 12:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; ReleaseLock(Message message);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 13:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; DateTime Renew(TimeSpan requestedExpiration);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 14:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; Message Retrieve();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 15:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; Message Retrieve(TimeSpan timeout);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 16:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IEnumerable&amp;lt;Message&amp;gt; RetrieveMultiple(&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; maxMessages);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 17:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IEnumerable&amp;lt;Message&amp;gt; RetrieveMultiple(&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; maxMessages, TimeSpan timeout);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 18:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; Send(Message message, TimeSpan timeout);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 19:     &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; RouterSubscriptionClient SubscribeToRouter(RouterClient routerClient, TimeSpan requestedTimeout);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 20: }&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can tell, the class is – well – a queue client. It’s using WCF’s &lt;EM&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx"&gt;Message&lt;/A&gt;&lt;/EM&gt; class as its message abstraction and supports sending messages into the queue, reading messages off the queue in a destructive fashion (Retrieve), and reading messages off the queue using the Peek/Lock pattern which provides resilience against message loss if the message were to be lost in transfer or the receiver fumbled the message. What you’ll also notice is that there are RetrieveMultiple and PeekLockMultiple variants of the retrieval functions which allow for getting more data with fewer network roundtrips. &lt;/P&gt;
&lt;P&gt;Again, there should be no surprises using the API. Here’s how you send:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: queueClient.Send(Message.CreateMessage(MessageVersion.Default, "&lt;SPAN style="COLOR: #8b0000"&gt;Hello&lt;/SPAN&gt;", input), TimeSpan.MaxValue);&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;and here’s how you do a destructive read:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: Message message = queueClient.Retrieve();&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;and here’s how you use the Peek/Lock pattern:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: Message message = queueClient.PeekLock();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2: &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; content = message.GetBody&amp;lt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&amp;gt;();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3: queueClient.DeleteLockedMessage(message);
&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;There are several examples in the SDK showing how to use the API for Queues. The OnewayQueueSender and SoapHttpQueueSender samples are particularly interesting since they just use WCF channels to enqueue, including all the bells and whistles you get from using a WCF channel. Here’s how the OnewayQueueSender does it:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: ChannelFactory&amp;lt;IOnewayChannel&amp;gt; channelFactory = 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2:      &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; ChannelFactory&amp;lt;IOnewayChannel&amp;gt;(&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; NetOnewayRelayBinding(), 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3:                                         &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; EndpointAddress(queueUri));
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4: channelFactory.Endpoint.Behaviors.Add(userNamePasswordServiceBusCredential);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  5: IOnewayChannel onewayChannel = channelFactory.CreateChannel();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  6: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  7: &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; input = Console.ReadLine();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  8: onewayChannel.Hello(&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; HelloMessage(input));
&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;The logical next question is: So why is the Queue not hooked up to a WCF listener? Answer: That’s what we’ve got “buffered Routers” for. The queue very explicitly provides a ‘pull’ model and the WCF listener would abstract that away and turn it into ‘push’. Routers provide ‘push’ natively &lt;EM&gt;and&lt;/EM&gt; they can embed a Queue. More on Routers in the next set of posts in this series. &lt;/P&gt;&lt;img width="0" height="0" src="http://vasters.com/clemensv/cptrk.ashx?id=b703725d-3e6a-4dbb-a613-890c31505fe8"&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9535412" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/clemensv/archive/tags/Azure/default.aspx">Azure</category><category domain="http://blogs.msdn.com/clemensv/archive/tags/Service+Bus/default.aspx">Service Bus</category><category domain="http://blogs.msdn.com/clemensv/archive/tags/Queues/default.aspx">Queues</category></item><item><title>.NET Services March 2009 CTP - Service Bus Routers and Queues - Part 4: The REST Queue Protocol in Code Snippets</title><link>http://blogs.msdn.com/clemensv/archive/2009/04/06/net-services-march-2009-ctp-service-bus-routers-and-queues-part-4-the-rest-queue-protocol-in-code-snippets.aspx</link><pubDate>Mon, 06 Apr 2009 23:40:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9535294</guid><dc:creator>clemensv</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/clemensv/comments/9535294.aspx</comments><wfw:commentRss>http://blogs.msdn.com/clemensv/commentrss.aspx?PostID=9535294</wfw:commentRss><wfw:comment>http://blogs.msdn.com/clemensv/rsscomments.aspx?PostID=9535294</wfw:comment><description>&lt;P&gt;After I’ve gone through the dry facts of the REST Queue Protocol in &lt;A href="http://vasters.com/clemensv/PermaLink,guid,413c6128-a6a6-4894-9cc9-701ffb674ab0.aspx"&gt;Part 3 of this series&lt;/A&gt;, here’s some code to look at. The code snippets are ripped from the HTTP Queue sample we’ve got in the .NET Services &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=8d1d1d5e-1332-4186-b33f-26d053759e49&amp;amp;displaylang=en"&gt;SDK&lt;/A&gt; and you can get the copy/paste ready code from there. &lt;/P&gt;
&lt;P&gt;The most straightforward way to acquire the required hashed security token (&lt;A href="http://vasters.com/clemensv/PermaLink,guid,19e938fc-e6ec-42df-96d9-e2f6a31f7399.aspx"&gt;see my comments to Stefan Tilkov&lt;/A&gt;) using HttpWebRequest looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; HttpGetAuthenticationToken(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; username, &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; password)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2: {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3:     &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; tokenUri = &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Format("&lt;SPAN style="COLOR: #8b0000"&gt;https://{0}/issuetoken.aspx?u={1}&amp;amp;p={2}&lt;/SPAN&gt;", 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4:                                     ServiceBusEnvironment.DefaultIdentityHostName, 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  5:                                     username, Uri.EscapeDataString(password));
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  6: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  7:     HttpWebRequest tokenRequest = (HttpWebRequest)WebRequest.Create(tokenUri);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  8:     &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var tokenResponse = tokenRequest.GetResponse())
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  9:     {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 10:         &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var tokenResponseStream = tokenResponse.GetResponseStream())
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 11:         {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 12:             &lt;SPAN style="COLOR: #0000ff"&gt;byte&lt;/SPAN&gt;[] tokenBody = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;byte&lt;/SPAN&gt;[500];
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 13:             &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; tokenBodyLength = tokenResponseStream.Read(tokenBody, 0, 500);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 14:             &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; Encoding.UTF8.GetString(tokenBody, 0, tokenBodyLength);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 15:         }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 16:     }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 17: }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 18: &lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you’ve got the token, you need to pick a place in the Service Bus namespace. We’ve got a built-in helper function in the SDK that sits on &lt;EM&gt;ServiceBusEnvironment&lt;/EM&gt; and which knows all the right incantations:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1:  Uri queueUri = ServiceBusEnvironment.CreateServiceUri(
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2:                    Uri.UriSchemeHttps, 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3:                    solutionName, 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4:                    "&lt;SPAN style="COLOR: #8b0000"&gt;/MyHttpQueue/&lt;/SPAN&gt;");          &lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;Invoked in this way, the method yields the URI &lt;STRONG&gt;https://yourproject.&lt;FONT color=#ff8040&gt;servicebus.windows.net&lt;/FONT&gt;/MyHttpQueue/&lt;/STRONG&gt; so there’s spectacularly little magic to it. The reason why we recommend that you use the method in .NET applications is that we’ve broken everyone’s apps going from the previous CTP to the current CTP due to the namespace restructuring and we’d like to avoid doing that again as we improve the namespace story. I don’t foresee any further change of the magnitude we had this time, however. &lt;/P&gt;
&lt;P&gt;To create a new Queue, you first &lt;A href="http://vasters.com/clemensv/PermaLink,guid,0f64f592-7239-42fc-aed2-f0993701c5f6.aspx"&gt;create a Queue policy&lt;/A&gt; and then apply it to the Service Bus namespace name. We’ve got a Queue Policy object in the SDK that I’ll use here to keep things short. I’m accepting all the defaults that are spelled out in &lt;A href="http://vasters.com/clemensv/PermaLink,guid,0f64f592-7239-42fc-aed2-f0993701c5f6.aspx"&gt;Part 2 of the series&lt;/A&gt;, but explicitly I’m setting the expiration to 1 hour. The Queue Policy XSD schema in the the HTTP Queue sample’s &lt;EM&gt;readme&lt;/EM&gt; document, by the way. &lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: QueuePolicy queuePolicy = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; QueuePolicy();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2: queuePolicy.ExpirationInstant = DateTime.UtcNow + TimeSpan.FromHours(1);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3: queueManageUri = HttpCreateQueue(token, queueUri, queuePolicy);&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;The code for creating the Queue shouldn’t be very surprising. It’s a POST of an Atom 1.0 entry for which I’m using HttpWebRequest and the WCF 3.5 Syndication API. The SDK sample is using a rather terse version of the ‘correct’ way of doing things. I’m quoting the expanded variant from the Text140 sample that I showed at MIX’09:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; QueuePolicy HttpCreateQueue(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; token, Uri queueUri, QueuePolicy policy, 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2:                                           &lt;SPAN style="COLOR: #0000ff"&gt;out&lt;/SPAN&gt; Uri queueSelfUri, &lt;SPAN style="COLOR: #0000ff"&gt;out&lt;/SPAN&gt; Uri queueHeadUri)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3: {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4:     HttpWebRequest webRequest;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  5:     HttpWebResponse webResponse;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  6: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  7:     queueSelfUri = &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  8:     queueHeadUri = &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  9: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 10:     &lt;SPAN style="COLOR: #008000"&gt;// Create a new syndication item and add the queue policy as an extension&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 11:     SyndicationItem syndicationItem = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; SyndicationItem();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 12:     syndicationItem.ElementExtensions.Add(
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 13:         &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; SyndicationElementExtension("&lt;SPAN style="COLOR: #8b0000"&gt;QueuePolicy&lt;/SPAN&gt;",
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 14:                                         "&lt;SPAN style="COLOR: #8b0000"&gt;http://schemas.microsoft.com/ws/2007/08/connect&lt;/SPAN&gt;",
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 15:                                         policy));
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 16: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 17:     &lt;SPAN style="COLOR: #008000"&gt;// create a new POST request and set the Content-Type to represent an Atom 1.0 entry&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 18:     webRequest = HttpWebRequest.Create(queueUri) &lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt; HttpWebRequest;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 19:     webRequest.ConnectionGroupName = "&lt;SPAN style="COLOR: #8b0000"&gt;queueclient&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 20:     webRequest.KeepAlive = &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 21:     webRequest.Method = "&lt;SPAN style="COLOR: #8b0000"&gt;POST&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 22:     webRequest.Headers.Add("&lt;SPAN style="COLOR: #8b0000"&gt;X-MS-Identity-Token&lt;/SPAN&gt;", token);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 23:     webRequest.ContentType = "&lt;SPAN style="COLOR: #8b0000"&gt;application/atom+xml;type=entry;charset=utf-8&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 24: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 25:     &lt;SPAN style="COLOR: #008000"&gt;// write the item to the request stream&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 26:     &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var requestStream = webRequest.GetRequestStream())
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 27:     {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 28:         &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var textWriter = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; XmlTextWriter(requestStream, Encoding.UTF8))
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 29:         {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 30:             syndicationItem.GetAtom10Formatter().WriteTo(textWriter);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 31:             textWriter.Flush();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 32:         }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 33:     }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 34: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 35:     &lt;SPAN style="COLOR: #008000"&gt;// get the response&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 36:     &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (webResponse = webRequest.GetResponse() &lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt; HttpWebResponse)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 37:     {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 38:         &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; GetQueueInfoFromResponse(webResponse, queueUri, &lt;SPAN style="COLOR: #0000ff"&gt;out&lt;/SPAN&gt; queueSelfUri, &lt;SPAN style="COLOR: #0000ff"&gt;out&lt;/SPAN&gt; queueHeadUri);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 39:     }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 40: }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 41: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 42: &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; QueuePolicy GetQueueInfoFromResponse(HttpWebResponse webResponse, Uri queueUri, 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 43:                                                     &lt;SPAN style="COLOR: #0000ff"&gt;out&lt;/SPAN&gt; Uri queueSelfUri, &lt;SPAN style="COLOR: #0000ff"&gt;out&lt;/SPAN&gt; Uri queueHeadUri)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 44: {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 45:     queueHeadUri = &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 46:     queueSelfUri = &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 47: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 48:     &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (webResponse.ContentType.StartsWith("&lt;SPAN style="COLOR: #8b0000"&gt;application/atom+xml;type=entry&lt;/SPAN&gt;", StringComparison.OrdinalIgnoreCase))
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 49:     {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 50:         Atom10ItemFormatter atomItemFormatter = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; Atom10ItemFormatter();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 51:         &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var responseReader = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; XmlTextReader(webResponse.GetResponseStream()))
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 52:         {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 53:             atomItemFormatter.ReadFrom(responseReader);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 54:             &lt;SPAN style="COLOR: #008000"&gt;// we found it. let's get the policy and the queue head URI&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 55:             &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (SyndicationLink queueSelfLink &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 56:                            from link &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; atomItemFormatter.Item.Links
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 57:                            where link.RelationshipType.Equals("&lt;SPAN style="COLOR: #8b0000"&gt;self&lt;/SPAN&gt;", StringComparison.OrdinalIgnoreCase)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 58:                            select link)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 59:             {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 60:                 queueSelfUri = queueSelfLink.Uri;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 61:                 &lt;SPAN style="COLOR: #0000ff"&gt;break&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 62:             }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 63: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 64:             &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (SyndicationLink queueHeadLink &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 65:                            from link &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; atomItemFormatter.Item.Links
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 66:                            where link.RelationshipType.Equals("&lt;SPAN style="COLOR: #8b0000"&gt;queuehead&lt;/SPAN&gt;", StringComparison.OrdinalIgnoreCase)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 67:                            select link)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 68:             {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 69:                 queueHeadUri = queueHeadLink.Uri;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 70:                 &lt;SPAN style="COLOR: #0000ff"&gt;break&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 71:             }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 72: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 73:             &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; atomItemFormatter.Item.ElementExtensions.ReadElementExtensions&amp;lt;QueuePolicy&amp;gt;(
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 74:                  "&lt;SPAN style="COLOR: #8b0000"&gt;QueuePolicy&lt;/SPAN&gt;",
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 75:                  "&lt;SPAN style="COLOR: #8b0000"&gt;http://schemas.microsoft.com/ws/2007/08/connect&lt;/SPAN&gt;").FirstOrDefault();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 76:         }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 77:     }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 78:     &lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 79:     {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 80:         Atom10FeedFormatter atomFeedFormatter = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; Atom10FeedFormatter();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 81:         &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var responseReader = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; XmlTextReader(webResponse.GetResponseStream()))
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 82:         {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 83:             atomFeedFormatter.ReadFrom(responseReader);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 84: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 85:             &lt;SPAN style="COLOR: #008000"&gt;// look for an item whose alternate-link equals the desired queue URI. The alternate &lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 86:             &lt;SPAN style="COLOR: #008000"&gt;// URI is the 'tail' endpoint by which the queue is mapped into the namespace. We are &lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 87:             &lt;SPAN style="COLOR: #008000"&gt;// comparing Authority and Path since the scheme might be http or https and we want to match&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 88:             &lt;SPAN style="COLOR: #008000"&gt;// either.&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 89:             &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (SyndicationItem requestedItem &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 90:                          from item &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; atomFeedFormatter.Feed.Items
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 91:                          from link &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; item.Links
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 92:                          where 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 93:                            (link.RelationshipType.Equals("&lt;SPAN style="COLOR: #8b0000"&gt;alternate&lt;/SPAN&gt;", StringComparison.OrdinalIgnoreCase) &amp;amp;&amp;amp;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 94:                             link.Uri.Authority.Equals(queueUri.Authority, StringComparison.OrdinalIgnoreCase) &amp;amp;&amp;amp;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 95:                             link.Uri.AbsolutePath.Equals(queueUri.AbsolutePath, StringComparison.OrdinalIgnoreCase)) ||
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 96:                            (link.RelationshipType.Equals("&lt;SPAN style="COLOR: #8b0000"&gt;self&lt;/SPAN&gt;", StringComparison.OrdinalIgnoreCase) &amp;amp;&amp;amp; 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 97:                             link.Uri.Equals(queueUri))
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 98:                          select item)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 99:             {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;100:                 &lt;SPAN style="COLOR: #008000"&gt;// we found it. let's get the policy and the queue head URI&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;101:                 &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (SyndicationLink queueSelfLink &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;102:                                from link &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; requestedItem.Links
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;103:                                where link.RelationshipType.Equals("&lt;SPAN style="COLOR: #8b0000"&gt;self&lt;/SPAN&gt;", StringComparison.OrdinalIgnoreCase)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;104:                                select link)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;105:                 {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;106:                     queueSelfUri = queueSelfLink.Uri;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;107:                     &lt;SPAN style="COLOR: #0000ff"&gt;break&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;108:                 }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;109: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;110:                 &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (SyndicationLink queueHeadLink &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;111:                                from link &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; requestedItem.Links
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;112:                                where link.RelationshipType.Equals("&lt;SPAN style="COLOR: #8b0000"&gt;queuehead&lt;/SPAN&gt;", StringComparison.OrdinalIgnoreCase)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;113:                                select link)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;114:                 {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;115:                     queueHeadUri = queueHeadLink.Uri;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;116:                     &lt;SPAN style="COLOR: #0000ff"&gt;break&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;117:                 }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;118: 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;119:                 &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; requestedItem.ElementExtensions.ReadElementExtensions&amp;lt;QueuePolicy&amp;gt;(
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;120:                      "&lt;SPAN style="COLOR: #8b0000"&gt;QueuePolicy&lt;/SPAN&gt;",
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;121:                      "&lt;SPAN style="COLOR: #8b0000"&gt;http://schemas.microsoft.com/ws/2007/08/connect&lt;/SPAN&gt;").FirstOrDefault();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;122:             }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;123:         }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;124:     }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;125:     &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;126: }&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;The “magic” that isn’t straight up Atom Pub is in lines 10-15 above. I’m attaching the policy object to the SyndicationItem abstraction that will be written out as an Atom 1.0 entry. [I know that copy/paste is difficult using this format – I need to clean up that expanded utility class and will post it in downloadable form within the next few days]&lt;/P&gt;
&lt;P&gt;The method returns the effective policy that the Service Bus is using, and yields the management URI for the queue where the Atom entry resides (self-link) as well as the head of the queue as output arguments. The &lt;EM&gt;queueUri&lt;/EM&gt; to which you applied the entry has morphed into the Queue’s tail when the method returns successfully. Having the Queue by its tail, submitting messages into it is very simple. Just do a plain POST. Here we’re just writing a simple string from the local variable &lt;EM&gt;input&lt;/EM&gt; as the entity body and send it.&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: &lt;SPAN style="COLOR: #008000"&gt;// send&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2: HttpWebRequest sendRequest = HttpWebRequest.Create(queueUri) &lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt; HttpWebRequest;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3: sendRequest.Method = "&lt;SPAN style="COLOR: #8b0000"&gt;POST&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4: sendRequest.Headers.Add("&lt;SPAN style="COLOR: #8b0000"&gt;X-MS-Identity-Token&lt;/SPAN&gt;", token);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  5: sendRequest.ContentType = "&lt;SPAN style="COLOR: #8b0000"&gt;text/plain;charset=utf-8&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  6: &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var sendStream = sendRequest.GetRequestStream())
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  7: {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  8:     &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var writer = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; StreamWriter(sendStream, Encoding.UTF8))
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  9:     {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 10:         writer.Write(input);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 11:         writer.Flush();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 12:     }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 13: }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 14: sendRequest.GetResponse().Close();&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;For a simple destructive read, you use the ‘queue head’ URI and do a DELETE:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: HttpWebRequest dequeueRequest = 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2:     HttpWebRequest.Create(queueHeadUri.AbsoluteUri+
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3:                           "&lt;SPAN style="COLOR: #8b0000"&gt;?encoding=asreply&amp;amp;maxmessages=1&amp;amp;timeout=60&lt;/SPAN&gt;") &lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt; HttpWebRequest;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4: dequeueRequest.ConnectionGroupName = "&lt;SPAN style="COLOR: #8b0000"&gt;dequeue&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  5: dequeueRequest.Method = "&lt;SPAN style="COLOR: #8b0000"&gt;DELETE&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  6: dequeueRequest.ContentLength = 0;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  7: dequeueRequest.Headers.Add("&lt;SPAN style="COLOR: #8b0000"&gt;X-MS-Identity-Token&lt;/SPAN&gt;", token);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  8: &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (HttpWebResponse response = dequeueRequest.GetResponse() &lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt; HttpWebResponse)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  9: {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 10:     &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (response.StatusCode == HttpStatusCode.OK)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 11:     {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 12:         &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var responseBody = response.GetResponseStream())
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 13:         {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 14:             &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var responseReader = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; StreamReader(responseBody, Encoding.UTF8))
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 15:             {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 16:                 &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; data = responseReader.ReadToEnd();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 17:                 Console.WriteLine(data);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 18:             }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 19:         }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 20:     }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 21: }&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;For a peek/lock read where you first lock the message and then delete the lock when you want to keep the message, you do a POST on the head and remember the &lt;EM&gt;X-MS-Message-Lock&lt;/EM&gt; header value:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: HttpWebRequest dequeueRequest = 
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2:      HttpWebRequest.Create(queueHeadUri.AbsoluteUri+
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3:                            "&lt;SPAN style="COLOR: #8b0000"&gt;?encoding=asreply&amp;amp;maxmessages=1&amp;amp;timeout=60&lt;/SPAN&gt;") &lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt; HttpWebRequest;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4: dequeueRequest.ConnectionGroupName = "&lt;SPAN style="COLOR: #8b0000"&gt;dequeue&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  5: dequeueRequest.Method = "&lt;SPAN style="COLOR: #8b0000"&gt;POST&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  6: dequeueRequest.ContentLength = 0;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  7: dequeueRequest.Headers.Add("&lt;SPAN style="COLOR: #8b0000"&gt;X-MS-Identity-Token&lt;/SPAN&gt;", token);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  8: &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (HttpWebResponse response = dequeueRequest.GetResponse() &lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt; HttpWebResponse)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  9: {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 10:     &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (response.StatusCode == HttpStatusCode.OK)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 11:     {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 12:         lockUri = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; Uri(response.Headers["&lt;SPAN style="COLOR: #8b0000"&gt;X-MS-Message-Lock&lt;/SPAN&gt;"]);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 13:         &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var responseBody = response.GetResponseStream())
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 14:         {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 15:             &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var responseReader = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; StreamReader(responseBody, Encoding.UTF8))
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 16:             {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 17:                 &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; data = responseReader.ReadToEnd();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 18:                 Console.WriteLine(data);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 19:             }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 20:         }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 21:     }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt; 22: }&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;If you decide to keep the message (i.e. your app didn’t puke processing it), you DELETE the lock, otherwise you do a PUT. The code is practically the same except for the method so I’ll just quote DELETE:&lt;/P&gt;&lt;PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  1: HttpWebRequest deleteLockedMessageRequest = HttpWebRequest.Create(lockUri) &lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt; HttpWebRequest;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  2: deleteLockedMessageRequest.ConnectionGroupName = "&lt;SPAN style="COLOR: #8b0000"&gt;lock&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  3: deleteLockedMessageRequest.Method = "&lt;SPAN style="COLOR: #8b0000"&gt;DELETE&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  4: deleteLockedMessageRequest.KeepAlive=&lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  5: deleteLockedMessageRequest.ContentLength = 0;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  6: deleteLockedMessageRequest.Headers.Add("&lt;SPAN style="COLOR: #8b0000"&gt;X-MS-Identity-Token&lt;/SPAN&gt;", token);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  7: deleteLockedMessageRequest.ContentLength = 0;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #ffffff; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 12px"&gt;  8: deleteLockedMessageRequest.GetResponse().Close();&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;That’s it. Create, Enqueue, Destructive Read, Peek/Lock Read, and .. oh .. yes.. forgot Delete the Queue. Take the snippet above and swap out the lockUri for the queueSelfUri. Done.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Ah, yes, and please … don’t blame me for HTTP or HttpWebRequest or Clemens’ demo coding style requiring too many lines of code. I could have applied a bit of code-compression here, but I’m intentionally trying not to abstract away too much of the protocol here. I’m generally with you, though. The guys putting together the &lt;A href="http://msdn.microsoft.com/wcf/rest"&gt;WCF REST Starter Kit&lt;/A&gt; are working on making code like that shrink.&lt;/P&gt;&lt;img width="0" height="0" src="http://vasters.com/clemensv/cptrk.ashx?id=4aefc36e-4476-4543-9574-13727c8f615d"&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9535294" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/clemensv/archive/tags/Azure/default.aspx">Azure</category><category domain="http://blogs.msdn.com/clemensv/archive/tags/Service+Bus/default.aspx">Service Bus</category><category domain="http://blogs.msdn.com/clemensv/archive/tags/Queues/default.aspx">Queues</category></item><item><title>.NET Services March 2009 CTP - Service Bus Routers And Queues - Part 3: The REST Queue Protocol</title><link>http://blogs.msdn.com/clemensv/archive/2009/04/02/net-services-march-2009-ctp-service-bus-routers-and-queues-part-3-the-rest-queue-protocol.aspx</link><pubDate>Thu, 02 Apr 2009 16:08:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9529799</guid><dc:creator>clemensv</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/clemensv/comments/9529799.aspx</comments><wfw:commentRss>http://blogs.msdn.com/clemensv/commentrss.aspx?PostID=9529799</wfw:commentRss><wfw:comment>http://blogs.msdn.com/clemensv/rsscomments.aspx?PostID=9529799</wfw:comment><description>&lt;P&gt;[If this text looks vaguely familiar you’ve read the HttpQueueSample Readme doc from the SDK. Good job!]&lt;/P&gt;
&lt;P&gt;Here is the Service Bus Queue REST protocol. I apologize if this is a bit dry, but I want to give you the bare protocol facts first and will follow-up with code samples later. Look at the HTTP Queue &lt;A href="http://www.microsoft.com/downloads/details.aspx?familyid=8D1D1D5E-1332-4186-B33F-26D053759E49&amp;amp;displaylang=en"&gt;SDK sample&lt;/A&gt; if you can’t wait for code ;-)&lt;/P&gt;
&lt;P&gt;You can find the HTTP Queue sample in the SDK install path under &lt;EM&gt;.\Samples\ServiceBus\ExploringFeatures\Queues\HttpMessages\&lt;/EM&gt; &lt;/P&gt;
&lt;P&gt;The beauty of REST is that there’s a uniform interface. It’s all just GET, POST, PUT, DELETE, a set of resources, and a rigorous application of the RFC2616 / HTTP 1.1 rules. That doesn’t make the description particularly entertaining, but it does yield a pretty consistent interaction model:&lt;/P&gt;
&lt;H5&gt;Authorization&lt;/H5&gt;
&lt;P&gt;All Queue operations require the client to be appropriately authorized. The client must therefore acquire an lightweight identity token from the Microsoft .NET Access Control Service using the .NET Services solution name and the solution password and include the acquired token with each request. The tokens are added to requests using the &lt;STRONG&gt;X-MS-Identity-Token&lt;/STRONG&gt; HTTP header. The value for this header is a short-lived token which can be used for a period of up to 8 hours and must be acquired from the .NET Access Control Service. We strongly encourage you to guard the acquired tokens in the same fashion as you would guard a credential and &lt;STRONG&gt;you should not&lt;/STRONG&gt; openly expose them unprotected on the network or web-pages or embedded in a Flash or Silverlight application. 
&lt;P&gt; 
&lt;P&gt;The request for acquiring the token is an HTTPS &lt;STRONG&gt;GET&lt;/STRONG&gt; on the URI &lt;EM&gt;&lt;STRONG&gt;https://accesscontrol.windows.net/issuetoken.aspx?u={solutionName}&amp;amp;p={solutionPassword}&lt;/STRONG&gt;&lt;/EM&gt; whereby you replace the arguments for solution name and the solution password with your .NET Services solution credentials. If a token is successfully issued to you the request returns with a 200 (OK) status code and contains a &lt;EM&gt;&lt;STRONG&gt;text/plain&lt;/STRONG&gt;&lt;/EM&gt; entity body with a short, base64 encoded token hash as a single line of text, which you for the value of the X-MS-Identity-Token header. 
&lt;H5&gt;Creating a Queue&lt;/H5&gt;
&lt;P&gt;A Queue is created on the Service Bus in four simple steps. I’ve discussed most of this in the post on &lt;A href="http://vasters.com/clemensv/PermaLink,guid,0f64f592-7239-42fc-aed2-f0993701c5f6.aspx"&gt;Queue Policies&lt;/A&gt;: 
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Select a name in the Service Bus naming hierarchy where the Queue should be located, i.e. &lt;STRONG&gt;https://&lt;/STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;mysolution&lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG&gt;.servicebus.windows.net/myapp/q1&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;&lt;A href="http://vasters.com/clemensv/PermaLink,guid,0f64f592-7239-42fc-aed2-f0993701c5f6.aspx"&gt;Create a Queue policy&lt;/A&gt; and define the desired properties of the Queue. &lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;Embed the Queue policy into an ATOM 1.0 &lt;EM&gt;&lt;STRONG&gt;&amp;lt;atom:entry&amp;gt;&lt;/STRONG&gt;&lt;/EM&gt; as an extension and &lt;STRONG&gt;POST&lt;/STRONG&gt; the entry to the designated Queue URI with the content-type &lt;EM&gt;&lt;STRONG&gt;application/atom+xml;type=entry&lt;/STRONG&gt;.&lt;/EM&gt; &lt;EM&gt;&lt;/EM&gt;The request must carry an X-MS-Identity-Token header and the respective identity must have 'Manage' permission on for scope covering the Queue URI.&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;If the queue was successfully created, the POST request returns with a &lt;STRONG&gt;201&lt;/STRONG&gt; 'created' status code along with a &lt;STRONG&gt;Location&lt;/STRONG&gt; header. The response entity body contains the effective Queue policy as applied to the name by the Service Bus. &lt;BR&gt;&lt;BR&gt;The location header contains the queue's management URI that you need to retain in your application state to have access to the queue's metadata and management functions. If the queue could not be created successfully, the request may yield the following status codes: 
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;400&lt;/STRONG&gt; - Bad Request. The policy was malformed or invalid.&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;403&lt;/STRONG&gt; - Forbidden. The client did not provide a X-MS-Identity-Token header, the provided token is no longer valid for use, or the provided identity is not authorized to create a Queue at this location.&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;409&lt;/STRONG&gt; - Conflict.&amp;nbsp; There is already a Queue with an incompatible policy at the given location or the location is occupied by a Router or a Service Bus listener.&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;415&lt;/STRONG&gt; - Unsupported Media Type. The request did not carry the required content-type header.&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;500&lt;/STRONG&gt; - Internal Server Error. The processing failed to to a condition internal to the Service Bus service.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;H5&gt;REST Anatomy of a Queue&lt;/H5&gt;
&lt;P&gt;Each Queue has five distinct types of resources: &lt;STRONG&gt;Policy&lt;/STRONG&gt;, &lt;STRONG&gt;Tail&lt;/STRONG&gt;, &lt;STRONG&gt;Head&lt;/STRONG&gt;, &lt;STRONG&gt;Locks&lt;/STRONG&gt;, and &lt;STRONG&gt;Control&lt;/STRONG&gt;. The concrete URIs are discoverable using the Service Registry's Atom Publishing protocol. you should not make any assumptions about the particular format of the URIs spelled out below since the particular format might change.&lt;/P&gt;
&lt;P&gt;The Atom 1.0 entry shown below is also enclosed in the response entity body of the create request (POST) explained above. A Queue's representation in the registry feed as seen when doing a &lt;STRONG&gt;GET&lt;/STRONG&gt; (discovery-) request on the queue's parent URI is commonly as follows:&lt;/P&gt;&lt;PRE&gt;&amp;lt;feed xmlns="http://www.w3.org/2005/Atom"&amp;gt;
  ...
  &amp;lt;entry&amp;gt;
    &amp;lt;id&amp;gt;{id}&amp;lt;/id&amp;gt;
    &amp;lt;title type="text"&amp;gt;MyHttpQueue&amp;lt;/title&amp;gt;
    &amp;lt;updated&amp;gt;{date}&amp;lt;/updated&amp;gt;
    &amp;lt;link rel="alternate" href="https://solution.servicebus.windows.net/myapp/q1" /&amp;gt;
    &amp;lt;link rel="self" href="https://solution.servicebus.windows.net/myapp/q1!(queue)" /&amp;gt;
    &amp;lt;link rel="queuehead" href="https://solution.servicebus.windows.net/myapp/q1!(queue/head)" /&amp;gt;
    &amp;lt;link rel="queuecontrol" href="https://solution.servicebus.windows.net/myapp/q1!(queue/control)" /&amp;gt;
    &amp;lt;QueuePolicy xmlns="http://schemas.microsoft.com/ws/2007/08/connect"&amp;gt;
      &amp;lt;Discoverability&amp;gt;Public&amp;lt;/Discoverability&amp;gt;
      &amp;lt;ExpirationInstant&amp;gt;{expiration}&amp;lt;/ExpirationInstant&amp;gt;
    &amp;lt;/QueuePolicy&amp;gt;
  &amp;lt;/entry&amp;gt;
&amp;lt;/feed&amp;gt;&lt;/PRE&gt;
&lt;H5&gt;&lt;/H5&gt;
&lt;H5&gt;Managing The Queue&lt;/H5&gt;
&lt;P&gt;&lt;EM&gt;&amp;lt;link rel="self" href="https://solution.servicebus.windows.net/myapp/q1!(queue)" /&amp;gt; &lt;BR&gt;&lt;/EM&gt;&lt;BR&gt;The "&lt;STRONG&gt;self&lt;/STRONG&gt;" link in the entry above is the queue's management URI that allows you to interact with the queue's policy. &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;To renew a queue and extend its expiration you &lt;STRONG&gt;PUT&lt;/STRONG&gt; an updated Atom 1.0 entry with the effective policy and an updated &lt;EM&gt;ExpirationInstant&lt;/EM&gt; value to the "self" URI.&amp;nbsp; The "self" URI is the same URI as the one returned in the &lt;STRONG&gt;Location&lt;/STRONG&gt; header returned by the create POST explained above. The request will yield a &lt;STRONG&gt;200&lt;/STRONG&gt; status code if the renewal is successful. It will yield a&lt;STRONG&gt; 404&lt;/STRONG&gt; if the queue no longer exists.&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;To delete a queue you issue a&lt;STRONG&gt; DELETE &lt;/STRONG&gt;request on&amp;nbsp; the queue's management URI. The Delete request is sent without any entity body and MUST have a Content-Length header that is set to zero (0). Not setting this header will yield a &lt;STRONG&gt;411&lt;/STRONG&gt; status code. The request yields a &lt;STRONG&gt;204&lt;/STRONG&gt; response if the queue was deleted successfully.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;H5&gt;Enqueue&lt;/H5&gt;
&lt;P&gt;&lt;EM&gt;&amp;lt;link rel="alternate" href="https://solution.servicebus.windows.net/myapp/q1" /&amp;gt;&lt;/EM&gt; 
&lt;P&gt; 
&lt;P&gt; 
&lt;P&gt;The "&lt;STRONG&gt;alternate&lt;/STRONG&gt;" link refers to the tail of the queue. The Queue's &lt;EM&gt;tail&lt;/EM&gt; resource is where senders submit messages into the Queue. The queue's tail URI is identical to the URI where the queue was initially created. The queue's tail endpoint accepts requests with any HTTP Content-Type and any HTTP method except GET, HEAD, and OPTIONS.&lt;/P&gt;
&lt;P&gt;The endpoint should be considered a 'delegate' of the message recipient and not the resource that the respective operations have an immediate effect on. That means that the HTTP method applied to the Queue tail doesn’t have any particular semantic. If a message has been successfully accepted into the queue, the request returns a &lt;STRONG&gt;202&lt;/STRONG&gt; status code. Otherwise it will return a &lt;STRONG&gt;500&lt;/STRONG&gt; &lt;/P&gt;
&lt;H5&gt;Dequeue and Peek/Lock&lt;/H5&gt;
&lt;P&gt;&lt;EM&gt;&amp;lt;link rel="queuehead" href="https://solution.servicebus.windows.net/myapp/q1!(queue/head)" /&amp;gt;&lt;BR&gt;&lt;/EM&gt;
&lt;P&gt;The "&lt;STRONG&gt;queuehead&lt;/STRONG&gt;" link refers to the head of the Queue. The Queue's &lt;EM&gt;head&lt;/EM&gt; resource is where receivers retrieve messages from the queue. It is modeled as a resource whose current representation corresponds to the message(s) that reside at the head of the queue and which is/are next in line to be retrieved by consumers. Permitted operations on the head are: 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;DELETE&lt;/STRONG&gt;:&amp;nbsp; Delete performs a destructive read on the queue whereby the message(s) at the head of the queue are permanently deleted and returned as the entity body of the response to the request. The content type and formatting of the response depends on a set of query parameters that are discussed below. The DELETE request's response status code is &lt;STRONG&gt;200&lt;/STRONG&gt; if at least one message could be retrieved and deleted from the queue and the message content is enclosed in the response's entity body. The response status code is &lt;STRONG&gt;204&lt;EM&gt; &lt;/EM&gt;&lt;/STRONG&gt;if no message could be retrieved/deleted. 
&lt;LI&gt;&lt;STRONG&gt;POST:&lt;/STRONG&gt; Post creates a lock on the message(s) at the head of the queue and returns the locked messages. Locked messages are temporarily removed from the head of the queue for a period of 1 minute during which time the receiver can decide whether to return the message to the head of the queue or whether to permanently delete it. The POST request's response status code is &lt;STRONG&gt;200&lt;/STRONG&gt; if at least one message could be retrieved and locked on the queue and the message content is enclosed in the response's entity body. The response status code is &lt;STRONG&gt;204&lt;EM&gt; &lt;/EM&gt;&lt;/STRONG&gt;if no message could be retrieved/locked.&lt;/LI&gt;&lt;/UL&gt;
&lt;H5&gt;Releasing and Deleting Peek/Lock Message Locks &lt;/H5&gt;
&lt;P&gt;Any retrieved, peek/locked message (POST on “queuehead”) contains an HTTP header &lt;STRONG&gt;X-MS-Message-Lock &lt;/STRONG&gt;whose value is a URI. The following operations can be performed on this URI:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;DELETE: &lt;/STRONG&gt;The message has been accepted/processed by the receiver and the lock shall be deleted. The deletion of the lock discards the message permanently from the queue. The Delete request is sent without any entity body and MUST have a Content-Length header that is set to zero (0). Not setting this header will yield a &lt;STRONG&gt;411&lt;/STRONG&gt; status code. The request yields a &lt;STRONG&gt;204&lt;/STRONG&gt; response if the lock was deleted successfully. 
&lt;LI&gt;&lt;STRONG&gt;PUT:&lt;/STRONG&gt;&amp;nbsp; The message has been not been accepted/processed by the receiver and the message shall be put back at the head of the queue. This operation transitions the lock from the locked state into the unlocked state which releases the message back into the queue. The lock itself is discarded afterwards. The Put request is sent without any entity body and MUST have a Content-Length header that is set to zero (0). Not setting this header will yield a &lt;STRONG&gt;411&lt;/STRONG&gt; status code. The request yields a &lt;STRONG&gt;204&lt;/STRONG&gt; response if the lock was released successfully.&lt;/LI&gt;&lt;/UL&gt;
&lt;H5&gt;Options for Dequeue and Peek/Lock&lt;/H5&gt;
&lt;P&gt;The &lt;STRONG&gt;DELETE&lt;/STRONG&gt; and &lt;STRONG&gt;POST&lt;/STRONG&gt; operation have a set of options that are expressed as query parameters appended to the queue's head URI. The options are the same for both operations:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;timeout=&lt;/STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;value&lt;/STRONG&gt; - &lt;/EM&gt;The value is a numerical value (expressed in seconds) that indicates how long the client is willing to wait for the polling request to complete. The value should not exceed 60 seconds and a value of 30 seconds is a safer choice with intermediate proxies in place. If the timeout expires and no message is available, the request completes with a&lt;STRONG&gt; 204 &lt;/STRONG&gt;response code. &lt;STRONG&gt;&lt;/STRONG&gt;The default value is zero (0), which means that the request returns immediately.&lt;BR&gt;&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;maxmessages=&lt;EM&gt;value&lt;/EM&gt;&lt;/STRONG&gt;&lt;EM&gt; - &lt;/EM&gt;Indicates how many messages the client is willing to accept in a single response. The default is 1. The service will return at most 10 messages at a time and a value greater than zero &lt;EM&gt;requires&lt;/EM&gt; encoding=multipart (see below)&lt;BR&gt;&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;encoding=&lt;EM&gt;value&lt;/EM&gt;&lt;/STRONG&gt;&lt;EM&gt; - &lt;/EM&gt;There are three supported encoding modes for the REST retrieval model 
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;asreply&lt;/STRONG&gt; - The request stored in the Queue is mapped onto the response to the DELETE/POST request returning the message from the queue. This option requires maxmessages=1 or omission of the maxmessages option.&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;single&lt;/STRONG&gt; - The request stored in the queue is returned as a complete HTTP request frame on the response to the DELETE/POST request using Content-Type &lt;STRONG&gt;&lt;A href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.1"&gt;application/http&lt;/A&gt;&lt;/STRONG&gt;. This option requires maxmessages=1 or omission of the maxmessages option.&lt;/P&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;multipart&lt;/STRONG&gt; - The request(s) stored in the queue are returned as a complete HTTP request frames on the response to the DELETE/POST request using Content-Type &lt;STRONG&gt;&lt;A href="http://www.ietf.org/rfc/rfc2046.txt"&gt;multipart/mixed&lt;/A&gt;&lt;/STRONG&gt; with MIME parts of Content-Type &lt;STRONG&gt;&lt;A href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.1"&gt;application/http&lt;/A&gt;&lt;/STRONG&gt;. &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;H5&gt;Queue Content Control&lt;/H5&gt;
&lt;P&gt;&lt;EM&gt;&amp;lt;link rel="queuecontrol" href="https://solution.servicebus.windows.net/myapp/q1!(queue/control)" /&amp;gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The "&lt;STRONG&gt;queuecontrol&lt;/STRONG&gt;" link refers to the &lt;EM&gt;control&lt;/EM&gt; resource provides information about the status of the queue and allows for purging all of the queue's contents. The control resource is present in the current CTP, but you cannot perform any operations on it. &lt;/P&gt;&lt;img width="0" height="0" src="http://vasters.com/clemensv/cptrk.ashx?id=413c6128-a6a6-4894-9cc9-701ffb674ab0"&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9529799" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/clemensv/archive/tags/Azure/default.aspx">Azure</category><category domain="http://blogs.msdn.com/clemensv/archive/tags/Service+Bus/default.aspx">Service Bus</category><category domain="http://blogs.msdn.com/clemensv/archive/tags/Queues/default.aspx">Queues</category></item><item><title>.NET Services March 2009 CTP - Service Bus Routers And Queues - Part 2: Queue Policies</title><link>http://blogs.msdn.com/clemensv/archive/2009/04/02/net-services-march-2009-ctp-service-bus-routers-and-queues-part-2-queue-policies.aspx</link><pubDate>Thu, 02 Apr 2009 14:10:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9529656</guid><dc:creator>clemensv</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/clemensv/comments/9529656.aspx</comments><wfw:commentRss>http://blogs.msdn.com/clemensv/commentrss.aspx?PostID=9529656</wfw:commentRss><wfw:comment>http://blogs.msdn.com/clemensv/rsscomments.aspx?PostID=9529656</wfw:comment><description>&lt;P&gt;&lt;A href="http://vasters.com/clemensv/PermaLink,guid,8e30d2eb-6e2d-4dc5-8aba-5aa410e450de.aspx"&gt;In the previous post in this series&lt;/A&gt; I’ve discussed some of the foundational principles of the new Queue and Router features of the .NET Services Bus and the role that policies play in turning names in the namespace into messaging primitives. In this post I’ll start drilling into the capabilities of the Queue feature and will discuss what’s in the queue policy. &lt;/P&gt;
&lt;P&gt;The capabilities of the Queue are best explored by looking at the Queue policy. Policies can be expressed in two ways: You can either you use the .NET Services SDK’s &lt;STRONG&gt;Microsoft.ServiceBus.QueuePolicy&lt;/STRONG&gt; class with a .NET application or you can just whip up a bit of XML. The structure and the serialized representation of that class is exactly equivalent to an XML queue policy you’d wire up “by hand” and thus I’ll discuss the policy in terms of its XML elements:&lt;/P&gt;
&lt;P&gt;The queue policy has the element name “&lt;STRONG&gt;QueuePolicy&lt;/STRONG&gt;” within the XML namespace “&lt;EM&gt;&lt;STRONG&gt;http://schemas.microsoft.com/ws/2007/08/connect&lt;/STRONG&gt;”. &lt;/EM&gt;That’s the namespace we use for most protocols and data structures in the .NET Service Bus at this development stage and you should expect that we’re migrating to the “final” V1 namespaces in one of the next CTPs.&amp;nbsp; If you use the .NET class you’ll just have to recompile to snap to new namespaces once they come around.&lt;/P&gt;
&lt;P&gt;Below is a list of the policy’s elements and the permitted values. All elements are optional and can appear at most once. The default value applies when an element is omitted. It’s perfectly ok to send an empty &lt;EM&gt;QueuePolicy&lt;/EM&gt; and accept the default values to keep things simple. I’d recommend to always set the &lt;EM&gt;ExpirationInstant&lt;/EM&gt; value, however. &lt;/P&gt;
&lt;P&gt;One required forward reference: Don’t get confused or distracted trying to figure out from here what it means “to provide an authorization token”. The docs explain this and I’ll also address this in the next blog post when I dive into the protocol. &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Authorization&lt;/STRONG&gt; – The authorization setting indicates whether sender and/or consumers must provide a security token when interacting with the queue. You can explicitly permit the .NET Service Bus to allow anonymous consumers and/or anonymous senders on a Queue. If a token is required, a sender must present a token with “Send” permission that is issued by the .NET Access Control service and the consumer must present a token with “Listen” permission that is issued by the .NET Access Control service. The respective rules are set up in the .NET Access Control service on your project’s “Service Bus” scope. Mind that all anonymous traffic is attributed to the “manager” of a Queue, i.e. to whoever sets the policy; all traffic is metered and accounted for. The permitted values for this element are: 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Required&lt;/STRONG&gt; – (default) Senders and Consumers must provide an authorization token to send/retrieve messages. 
&lt;LI&gt;&lt;STRONG&gt;RequiredToSend&lt;/STRONG&gt; – Senders must provide an authorization token with a “Send” claim to send messages, consumers don’t. 
&lt;LI&gt;&lt;STRONG&gt;RequiredToReceive&lt;/STRONG&gt; – Consumers must provide an authorization token with a “Listen” claim to receiver messages, senders don’t. 
&lt;LI&gt;&lt;STRONG&gt;NotRequired&lt;/STRONG&gt; – Neither senders nor consumers must provide a token, i.e. the queue is set up for anonymous traffic.&lt;BR&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Discoverability&lt;/STRONG&gt; – The discoverability setting defines under which conditions the Queue and its policy are visible in the Service Registry Atom feed and any forthcoming discoverability mechanisms. When you are browsing the Service Registry feed from within a browser, the only setting that will make the Queue visible is &lt;EM&gt;Public&lt;/EM&gt; since the browser isn’t able to attach an authorization token without some scripting assistance.&amp;nbsp; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Managers&lt;/STRONG&gt; - (default) The Queue and its policy are only discoverable if you provide an authorization token with the request and the token carries a “Manage” claim. 
&lt;LI&gt;&lt;STRONG&gt;ManagersListeners&lt;/STRONG&gt; – The Queue and its policy are only discoverable if you provide and authorization token with the request and the token carries a “Manage” and/or “Listen” claim. 
&lt;LI&gt;&lt;STRONG&gt;ManagersListenersSenders&lt;/STRONG&gt; – The Queue and its policy are only discoverable if you provide and authorization token with the request and the token carries a “Manage” and/or “Listen” and/or “Send” claim. 
&lt;LI&gt;&lt;STRONG&gt;Public&lt;/STRONG&gt; – The Queue and its policy are discoverable without any authorization requirement, i.e. the general public.&lt;BR&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;&lt;STRONG&gt;ExpirationInstant&lt;/STRONG&gt; – This is an XML dateTime value indicating the TTL (time-to-live) for the Queue. You can make Queues long-lived or short-lived. A Queue’s lifetime may be extended by changing this policy value and reapplying the policy. Once a Queue expires it is removed from the system along with all the messages that reside in it. The system may limit the Queue lifetime in the effective policy that you get back from the create/update request, but we’ll typically allow at least 24 hours without renewal. This value has a default of 24 hours, a maximum of 21 days and a minimum of 30 seconds. The value must represent a future dateTime and must be expressed in UTC. &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;MaxMessageSize&lt;/STRONG&gt; – This is a numeric value defining the maximum size of any individual message that can be accepted into the Queue. The maximum message size is expressed in bytes and includes all infrastructure-imposed and encoding-related overhead. The actual overhead varies significantly based on whether messages are sent as SOAP 1.1, SOAP 1.2, or plain HTTP frames using text or binary encoding and whether a security token is required. A very defensive assumption is to reserve 10-12KB for protocol overhead in complex cases with WS* Security; the minimal allocation for protocol overhead should be around 4KB. The &lt;STRONG&gt;default&lt;/STRONG&gt; and &lt;STRONG&gt;maximum&lt;/STRONG&gt; values for the maximum message size is &lt;STRONG&gt;60KB&lt;/STRONG&gt; (60*1024 bytes). The minimum value is &lt;STRONG&gt;8KB&lt;/STRONG&gt;. We suggest that the &lt;STRONG&gt;payload size&lt;/STRONG&gt; for an individual message does &lt;STRONG&gt;not exceed&lt;/STRONG&gt; &lt;STRONG&gt;48KB&lt;/STRONG&gt;, even though you can try to push it a bit. The expectation is that these values will trend up but I don’t see them more than doubling due to throughput, timeliness and scale considerations. If your data is larger you should consider how you can chunk it up. &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;TransportProtection&lt;/STRONG&gt; – The transport protection setting defines whether senders and consumers &lt;STRONG&gt;must&lt;/STRONG&gt; use HTTPS to interact with the Queue. This is the default setting. You would modify this to accommodate clients – typically on devices - that don’t do HTTPS all that well. Permitted values:&amp;nbsp; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;AllPaths&lt;/STRONG&gt; - (default) Any interaction with the queue requires HTTPS. 
&lt;LI&gt;&lt;STRONG&gt;None&lt;/STRONG&gt; – Any interaction may be performed using either HTTP or HTTPS.&lt;BR&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;&lt;STRONG&gt;EnqueueTimeout&lt;/STRONG&gt; – The enqueue timeout is an XML duration value that specifies how long an enqueue operation will hang if the queue is at capacity (full). The default value is 10 seconds, the minimum is 0 seconds, and the maximum is 60 seconds. If the timeout expires and the message could not be added to the queue during that time, the queue will act according to the &lt;STRONG&gt;Overflow&lt;/STRONG&gt; policy setting. &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;MaxConcurrentReaders&lt;/STRONG&gt; - &lt;FONT color=#ff8000&gt;[this setting not supported/enforced in the March 2009 CTP]&lt;/FONT&gt; The &lt;EM&gt;maximum concurrent readers&lt;/EM&gt; value defines how many concurrent readers are permitted on the queue. If this numeric value is smaller than the default value of 2^31 (max int), the queue protocol will switch into ‘session mode’ that grants a limited number of read-locks on the queue. The minimum value is 1. &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;MaxDequeueRetries&lt;/STRONG&gt; - &lt;FONT color=#ff8000&gt;[this setting not supported/enforced in the March 2009 CTP]&lt;/FONT&gt; The &lt;EM&gt;maximum dequeue retries&lt;/EM&gt; value defines how often a message may be peek/locked and put back into the queue until it is considered poisonous, i.e. after how many retries it should be expected the the consumer will not be able to ever consume the message successfully, because it is malformed or the consumer experiences an error condition that requires some form of manual intervention (including a bug fix). If the message is found to be poisonous it will be sent once and without any retries to the endpoint specified in the policy’s &lt;STRONG&gt;PoisonMessageDrop&lt;/STRONG&gt; value. &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;MaxMessageAge&lt;/STRONG&gt; – The &lt;EM&gt;maximum message age&lt;/EM&gt; is an XML duration value indicating after what time any enqueued message is considered ‘stale” and will be automatically dropped and removed from the queue. The default value is 10 minutes (600 seconds), the minimum value is 0 seconds (which effectively means that all incoming messages get dropped), the maximum value is 7 days. &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;MaxQueueCapacity&lt;/STRONG&gt; – This numeric value indicates the maximum size of the Queue in bytes. This is a system-calculated value that cannot be set on the .NET class and should not be set by clients creating policies from scratch. The default and &lt;STRONG&gt;maximum capacity&lt;/STRONG&gt; of any queue is currently capped at &lt;STRONG&gt;2MB&lt;/STRONG&gt;. This is a limitation specific to the March 2009 CTP , it’s been painful to impose this constraint, and it’s absolutely expected that this limit will be expanded significantly. 2MB still allow for a several hundred notification messages of a 2-4KB. If you need to store more data you can absolutely create several queues and partition data across them either explicitly or using Routers with a load-balancing message distribution policy (more on that in a subsequent post). &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;MaxQueueLength&lt;/STRONG&gt; – This numeric value indicates the maximum queue length. The maximum and default value is 2^31, the minimum value is 1. &lt;FONT color=#ff8000&gt;We’re not enforcing the exact queue length in the March 2009 CTP&lt;/FONT&gt;, but your code should assume that we do. The queue length value is the basis for the calculation of the &lt;STRONG&gt;MaxQueueCapacity&lt;/STRONG&gt;, with MaxQueueCapacity = min(MaxQueueLength * MaxMessageSize, 2MB) enforcing the hard 2MB limit that is currently in effect. You don’t need to touch this value unless you’d really want a Queue that’s even more size-constrained. &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;Overflow&lt;/STRONG&gt; – The overflow policy setting becomes relevant when the queue is at capacity and the &lt;STRONG&gt;EnqueueTimeout&lt;/STRONG&gt; has expired. It tells the Queue what to do with the message that just came in and that can’t be put into the queue because it’s full. Permitted values:&amp;nbsp; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;RejectIncomingMessage&lt;/STRONG&gt; - (default) The message will be rejected and an error status code or SOAP fault will be sent to the sender. 
&lt;LI&gt;&lt;STRONG&gt;DiscardIncomingMessage&lt;/STRONG&gt; – The sender will get an indication that the message has been accepted, but the message will be dropped on the floor. 
&lt;LI&gt;&lt;STRONG&gt;DiscardExistingMessage&lt;/STRONG&gt; – The Queue will remove and discard messages from the head of the Queue until the new, incoming message fits in the Queue.&lt;BR&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;&lt;STRONG&gt;PoisonMessageDrop&lt;/STRONG&gt; – &lt;FONT color=#ff8000&gt;[this setting not supported in the March 2009 CTP]&lt;/FONT&gt; This value is a WS-Addressing 1.0 EndpointReference referring to an endpoint that any poison messages will be sent to once the &lt;STRONG&gt;MaxDequeueRetries&lt;/STRONG&gt; limit has been exceeded. The EndpointReference may point to any SOAP or plain HTTP endpoint that can accept ‘any’ message. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Phew! Lots of options. The good thing is that most apps should be ok with the defaults. &lt;/P&gt;
&lt;P&gt;I know that the 2MB capacity limit is somewhat disappointing and I’m certainly not happy with it. There’s a particular behavior (with bug number) that may occur under very rare circumstances in the underlying replication system, which caused us to play it very safe instead of risking data loss. I don’t think the limit is a showstopper for apps that send notifications and events around – it is a showstopper for apps that want to exchange larger payloads and we’re working to relax that limit and make Queues much, much larger as soon as we can. You can obviously always spool larger data into SDS or one of the Azure storage systems and then send a reference to that data as a message, but it’d be strange for a messaging system to make that a required pattern for data of all sizes. If we’re talking hundreds of megabytes it makes sense, though.&lt;/P&gt;
&lt;P&gt;With the due apology out of the way, let’s look at how a policy may be applied to a namespace name – or in other words, how a queue is created in the simplest case (this must be done via HTTPS). The model here is that the client &lt;EM&gt;proposes&lt;/EM&gt; a policy and Service Bus is at liberty to adjust the policy. &lt;/P&gt;
&lt;P&gt;If you are intimately familiar with Atom, you’ll notice that the &amp;lt;QueuePolicy&amp;gt; is an extension and isn’t carried as &amp;lt;content&amp;gt;. That’s by intent. &amp;lt;content&amp;gt; is for people, extensions are for apps. We’ll start using &amp;lt;content&amp;gt; in a later milestone, so consider that being &lt;EM&gt;reserved&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;HTTP/1.1 POST /myapp/q1&lt;BR&gt;Host: clemensv.servicebus.windows.net&lt;BR&gt;X-MS-Identity-Token: A6hbJklu18hsnHRql61k1==&lt;BR&gt;Content-Type: application/atom+xml;type=entry;charset=utf-8&lt;BR&gt;Content-Length: nnn&lt;BR&gt;&lt;BR&gt;&amp;lt;entry xmlns=”&lt;EM&gt;http://www.w3.org/2005/Atom&lt;/EM&gt;”&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;QueuePolicy xmlns=”&lt;/STRONG&gt;&lt;STRONG&gt;&lt;EM&gt;http://schemas.microsoft.com/ws/2007/08/connect”&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ExpirationInstant&amp;gt;2009-04-03T12:00:00&amp;lt;/ExpirationInstant&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/QueuePolicy&amp;gt; &lt;/EM&gt;&lt;BR&gt;&amp;lt;/entry&amp;gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;If the queue can be created, the response is a 200 and you get the policy back along with any adjustments that the service may make. This is called the “effective” policy, i.e. that’s what the server is using. You also learn about where you can modify the policy, since – &lt;A href="http://vasters.com/clemensv/PermaLink,guid,8e30d2eb-6e2d-4dc5-8aba-5aa410e450de.aspx"&gt;as I explained before&lt;/A&gt; – the endpoint where you POST the policy to is morphing into the Queue’s tail.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;HTTP/1.1 200 OK&lt;BR&gt;Location: https://project-name.servicebus.windows.net/myapp/q1!(queue)&lt;BR&gt;Content-Type: application/atom+xml;type=entry;charset=utf-8&lt;BR&gt;Content-Length: nnn&lt;BR&gt;&lt;BR&gt;&amp;lt;entry xmlns=”&lt;EM&gt;http://www.w3.org/2005/Atom&lt;/EM&gt;”&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;link rel=”self” href=”https://project-name.servicebus.windows.net/myapp/q1!(queue)” /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;link rel=”alternate” href=”https://project-name.servicebus.windows.net/myapp/q1” /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;link rel=”queuehead” href=”https://project-name.servicebus.windows.net/myapp/q1!(queue/head)” /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;QueuePolicy xmlns=”&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;&lt;EM&gt;http://schemas.microsoft.com/ws/2007/08/connect” &amp;gt;&lt;BR&gt;&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ExpirationInstant&amp;gt;2009-04-03T12:00:00&amp;lt;/ExpirationInstant&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;MaxQueueCapacity&amp;gt;2097152&amp;lt;/MaxQueueCapacity&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/QueuePolicy&amp;gt;&lt;BR&gt;&amp;lt;/entry&amp;gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;If you want to renew the Queue (extend the expiration), take the effective policy, adjust ExpirationInstant and do a PUT to the “self” location. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New"&gt;HTTP/1.1 PUT /myapp/q1&lt;FONT color=#ff0000&gt;!(queue)&lt;/FONT&gt;&lt;BR&gt;Host: project-name.servicebus.windows.net&lt;BR&gt;X-MS-Identity-Token: A6hbJklu18hsnHRql61k1==&lt;BR&gt;Content-Type: application/atom+xml;type=entry;charset=utf-8&lt;BR&gt;Content-Length: nnn&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;FONT face="Courier New"&gt;&amp;lt;entry xmlns=”&lt;EM&gt;http://www.w3.org/2005/Atom&lt;/EM&gt;”&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;link rel=”self” href=”https://project-name.servicebus.windows.net/myapp/q1!(queue)” /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;link rel=”alternate” href=”https://project-name.servicebus.windows.net/myapp/q1” /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;link rel=”queuehead” href=”https://project-name.servicebus.windows.net/myapp/q1!(queue/head)” /&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;QueuePolicy xmlns=”&lt;/FONT&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;FONT face="Courier New"&gt;&lt;EM&gt;http://schemas.microsoft.com/ws/2007/08/connect” &amp;gt;&lt;BR&gt;&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ExpirationInstant&amp;gt;&lt;FONT color=#ff0000&gt;2009-04-04T12:00:00&lt;/FONT&gt;&amp;lt;/ExpirationInstant&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;MaxQueueCapacity&amp;gt;2097152&amp;lt;/MaxQueueCapacity&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/QueuePolicy&amp;gt;&lt;BR&gt;&amp;lt;/entry&amp;gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;[&lt;STRONG&gt;&lt;FONT color=#008080&gt;Bug note:&lt;/FONT&gt;&lt;/STRONG&gt; The PUT will return the new effective policy just like the POST response shown above, but the returned Atom &amp;lt;links&amp;gt; aren’t correctly formed. Keep the ones returned from the POST]&lt;/P&gt;
&lt;P&gt;If you want to delete the queue, just nuke the policy:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New"&gt;HTTP/1.1 DELETE /myapp/q1&lt;FONT color=#ff0000&gt;!(queue)&lt;/FONT&gt;&lt;BR&gt;Host: project-name.servicebus.windows.net&lt;BR&gt;X-MS-Identity-Token: A6hbJklu18hsnHRql61k1==&lt;BR&gt;Content-Length: 0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;So that’s the policy story for Queues. In the next posts I’ll discuss the REST Queue protocol and the SOAP Queue protocol for how you send message to the queue and get messages out. REST I’ll explain in protocol terms, the SOAP model in .NET programming model terms. &lt;/P&gt;&lt;img width="0" height="0" src="http://vasters.com/clemensv/cptrk.ashx?id=0f64f592-7239-42fc-aed2-f0993701c5f6"&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9529656" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/clemensv/archive/tags/Azure/default.aspx">Azure</category><category domain="http://blogs.msdn.com/clemensv/archive/tags/Service+Bus/default.aspx">Service Bus</category><category domain="http://blogs.msdn.com/clemensv/archive/tags/Queues/default.aspx">Queues</category></item></channel></rss>