<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Phil Leggetter - Real-Time Web Software and Technology Evangelist &#187; C#</title>
	<atom:link href="http://www.leggetter.co.uk/tag/c/feed" rel="self" type="application/rss+xml" />
	<link>http://www.leggetter.co.uk</link>
	<description>Real-Time Web, Real-Time Data and Social Media Software and Technology Evangelist and Consultant</description>
	<lastBuildDate>Sun, 29 Jan 2012 05:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Adding a real-time &quot;Who&#8217;s shopping?&quot; widget to an ASP.NET Web App</title>
		<link>http://www.leggetter.co.uk/2011/08/04/adding-a-real-time-whos-shopping-widget-to-an-asp-net-web-app.html</link>
		<comments>http://www.leggetter.co.uk/2011/08/04/adding-a-real-time-whos-shopping-widget-to-an-asp-net-web-app.html#comments</comments>
		<pubDate>Thu, 04 Aug 2011 00:00:00 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[pusher]]></category>
		<category><![CDATA[real-time]]></category>
		<category><![CDATA[real-time web]]></category>

		<guid isPermaLink="false">http://blog.pusherapp.com/2011/8/3/adding-a-real-time-who-s-shopping-widget-to-an-asp-net-web-app</guid>
		<description><![CDATA[<p>In our last ASP.NET post, <a href="http://blog.pusher.com/2011/6/25/the-easiest-way-to-add-real-time-functionality-to-an-asp-net-e-commerce-application">The easiest way to add real-time functionality to an ASP.NET e-commerce application</a>, I demonstrated how to add realtime stock level updates and notifications to an ASP.NET e-commerce application. In this post I&#8217;m going to show how to add a &#8220;Who&#8217;s shopping?&#8221; widget to the same application. The purpose of [...]
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2011/07/05/the-easiest-way-to-add-real-time-functionality-to-an-asp-net-e-commerce-application.html' rel='bookmark' title='The easiest way to add real-time functionality to an ASP.NET e-commerce application'>The easiest way to add real-time functionality to an ASP.NET e-commerce application</a></li>
<li><a href='http://www.leggetter.co.uk/2010/12/17/kwwika-powered-real-time-opta-sports-cricket-widget.html' rel='bookmark' title='Kwwika Powered Real-Time Opta Sports Cricket Widget'>Kwwika Powered Real-Time Opta Sports Cricket Widget</a></li>
<li><a href='http://www.leggetter.co.uk/2011/06/28/recent-article-in-net-magazine-websockets-code-a-real-time-survey.html' rel='bookmark' title='Recent article in .net magazine: WebSockets &#8211; Code a real-time survey'>Recent article in .net magazine: WebSockets &#8211; Code a real-time survey</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In our last ASP.NET post, <a  href="http://blog.pusher.com/2011/6/25/the-easiest-way-to-add-real-time-functionality-to-an-asp-net-e-commerce-application">The easiest way to add real-time functionality to an ASP.NET e-commerce application</a>, I demonstrated how to add realtime stock level updates and notifications to an ASP.NET e-commerce application. In this post I&#8217;m going to show how to add a &#8220;Who&#8217;s shopping?&#8221; widget to the same application. The purpose of this widget is to show other users that interest in the product they are viewing is high and that, in combination with the realtime stock levels, will encourage them to make a purchase before the product sells out.</p>
<p>In this tutorial I&#8217;ll show how to:</p>
<ul>
<li>subscribe to a presence channel</li>
<li>authenticate a subscription to a channel</li>
<li>provide Pusher with additional information about a user</li>
<li>display presence information on a product page for the &#8220;Who&#8217;s shopping?&#8221; widget</li>
</ul>
<p>If you are desperate to see the demo in action you can see the <a  href="http://realtimewebstore.apphb.com/">Real-Time Web Store demo here</a>.</p>
<h2>Pusher Presence</h2>
<p>To achieve the &#8220;Who&#8217;s shopping?&#8221; functionality I&#8217;m going to be using a feature in Pusher called <a  href="http://pusher.com/docs/client_api_guide/client_channels#subscribe-presence-channels">presence</a>. Presence provides you with additional information about a channel you are subscribed to so that you know:</p>
<ul>
<li>who is subscribed to that channel</li>
<li>when new users subscribe</li>
<li>when existing users unsubscribe (by either actually unsubscribing or navigating away from the page).</li>
</ul>
<p>We are going to have a presence channel per product so that we know who is viewing each product.</p>
<h2>User Info &amp; Authentication</h2>
<h3>Subscribing to a presence channel</h3>
<p>You subscribe to a presence channel in the same way that you do to any other channel but the name of the channel must have a <code>presence-</code> prefix. Presence channels are normal channels with two additions; authentication and presence information. With this in mind we are just going to update our application to use a presence channel.</p>
<p>The JavaScript that makes the subscription in our Razor view looks like this:</p>
<pre><code>var productId = "@Model.ProductId";
var pusher = new Pusher("APP_KEY");
var channel = pusher.subscribe("presence-" + productId);
</code></pre>
<p>We also need to update the code in our <code>StoreController</code> to publish our stock events on the new presence channel:</p>
<pre><code>var stockEvent = new StockUpdatedEvent(model, socketId);
ObjectPusherRequest request = new ObjectPusherRequest("presence-" + stockEvent.ProductId, "stockUpdated", stockEvent);
_provider.Trigger(request);
</code></pre>
<p><em>Note: If you are continuing where we left off in our last blog post there are a final couple of updates that are required to change the app to use the latest version of the Pusher JavaScript API. We recently released version 1.9 which introduced <a  href="http://blog.pusher.com/2011/7/12/connections-states">new connection state functionality</a> and also a new <code>connection</code> object. So, update your Pusher script tag as follows:</em></p>
<pre><code>&lt;script src="http://js.pusherapp.com/1.9/pusher.js"&gt;&lt;/script&gt;
</code></pre>
<p><em>And you&#8217;ll also need to update any pieces of code that access the <code>socket_id</code> via the <code>Pusher</code> instance. It should now be accessed via the new <code>connection</code> object as follows:</em></p>
<pre><code>var socketId = pusher.connection.socket_id;
</code></pre>
<h3>Getting User information</h3>
<p>If Pusher is to send events about users subscribing to and unsubscribing from presence channels it needs information about the users. It gets this information from your application when the subscription request to the channel is made (<code>pusher.subscribe('presence-channel')</code>). Since we can&#8217;t really trust the web browser/client (it&#8217;s so easy to hack JavaScript running in a web browser) the Pusher library requests this information from your web server by making an AJAX call. By default this call goes to <code>/pusher/auth</code> and passes two parameters; <code>channel_name</code>, which is the name of the channel being subscribed to, and <code>socket_id</code>, which is a unique identifier for the current user&#8217;s connection to Pusher.</p>
<pre><code>/pusher/auth/?channel_name=presence-pusher-tshirt&amp;socket_id=&lt;unique_socket_id&gt;
</code></pre>
<p>When our application responds to this request we must provide an authentication signature to confirm that the user can subscribe to the channel and, importantly for our &#8220;Who&#8217;s shopping?&#8221; widget, information about the current user. The way we&#8217;ll handle this within our ASP.NET MVC application is by creating a <code>PusherController</code> with an <code>Auth(string socket_id, string channel_name)</code> action, and by using the authentication functionality within the <a  href="https://github.com/leggetter/pusher-rest-dotnet">PusherRESTDotNet library</a>. This library is also available as a <a  href="http://nuget.org/List/Packages/PusherRESTDotNet">NuGet package</a>.</p>
<p><em>Note: If you got the NuGet package as part of the last tutorial you&#8217;ll need to update it since the authentication functionality has just been added. You should also check that the .NET 3.5 runtime version of Newtonsoft.Json is added.</em></p>
<h3>Handling the authentication request</h3>
<p>As mentioned above, the Pusher JavaScript library will make a request to <code>/pusher/auth</code> when making the authentication request. Our new <code>PusherController</code> with <code>Auth</code> action does the following:</p>
<ol>
<li>Fetches our Pusher credentials from the Web.config file.</li>
<li>Creates a new <code>PusherProvider</code> using the Pusher credentials</li>
<li>Creates a unique <code>user_id</code> for the presence channel</li>
<li>Creates an authentication string and returns that string as the <code>Content</code> of a <code>ContentResult' with the</code>ContentType<code>set to</code>application/json` in response to the AJAX request.</li>
</ol>
<p>For the moment this code doesn&#8217;t do any user authentication or provide any additional information about the current user.</p>
<pre><code>using System;
using System.Configuration;
using System.Web.Mvc;
using PusherRESTDotNet;
using PusherRESTDotNet.Authentication;

namespace RealTimeWebStore.Controllers
{
    public class PusherController : Controller
    {
        public ActionResult Auth(string channel_name, string socket_id)
        {
            var applicationId = ConfigurationManager.AppSettings["application_id"];
            var applicationKey = ConfigurationManager.AppSettings["application_key"];
            var applicationSecret = ConfigurationManager.AppSettings["application_secret"];

            var channelData = new PresenceChannelData()
            {
                user_id = Guid.NewGuid().ToString()
            };

            var provider = new PusherProvider(applicationId, applicationKey, applicationSecret);
            string authJson = provider.Authenticate(channel_name, socket_id, channelData);

            return new ContentResult { Content = authJson, ContentType = "application/json" };
        }
    }
}
</code></pre>
<p>If we use one of the many web browser development tools available to us to inspect the authentication call within the browser we&#8217;ll see the JSON response coming back.</p>
<p><img alt="Screen+shot+2011-08-04+at+17" src="http://blog.pusher.com/media/2011/08/04/09/07/01/978/Screen+shot+2011-08-04+at+17.06.17.jpg?m=resize&amp;o%5Bgeometry%5D=500x400&amp;s=0d9d3c037a95e8d6" /></p>
<p>You&#8217;ll see the response contains a <code>channel_data</code> property which itself has a <code>user_id</code> with a unique <a  href="http://msdn.microsoft.com/en-us/library/system.guid.aspx"><code>Guid</code></a> value and a <code>user_info</code> property with a <code>null</code> value. Pusher uses this <code>user_id</code> value to uniquely identify the user subscription to the presence channel. So it&#8217;s very important to make sure that each user has a unique ID.</p>
<h3>Adding authentication</h3>
<p>We&#8217;ve mentioned authentication a few times but as yet we haven&#8217;t authenticated the user. If the user has already logged (our app doesn&#8217;t have this functionality, but most do) in we can use the existing <code>User.Identity</code> or else we can just assign a guest identity to the user. Once we have a unique ID for the user we&#8217;ll also add some additional <code>user_info</code> to the <code>channelData</code>. The value of <code>user_info</code> can be anything you like from a simple string to a complex object. This gives you the ability to push as much additional information through Pusher and to the web page as you like. In our case we&#8217;ll just send through a timestamp which identifies how long the user has been on the site.</p>
<pre><code>public ActionResult Auth(string channel_name, string socket_id)
{
    var channelData = new PresenceChannelData();
    if (User.Identity.IsAuthenticated)
    {
        channelData.user_id = User.Identity.Name;
    }
    else
    {
        channelData.user_id = GetUniqueUserId();
    }
    channelData.user_info = GetUserInfo();

    var provider = new PusherProvider(applicationId, applicationKey, applicationSecret);
    string authJson = provider.Authenticate(channel_name, socket_id, channelData);

    return new ContentResult { Content = authJson, ContentType = "application/json" };
}
</code></pre>
<p><em>Note: In our case we don&#8217;t really need to authorise a user but in other situations where the user needs to be logged in we can return a 401  <a  href="http://msdn.microsoft.com/en-us/library/system.web.mvc.httpstatuscoderesult(v=vs.98).aspx?ppud=4"><code>HttpStatusCodeResult</code></a>.</em></p>
<h2>Who&#8217;s Shopping?</h2>
<p>Now that we&#8217;ve got a <code>PusherController</code> that gives Pusher information about the user, we can start showing information about the user on the product page. You can get information about the users subscribed to presence channels by binding to the <a  href="http://pusher.com/docs/client_api_guide/client_presence_events#pusher-subscription-succeeded"><code>pusher:subscription_succeeded</code></a> event on the presence channel object. The callback method for this event receives a <a  href="http://pusher.com/docs/client_api_guide/client_presence_events#members-parameter"><code>members</code></a> parameter which contains all the information about users subscribed to the channel.</p>
<p>First we&#8217;ll create some HTML within our web page where we are going to show &#8220;Who&#8217;s shopping?&#8221;. Then we&#8217;ll add the users to the HTML when pusher notifies us of them.</p>
<p><strong>HTML</strong></p>
<pre><code>&lt;div class="whos-shopping"&gt;
    &lt;h3&gt;Who's shopping?&lt;/h3&gt;
    &lt;ul&gt;&lt;/ul&gt;
&lt;/div&gt;
</code></pre>
<p><strong>JavaScript</strong></p>
<pre><code>var pusher = new Pusher("006c79b1fe1700c6c10d");
var channel = pusher.subscribe("presence-" + productId);
channel.bind("pusher:subscription_succeeded", function(members) {

    members.each(function(member) {
        addMember(member);
    });

});

function addMember(member) {
    var enteredSite = new Date(member.info.timestamp);
    var now = new Date();
    var timeOnSite = (now - enteredSite);
    var li = $("&lt;li data-user-id='" + member.id + "'&gt;" +
                    member.id + " here for " +
                    toReadableTime(timeOnSite) +
               "&lt;/li&gt;");
    $(".whos-shopping ul").append(li);
};
</code></pre>
<p><em>Note: The <code>members</code> object comes with a handy <code>each</code> method to make iterating the members collection really easy.</em></p>
<p>Of course new users can navigate to the page and existing users can leave it so the Pusher JavaScript library also exposes <a  href="http://pusher.com/docs/client_api_guide/client_presence_events#pusher-member-added"><code>pusher:member_added</code></a> and <a  href="http://pusher.com/docs/client_api_guide/client_presence_events#pusher-member-removed"><code>pusher:member_removed</code></a> events on the presence channel object. When these events fire we should add or remove the user as required.</p>
<pre><code>channel.bind("pusher:member_added", function(member) {
    addMember(member);
});
channel.bind("pusher:member_removed", function(member) {
    removeMember(member);
});

function addMember(member) {
    /* as before */
};

function removeMember(member) {
    $(".whos-shopping ul li[data-user-id='" + member.id + "']").remove();
};
</code></pre>
<p>With this in place we now have a fully functioning &#8220;Who&#8217;s shopping?&#8221; widget that shows the current user who else is viewing the same product as they are.</p>
<p><img alt="Screen+shot+2011-08-03+at+21" src="http://blog.pusher.com/media/2011/08/03/13/19/53/544/Screen+shot+2011-08-03+at+21.10.42.jpg?m=resize&amp;o%5Bgeometry%5D=500x400&amp;s=ee8762b09260ca71" /></p>
<p>As mentioned in the opening paragraph, the theory here is that if shoppers can see that others users are viewing the same product it might give them that little push they need to take the plunge and make that purchase &#8220;while stocks last&#8221;.</p>
<p>There are a few refinements and enhancements that could be made to this widget such as filtering out the current user from the &#8220;Who&#8217;s shopping?&#8221; list or possibly showing them which one they are. You could also use the notification system from last time to notify the shopper when another shopper joins or leaves the product page. And, of course, you could add some user chat functionality to get the users discussing the product and really engaging. You could also have a staff member user who could answer any questions that the shoppers may have.</p>
<p>Just as last time all the code from this post is available in the <a  href="https://github.com/leggetter/realtime-webstore">real-time web store github repo</a>. You can also see the <a  href="http://realtimewebstore.apphb.com/">Real-Time Web Store application up and running</a> on <a  href="https://appharbor.com/">AppHarbor</a>. I&#8217;ve tried to link to relevant parts of the <a  href="http://pusher.com/docs">Pusher documentation</a> throughout the post but if there anything that isn&#8217;t clear, if there&#8217;s anything that I&#8217;ve not provided enough detail on and it all just seems too <em>&#8216;magical&#8217;</em>, then please leave a comment or send an email to me (<a  href="mailto:phil@pusher.com?subject=ASP.NET%20real-time%20web%20store">phil@pusher.com</a>).</p>
<p>Here are some links to the key things covered in this post:</p>
<ul>
<li><a  href="http://pusher.com/docs/presence">Presence channels</a></li>
<li><a  href="http://pusher.com/docs/client_api_guide/client_presence_events">Presence channel events</a></li>
<li><a  href="http://pusher.com/docs/authenticating_users">Authenticating Users</a></li>
<li><a  href="http://pusher.com/docs/rest_libraries#cs">Pusher REST .NET Library</a> | <a  href="http://nuget.org/List/Packages/PusherRESTDotNet">NuGet package</a></li>
<li><a  href="https://github.com/leggetter/realtime-webstore">ASP.NET real-time web store in github</a></li>
<li><a  href="http://realtimewebstore.apphb.com/">Real-Time Web Store application up and running</a></li>
<li><a  href="http://www.asp.net/mvc/mvc3">ASP.NET MVC 3</a></li>
</ul>
<h2>Addendum: What about WebForms?</h2>
<p>The post above shows how to user the Pusher REST .NET library within an ASP.NET MVC application but it can just as easily be used within an ASP.NET WebForms app. The way I achieved this was by adding a new Generic HTTP Handler to our web app which will handle the authentication AJAX call.</p>
<p><img alt="Screen+shot+2011-08-02+at+16" src="http://blog.pusher.com/media/2011/08/03/13/22/53/682/Screen+shot+2011-08-02+at+16.07.19.jpg?m=resize&amp;o%5Bgeometry%5D=500x400&amp;s=8b9774ad1cdd29ca" /></p>
<p>In the code below the <code>ProcessRequest</code> method does the following things:</p>
<ol>
<li>Fetches our Pusher credentials from the Web.config file.</li>
<li>Gets the values of the <code>channel_name</code> and <code>socket_id</code> parameters from the <code>context.Request</code></li>
<li>Creates a new <code>PusherProvider</code> using the Pusher credentials</li>
<li>Creates a unique <code>user_id</code> for the presence channel</li>
<li>Creates an authentication string and returns that string as the response body of the AJAX request.</li>
</ol>
<p>For the moment this code doesn&#8217;t do any user authentication or provide any additional information about the current user.</p>
<pre><code>using System.Configuration;
using System.Web;
using PusherRESTDotNet;
using PusherRESTDotNet.Authentication;
using System;

namespace RealTimeWebStore
{
    public class AuthHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            var applicationId = ConfigurationManager.AppSettings["pusher-application-id"];
            var applicationKey = ConfigurationManager.AppSettings["pusher-application-key"];
            var applicationSecret = ConfigurationManager.AppSettings["pusher-application-secret"];

            var socketID = context.Request["socket_id"].ToString();
            var channelName = context.Request["channel_name"].ToString();
            var channelData = new PresenceChannelData()
            {
                user_id = Guid.NewGuid().ToString()
            };

            var provider = new PusherProvider(applicationId, applicationKey, applicationSecret);
            string authJson = provider.Authenticate(channelName, socketId,  channelData);

            context.Response.Write(authJson);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
</code></pre>
<p>Finally we need to configure our handler in the application <code>Web.config</code> file. We want the <code>ProcessRequest</code> method of our handler to be invoked for any call to <code>/pusher/auth</code>. To do this we just add a handler to the <code>httpHandlers</code> element and specify our handler, <code>RealTimeWebStore.AuthHandler</code> as the handler:</p>
<pre><code>&lt;system.web&gt;
  &lt;!-- other config --&gt;
  &lt;httpHandlers&gt;
    &lt;add verb="*"
         path="/pusher/auth/"
         type="RealTimeWebStore.AuthHandler" /&gt;
  &lt;/httpHandlers&gt;
&lt;/system.web&gt;
</code></pre>
<p><script>
var div = $("
<div/>")
.css({
"text-align":"center",
"margin":"auto",
"margin-bottom":"10px"
});
$(".entrybody img")
.css({
"-moz-border-radius": "4px", 
"-webkit-border-radius": "4px", 
"-o-border-radius": "4px", 
"-ms-border-radius": "4px", 
"-khtml-border-radius": "4px", 
"border-radius": "4px", 
"border": "1px solid #DEDEDE", 
"padding": "4px"})
.wrap(div);
</script></p>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2011/07/05/the-easiest-way-to-add-real-time-functionality-to-an-asp-net-e-commerce-application.html' rel='bookmark' title='The easiest way to add real-time functionality to an ASP.NET e-commerce application'>The easiest way to add real-time functionality to an ASP.NET e-commerce application</a></li>
<li><a href='http://www.leggetter.co.uk/2010/12/17/kwwika-powered-real-time-opta-sports-cricket-widget.html' rel='bookmark' title='Kwwika Powered Real-Time Opta Sports Cricket Widget'>Kwwika Powered Real-Time Opta Sports Cricket Widget</a></li>
<li><a href='http://www.leggetter.co.uk/2011/06/28/recent-article-in-net-magazine-websockets-code-a-real-time-survey.html' rel='bookmark' title='Recent article in .net magazine: WebSockets &#8211; Code a real-time survey'>Recent article in .net magazine: WebSockets &#8211; Code a real-time survey</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2011/08/04/adding-a-real-time-whos-shopping-widget-to-an-asp-net-web-app.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Looking for a C# (ASP.NET MVC), jQuery &amp; Real-Time Web Contractor</title>
		<link>http://www.leggetter.co.uk/2011/03/23/looking-for-a-c-javascript-real-time-web-contractor.html</link>
		<comments>http://www.leggetter.co.uk/2011/03/23/looking-for-a-c-javascript-real-time-web-contractor.html#comments</comments>
		<pubDate>Wed, 23 Mar 2011 09:45:04 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Job]]></category>
		<category><![CDATA[Jobs]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[real-time data]]></category>
		<category><![CDATA[real-time web]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://leggetter.posterous.com/looking-for-a-c-javascript-real-time-web-cont</guid>
		<description><![CDATA[        
	I&#039;m very hopeful that I&#039;ll be looking to hire a contractor very soon and I thought I would post this to get a feeling for who is out there and interested. The skills I&#039;m looking for are as follows:EssentialC#Advanced JavaScriptTD...
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2009/01/31/drag-drop-bug-in-jquery-ui-153.html' rel='bookmark' title='Drag Drop bug in JQuery UI 1.5.3'>Drag Drop bug in JQuery UI 1.5.3</a></li>
<li><a href='http://www.leggetter.co.uk/2009/10/29/real-time-rich-internet-applications-rtria.html' rel='bookmark' title='Real-Time Rich Internet Applications (RTRIA)'>Real-Time Rich Internet Applications (RTRIA)</a></li>
<li><a href='http://www.leggetter.co.uk/2011/01/20/the-real-time-web-techmeetup-aberdeen-19012011.html' rel='bookmark' title='The Real-Time Web: TechMeetup Aberdeen &#8211; 19/01/2011'>The Real-Time Web: TechMeetup Aberdeen &#8211; 19/01/2011</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m looking for a contractor for a provisional 3 month contract with the following skills, experience and interests:</p>
<p><strong>Essential</strong></p>
<ul>
<li>C#</li>
<li>jQuery</li>
<li>TDD/BDD</li>
<li>ASP.NET MVC</li>
<li>ADO.NET Entity Framework or other ORM</li>
</ul>
<p><strong>Great to have</strong></p>
<ul>
<li>Passionate about the real-time web and real-time data (essential for the longer term)</li>
<li>Knowledge of building scalable systems on Amazon Infrastructure</li>
<li>Experience of integrating with 3rd party payment systems and building basic ecommerce functionality</li>
<li>Experience of building a SaaS or IaaS offering</li>
<li>Interest/experience in API and Web Service development</li>
<li>Advanced JavaScript</li>
<li>CSS</li>
<li>Excited about HTML5</li>
<li>Part of a tech community</li>
</ul>
<p><strong>Location</strong></p>
<p>The role will be primarily home-based but at times we may need to meet around 2 to 3 times a week at a location that we agree on anywhere between or around Dundee and Edinburgh.</p>
<p>Moving forward I&#8217;m hopeful that this could develop into a fulltime role so it would be ideal if we could get somebody who was interested in this also.</p>
<p>If you are interested please <a  href="mailto:phil@kwwika.com">get in touch</a>&nbsp;with&nbsp;your availability and your rate.</p>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2009/01/31/drag-drop-bug-in-jquery-ui-153.html' rel='bookmark' title='Drag Drop bug in JQuery UI 1.5.3'>Drag Drop bug in JQuery UI 1.5.3</a></li>
<li><a href='http://www.leggetter.co.uk/2009/10/29/real-time-rich-internet-applications-rtria.html' rel='bookmark' title='Real-Time Rich Internet Applications (RTRIA)'>Real-Time Rich Internet Applications (RTRIA)</a></li>
<li><a href='http://www.leggetter.co.uk/2011/01/20/the-real-time-web-techmeetup-aberdeen-19012011.html' rel='bookmark' title='The Real-Time Web: TechMeetup Aberdeen &#8211; 19/01/2011'>The Real-Time Web: TechMeetup Aberdeen &#8211; 19/01/2011</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2011/03/23/looking-for-a-c-javascript-real-time-web-contractor.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Authentication against the Superfeedr HTTP PubSubHubbub API using a .NET HttpWebRequest</title>
		<link>http://www.leggetter.co.uk/2010/07/04/basic-authentication-against-the-superfeedr-http-pubsubhubbub-api-using-a-net-httpwebrequest.html</link>
		<comments>http://www.leggetter.co.uk/2010/07/04/basic-authentication-against-the-superfeedr-http-pubsubhubbub-api-using-a-net-httpwebrequest.html#comments</comments>
		<pubDate>Sun, 04 Jul 2010 09:58:00 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[pubsubhubbub]]></category>
		<category><![CDATA[Superfeedr]]></category>

		<guid isPermaLink="false">http://blog.kwwika.com/basic-authentication-against-the-superfeedr-h</guid>
		<description><![CDATA[        
	It would appear that setting the Credentials property of a HttpWebRequest still leads to authentication failure against the Superfeedr HTTP PubSubHubbub API. This might be because the way the HttpWebRequest works is that it first waits to be...
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2011/01/07/real-time-data-delivery-http-streaming-versus-pubsubhubbub.html' rel='bookmark' title='Real-time Data Delivery: HTTP Streaming Versus PubSubHubbub'>Real-time Data Delivery: HTTP Streaming Versus PubSubHubbub</a></li>
<li><a href='http://www.leggetter.co.uk/2008/10/24/how-to-make-a-cross-domain-web-request-with-silverlight-2.html' rel='bookmark' title='How to make a cross domain web request with SilverLight 2'>How to make a cross domain web request with SilverLight 2</a></li>
<li><a href='http://www.leggetter.co.uk/2009/10/30/using-fiddler-to-trick-silverlight-into-allowing-a-crossdomain-web-request.html' rel='bookmark' title='Using Fiddler to trick Silverlight into allowing a crossdomain Web Request'>Using Fiddler to trick Silverlight into allowing a crossdomain Web Request</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>It would appear that setting the Credentials property of a HttpWebRequest still leads to authentication failure against the <a  href="http://superfeedr.com/documentation#pubsubhubbub">Superfeedr HTTP PubSubHubbub API</a>. This might be because the way the HttpWebRequest works is that it first waits to be challenged for credentials via a 401 (not authorized) and then replies with the authentication (<a  href="http://www.west-wind.com/weblog/posts/243915.aspx">more info include PreAuthenticate here</a>).</p>
<p>So, this doesn&#8217;t work:</p>
<pre class="brush: csharp; title: ; notranslate">
string username = &quot;username&quot;;
string password = &quot;password&quot;;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(&quot;url-here&quot;);
request.Credentials = new NetworkCredential(username, password);
</pre>
<p>To work around this you need to force the authentication to be sent. I found the details of how to do this in a blog post by Ian Dykes here:</p>
<p><a  href="http://devproj20.blogspot.com/2008/02/assigning-basic-authorization-http.html">http://devproj20.blogspot.com/2008/02/assigning-basic-authorization-http.html</a></p>
<p>But for fullness here&#8217;s the code:</p>
<pre class="brush: csharp; title: ; notranslate">
string username = &quot;username&quot;;
string password = &quot;password&quot;;
byte[] authBytes = Encoding.UTF8.GetBytes(username + &quot;:&quot; + password.ToCharArray());
request.Headers[&quot;Authorization&quot;] = &quot;Basic &quot; + Convert.ToBase64String(authBytes);
</pre>
<p><a  href="http://blog.kwwika.com/basic-authentication-against-the-superfeedr-h">Permalink</a> </p>
<p>	| <a  href="http://blog.kwwika.com/basic-authentication-against-the-superfeedr-h#comment">Leave a comment&nbsp;&nbsp;&raquo;</a></p>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2011/01/07/real-time-data-delivery-http-streaming-versus-pubsubhubbub.html' rel='bookmark' title='Real-time Data Delivery: HTTP Streaming Versus PubSubHubbub'>Real-time Data Delivery: HTTP Streaming Versus PubSubHubbub</a></li>
<li><a href='http://www.leggetter.co.uk/2008/10/24/how-to-make-a-cross-domain-web-request-with-silverlight-2.html' rel='bookmark' title='How to make a cross domain web request with SilverLight 2'>How to make a cross domain web request with SilverLight 2</a></li>
<li><a href='http://www.leggetter.co.uk/2009/10/30/using-fiddler-to-trick-silverlight-into-allowing-a-crossdomain-web-request.html' rel='bookmark' title='Using Fiddler to trick Silverlight into allowing a crossdomain Web Request'>Using Fiddler to trick Silverlight into allowing a crossdomain Web Request</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2010/07/04/basic-authentication-against-the-superfeedr-http-pubsubhubbub-api-using-a-net-httpwebrequest.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How I approach problem solving in code?</title>
		<link>http://www.leggetter.co.uk/2009/10/23/how-i-approach-problem-solving-in-code.html</link>
		<comments>http://www.leggetter.co.uk/2009/10/23/how-i-approach-problem-solving-in-code.html#comments</comments>
		<pubDate>Fri, 23 Oct 2009 17:44:57 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[problem solving]]></category>

		<guid isPermaLink="false">http://www.leggetter.co.uk/?p=382</guid>
		<description><![CDATA[<p>Recently I was posed the following question:</p> <p>Write a piece of code that prints all odd integer numbers between 1 and 99</p> <p>This really isn&#8217;t a difficult question but it still requires some thought. When I&#8217;m posed with any question I like to break things down into their constituent parts.</p> <p>Here&#8217;s the process I went [...]
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2008/12/10/problem-solving-lessons-relearnt.html' rel='bookmark' title='Problem solving lessons relearnt'>Problem solving lessons relearnt</a></li>
<li><a href='http://www.leggetter.co.uk/2011/06/02/collecta-gets-dispensed-was-it-solving-a-hard-enough-problem.html' rel='bookmark' title='Collecta Gets Dispensed: Was It Solving a Hard Enough Problem?'>Collecta Gets Dispensed: Was It Solving a Hard Enough Problem?</a></li>
<li><a href='http://www.leggetter.co.uk/2011/06/28/recent-article-in-net-magazine-websockets-code-a-real-time-survey.html' rel='bookmark' title='Recent article in .net magazine: WebSockets &#8211; Code a real-time survey'>Recent article in .net magazine: WebSockets &#8211; Code a real-time survey</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Recently I was posed the following question:</p>
<blockquote><p>Write a piece of code that prints all odd integer numbers between 1 and 99</p></blockquote>
<p>This really isn&#8217;t a difficult question but it still requires some thought. When I&#8217;m posed with any question I like to break things down into their constituent parts.</p>
<p>Here&#8217;s the process I went through:</p>
<p>Okay, so I&#8217;ll define two variables for a start and end value and there&#8217;s going to have to be a loop.</p>
<pre class="brush: csharp; title: ; notranslate">int startValue = 1;
int endValue = 99;
for(int i = startValue;
     i &amp;lt;= endValue;
     i++)
{
   // work out if &quot;i&quot; is an odd number
}</pre>
<p>Now, for the odd number detection. And&#8230; after a few umms and errrs &#8230; I&#8217;m going to have to mod 2 (<code>%2</code>) the current value of <code>i</code> to work out if the value is odd. More &#8230; umms and errs. Okay, I&#8217;ve finally worked out that if something mod 2 is not equal to 0 it&#8217;s clearly an odd number. This took me longer than it should have but never mind. Once I&#8217;ve detected if <code>i</code> is an odd number I&#8217;ll then put the odd number into a list for use later.</p>
<pre class="brush: csharp; title: ; notranslate">
int startValue = 1;
int endValue = 99;
IList&lt;int&gt; oddValues = new List&amp;lt;int&amp;gt;();
for(int i = startValue;
     i &amp;lt;= endValue;
     i++)
{
   if(i%2 != 0)
   {
      oddValues.Add(i);
   }
}
</pre>
<p>Those of you that are good at these little puzzles, or just think this is way too easy, might already be screaming at me about one of the following:</p>
<ul>
<li>Why are you using a <code>IList<int></code>, why don&#8217;t you just print the value?</li>
<li>Odd numbers are always 2 apart so why aren&#8217;t you just increment <code>i</code> by 2 using <code>i+=2</code>?</li>
</ul>
<p><span id="more-382"></span><br />
I admit it,  I missed the second point and that is a bit silly of me. However, what I have starting doing is <a  title="separation of concerns" href="http://en.wikipedia.org/wiki/Separation_of_concerns">separating the concerns</a> of the piece of code. The code does two things; it detects the odd number and it prints the odd numbers. Those are two very distinct things. So, my code now looks like this:</p>
<pre class="brush: csharp; title: ; notranslate">
int startValue = 1;
int endValue = 99;
IList&lt;int&gt; oddNumbers = new List&amp;lt;int&amp;gt;();
for(int i = startValue;
     i &amp;lt;= endValue;
     i++)
{
   if(i%2 != 0)
   {
      oddNumbers.Add(i);
   }
}

string oddNumbersList = string.Join(&quot;,&quot;, oddNumbers.ToArray());
Console.WriteLine(oddNumbersList );
</pre>
<p>I&#8217;m now going to refactor this further so I&#8217;ll put the two different pieces of functionality into different methods. I&#8217;ll rename the <code>i</code>, <code>startValue</code> and <code>endValue</code> variables to be something a bit more useful; say <code>numberToCheck</code>, <code>startNumber</code> and <code>endNumber</code>. I&#8217;ll also create another helper for the odd number checking named <code>IsOddNumber</code>:</p>
<pre class="brush: csharp; title: ; notranslate">
IList&lt;int&gt; GetOddNumbersBetween(int startNumber, int endNumber)
{
   IList oddValues = new List&amp;lt;int&amp;gt;();
   for(int numberToCheck = startNumber;
        numberToCheck &amp;lt;= endNumber;
        numberToCheck++)
   {
      if(IsOddNumber(numberToCheck) == true)
      {
         oddValues.Add(numberToChecki);
      }
   }
   return oddValues;
}

bool IsOddNumber(int number)
{
   return (number % 2 == 1);
}

void PrintOddNumbersBetween(int startNumber, int endNumber)
{
   IList&lt;int&gt; oddNumbers = GetOddNumbersBetween(startNumber, endNumber);
   string oddNumbersList = string.Join(&quot;,&quot;, oddNumbers.ToArray());
   Console.WriteLine(oddNumbersList);
}
</pre>
<p>Let&#8217;s say I then notice the second point you&#8217;ve been screaming at me about (Odd numbers are always 2 apart so why aren&#8217;t you just increment i by 2 using i+=2) that I mentioned above? In practice I should notice this sort of thing either when I give the code a complete review, or one of my peers spots it. When I see this problem I decide to update the <code>for</code> loop, as noted, and I then see that I possibly don&#8217;t need the <code>if(IsOddNumber(i) == true)</code> statement. Although it would pain me to do this, since it&#8217;s a lovely little method, I would need to consider deleting it. But then it strikes me, I&#8217;m no longer just solving the &#8220;odd numbers between 1 and 99 problem&#8221; so I can&#8217;t just assume that the <code>startNumber</code> is going to be an odd number. I need to make sure that it&#8217;s an odd number so I&#8217;ll create another small utility method for that called <code>EnsureOddNumber</code> which will check if the value passed is an odd number, and if not return the next odd number (I&#8217;d like to rethink the name of this method).</p>
<pre class="brush: csharp; title: ; notranslate">
IList&lt;int&gt; GetOddNumbersBetween(int startNumber, int endNumber)
{
   startNumber = EnsureOddNumber(startNumber);

   IList&lt;int&gt; oddValues = new List&amp;lt;int&amp;gt;();
   for(int numberToCheck = startNumber;
        numberToCheck &amp;lt;= endNumber;
        numberToCheck+=2)
   {
      oddValues.Add(numberToCheck);
   }
   return oddValues;
}

int EnsureOddNumber(int number)
{
   if( IsOddNumber(startNumber) == false )
   {
      startNumber++;
   }
   return startNumber;
}

bool IsOddNumber(int number)
{
   return (number % 2 == 1);
}

void PrintOddNumbersBetween(int startNumber, int endNumber)
{
   IList&lt;int&gt; oddNumbers = GetOddNumbersBetween(startNumber, endNumber);
   string oddNumbersList = string.Join(&quot;,&quot;, oddNumbers.ToArray());
   Console.WriteLine(oddNumbersList);
}
</pre>
<p>Now, when I look at this code I get a warm feeling because I feel that it solves the problem, it&#8217;s well engineered, the concerns are separated and the code is completely <a  href="http://en.wikipedia.org/wiki/Self-documenting">self documenting</a>.</p>
<p>There are a few comments that people may have here:</p>
<blockquote><p>The question asked specifically to print odd values between 1 and 99 and you&#8217;ve done more than was required.</p></blockquote>
<p>Although my answer does satisfy the original question have I over engineered things? The question does specifically ask us to print odd values between 1 and 99 so maybe I should have created a function that just satisfied that requirement.</p>
<pre class="brush: csharp; title: ; notranslate">
void PrintOddNumbersBetween1And99()
{
   for(int i = 1;
        i &amp;lt;= 99;
        i+=2)
   {
      Console.WriteLine(i + &quot; &quot;);
   }
}
</pre>
<p>And I&#8217;d have to admit that this very short piece of code exactly answers the question. But I&#8217;d also argue that there is very little chance of this code being reused. Don&#8217;t get me wrong, you definitely shouldn&#8217;t over engineer things but there should be some scope for <a  href="http://en.wikipedia.org/wiki/Code_reuse">code reuse</a>.</p>
<blockquote><p>For such a simple problem you&#8217;ve over engineered this.</p></blockquote>
<p>or</p>
<blockquote><p>There&#8217;s a better solutions that that&#8230; it&#8217;s not efficient</p></blockquote>
<p>Is creating four methods over engieering? Does my code require any comments to provide documentation? There may well be a more performant solution to this, but that&#8217;s not my point. My point is the way of approaching a question: the thought processes involved in understanding the problem and breaking it down to <a  href="http://en.wikipedia.org/wiki/Separation_of_concerns">separate concerns</a>, making it easy to read, <a  href="http://en.wikipedia.org/wiki/Code_reuse">reusable</a> and <a  href="http://en.wikipedia.org/wiki/Self-documenting">self documenting</a>. If the code that worked out the odd numbers is not efficient it could easily be changed in one place without impacting the interface, the other methods within the class, or the overall functionality.</p>
<p>Some people may jump to the simplest solution but I think the way i&#8217;ve described approaching and solving the problem demonstrates good practice. If I&#8217;m completely honest I would normally approach the development of something such as this by writing a test case first since I practice <a  href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a> but that can wait for another blog post.</p>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2008/12/10/problem-solving-lessons-relearnt.html' rel='bookmark' title='Problem solving lessons relearnt'>Problem solving lessons relearnt</a></li>
<li><a href='http://www.leggetter.co.uk/2011/06/02/collecta-gets-dispensed-was-it-solving-a-hard-enough-problem.html' rel='bookmark' title='Collecta Gets Dispensed: Was It Solving a Hard Enough Problem?'>Collecta Gets Dispensed: Was It Solving a Hard Enough Problem?</a></li>
<li><a href='http://www.leggetter.co.uk/2011/06/28/recent-article-in-net-magazine-websockets-code-a-real-time-survey.html' rel='bookmark' title='Recent article in .net magazine: WebSockets &#8211; Code a real-time survey'>Recent article in .net magazine: WebSockets &#8211; Code a real-time survey</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2009/10/23/how-i-approach-problem-solving-in-code.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to make a cross domain web request with SilverLight 2</title>
		<link>http://www.leggetter.co.uk/2008/10/24/how-to-make-a-cross-domain-web-request-with-silverlight-2.html</link>
		<comments>http://www.leggetter.co.uk/2008/10/24/how-to-make-a-cross-domain-web-request-with-silverlight-2.html#comments</comments>
		<pubDate>Fri, 24 Oct 2008 12:16:18 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[thoughts]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[crossdomain]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.leggetter.co.uk/?p=60</guid>
		<description><![CDATA[<p>To make a cross domain web request with SilverLight 2 really isn&#8217;t that tough. I did have some problems with RC0 but I have no idea why. I just tried writing a little app to do this and it worked straight away.<br /> </p> <p>Here&#8217;s the code. It&#8217;s obviously part of a full solution containing [...]
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2009/10/30/using-fiddler-to-trick-silverlight-into-allowing-a-crossdomain-web-request.html' rel='bookmark' title='Using Fiddler to trick Silverlight into allowing a crossdomain Web Request'>Using Fiddler to trick Silverlight into allowing a crossdomain Web Request</a></li>
<li><a href='http://www.leggetter.co.uk/2010/03/19/using-fiddler-to-help-develop-cross-domain-capable-javascript-web-applications.html' rel='bookmark' title='Using Fiddler to help develop cross domain capable JavaScript web applications'>Using Fiddler to help develop cross domain capable JavaScript web applications</a></li>
<li><a href='http://www.leggetter.co.uk/2010/02/05/silverlight-uses-xcp-tmp-files-for-web-requests.html' rel='bookmark' title='Silverlight uses XCP tmp files for Web Requests'>Silverlight uses XCP tmp files for Web Requests</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>To make a cross domain web request with SilverLight 2 really isn&#8217;t that tough. I did have some problems with RC0 but I have no idea why. I just tried writing a little app to do this and it worked straight away.<br />
<span id="more-60"></span></p>
<p>Here&#8217;s the code. It&#8217;s obviously part of a full solution containing a Web Application and a SilverLight Application project. I&#8217;ve also <a  href="http://www.leggetter.co.uk/wp-content/uploads/2008/10/silverlightcrossdomainapplication.zip">uploaded it</a>.</p>
<h2>Useful Information:</h2>
<ul>
<li>You <strong>can not</strong> do a cross domain request over HTTPS.</li>
<li>You <strong>can</strong> do a cross domain request over HTTP.</li>
<li>To be able to make the cross domain request the server that you are making the request to needs to have either (requires clarification) <a  href="http://www.leggetter.co.uk/crossdomain.xml"> crossdomain.xml</a> and/or <a  href="http://www.leggetter.co.uk/clientaccesspolicy.xml">clientaccesspolicy.xml</a> in the root of the webserver.</li>
</ul>
<h2>Resources/links:</h2>
<div>
<ul>
<li><a  href="http://silverlight.net/forums/p/35194/106059.aspx#106059">SilverLight.net forum post on making a WCF cross domain request</a></li>
<li><a  href="http://timheuer.com/blog/archive/2008/04/06/silverlight-cross-domain-policy-file-snippet-intellisense.aspx">Cross domain policy file helpers for Visual Studio</a> &#8211; addes intellisense for the XML files</li>
<li><a  href="http://www.franksworld.com/Utilities/CrossDomainPolicyChecker/Default.aspx">Online cross domain policy file checker</a></li>
<li><a  href="http://www.leggetter.co.uk/wp-content/uploads/2008/10/silverlightcrossdomainapplication.zip">Silverlight cross domain web request example solution</a></li>
<li><a  href="http://www.leggetter.co.uk/crossdomain.xml">Example clientpolicy.xml</a> file<a  href="http://www.leggetter.co.uk/clientaccesspolicy.xml"></a></li>
<li><a href="http://www.leggetter.co.uk/clientaccesspolicy.xml">Example clientaccesspolicy.xml</a> file</li>
</ul>
</div>
<h2>The code:</h2>
<pre class="brush: csharp; title: ; notranslate">
private void RequestButton_Click(object sender, RoutedEventArgs e)
{
    try
    {
        // Create and being making the request/getting the response
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(&quot;http://www.leggetter.co.uk/&quot;));
        request.BeginGetResponse(HandleResponse, request);
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex);
    }
}

private void HandleResponse(IAsyncResult result)
{
    try
    {
        // Finish getting the response and then read the response in chunks
        HttpWebRequest request = (HttpWebRequest)result.AsyncState;
        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);

        StringBuilder readText = new StringBuilder();
        using (Stream responseStream = response.GetResponseStream())
        {
            byte[] buffer = new byte[1024];
            int read = responseStream.Read(buffer, 0, buffer.Length);
            while (read &gt; 0)
            {
                readText.Append(Encoding.UTF8.GetString(buffer, 0, read));
                read = responseStream.Read(buffer, 0, buffer.Length);
            }
        }

        // Display the response text
        Dispatcher.BeginInvoke(delegate()
        {
            ResponseText.Text = readText.ToString();
        });
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex);
    }
}
</pre>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2009/10/30/using-fiddler-to-trick-silverlight-into-allowing-a-crossdomain-web-request.html' rel='bookmark' title='Using Fiddler to trick Silverlight into allowing a crossdomain Web Request'>Using Fiddler to trick Silverlight into allowing a crossdomain Web Request</a></li>
<li><a href='http://www.leggetter.co.uk/2010/03/19/using-fiddler-to-help-develop-cross-domain-capable-javascript-web-applications.html' rel='bookmark' title='Using Fiddler to help develop cross domain capable JavaScript web applications'>Using Fiddler to help develop cross domain capable JavaScript web applications</a></li>
<li><a href='http://www.leggetter.co.uk/2010/02/05/silverlight-uses-xcp-tmp-files-for-web-requests.html' rel='bookmark' title='Silverlight uses XCP tmp files for Web Requests'>Silverlight uses XCP tmp files for Web Requests</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2008/10/24/how-to-make-a-cross-domain-web-request-with-silverlight-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# &#8211; Get Windows Temporary Directory</title>
		<link>http://www.leggetter.co.uk/2007/02/02/get-windows-temporary-directory.html</link>
		<comments>http://www.leggetter.co.uk/2007/02/02/get-windows-temporary-directory.html#comments</comments>
		<pubDate>Fri, 02 Feb 2007 09:25:48 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C# Snippets]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.leggetter.co.uk/2007/02/02/get-windows-temporary-directory.html</guid>
		<description><![CDATA[<p>Once you know it you&#8217;ll probably never forget it&#8230;but wait, this is the second time I&#8217;ve <a href="http://www.google.com/search?q=C%23+get+temp+folder+path" title="Google search for C# get temp folder path">googled</a> for this. I&#8217;d best post how you &#8220;get the Windows temporary directory using C#&#8220;!</p> <p>Related posts: <a href='http://www.leggetter.co.uk/2009/08/28/windows-azure-503-service-unavailable.html' rel='bookmark' title='Windows Azure &#8211; 503 Service Unavailable'>Windows Azure &#8211; 503 Service [...]
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2009/08/28/windows-azure-503-service-unavailable.html' rel='bookmark' title='Windows Azure &#8211; 503 Service Unavailable'>Windows Azure &#8211; 503 Service Unavailable</a></li>
<li><a href='http://www.leggetter.co.uk/2008/05/20/how-to-install-caplin-systems-liberator-free-edition-on-windows.html' rel='bookmark' title='How to install Caplin Systems&#8217; Liberator Free Edition on Windows'>How to install Caplin Systems&#8217; Liberator Free Edition on Windows</a></li>
<li><a href='http://www.leggetter.co.uk/2007/05/22/linkstation-nas-folder-share-with-windows-vista.html' rel='bookmark' title='Linkstation NAS Folder share with Windows Vista'>Linkstation NAS Folder share with Windows Vista</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Once you know it you&#8217;ll probably never forget it&#8230;but wait, this is the second time I&#8217;ve <a  href="http://www.google.com/search?q=C%23+get+temp+folder+path" title="Google search for C# get temp folder path">googled</a> for this. I&#8217;d best post how  you &#8220;<strong>get the Windows temporary directory using C#</strong>&#8220;!</p>
<pre class="brush: csharp; title: ; notranslate">string tempPath =
    System.IO.Path.GetTempPath();</pre>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2009/08/28/windows-azure-503-service-unavailable.html' rel='bookmark' title='Windows Azure &#8211; 503 Service Unavailable'>Windows Azure &#8211; 503 Service Unavailable</a></li>
<li><a href='http://www.leggetter.co.uk/2008/05/20/how-to-install-caplin-systems-liberator-free-edition-on-windows.html' rel='bookmark' title='How to install Caplin Systems&#8217; Liberator Free Edition on Windows'>How to install Caplin Systems&#8217; Liberator Free Edition on Windows</a></li>
<li><a href='http://www.leggetter.co.uk/2007/05/22/linkstation-nas-folder-share-with-windows-vista.html' rel='bookmark' title='Linkstation NAS Folder share with Windows Vista'>Linkstation NAS Folder share with Windows Vista</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2007/02/02/get-windows-temporary-directory.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 19/91 queries in 0.091 seconds using disk: basic

Served from: www.leggetter.co.uk @ 2012-02-04 20:02:32 -->
