<?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; .NET</title>
	<atom:link href="http://www.leggetter.co.uk/tag/net/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>DDD Scotland 2011 &#8211; Maybe .NET developers aren&#8217;t scared of the tech community</title>
		<link>http://www.leggetter.co.uk/2011/05/09/ddd-scotland-2011.html</link>
		<comments>http://www.leggetter.co.uk/2011/05/09/ddd-scotland-2011.html#comments</comments>
		<pubDate>Mon, 09 May 2011 20:42:50 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[DDD Scotland]]></category>
		<category><![CDATA[Developer Developer Developer]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Scotland]]></category>
		<category><![CDATA[SpecFlow]]></category>

		<guid isPermaLink="false">http://www.leggetter.co.uk/?p=14013</guid>
		<description><![CDATA[<p>On Saturday I went to DDD Scotland for the first time and really enjoyed myself. Not only were there some really good talks on a range of subjects but the it was great to meet people I interact with on Twitter and make new connections. I managed my schedule for the day using a <a [...]
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2011/04/28/are-net-developers-scared-of-the-tech-community-and-cutting-edge-technologies.html' rel='bookmark' title='Are .NET developers scared of the tech community and cutting edge technologies?'>Are .NET developers scared of the tech community and cutting edge technologies?</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>
<li><a href='http://www.leggetter.co.uk/2009/06/27/bing-com-round-table.html' rel='bookmark' title='Bing.com round table'>Bing.com round table</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>On Saturday I went to DDD Scotland for the first time and really enjoyed myself. Not only were there some really good talks on a range of subjects but the it was great to meet people I interact with on Twitter and make new connections. I managed my schedule for the day using a <a  href="http://ddd.thededicateddeveloper.com/">mobile app created for DDD Scotland</a> by the recently formed <a  href="http://www.thisislevelup.com/">Level Up</a>.</p>
<div><img class="aligncenter" style="max-width: 800px;" src="http://www.leggetter.co.uk/wp-content/uploads/2011/05/ddd_logo.png" alt="" width="229" height="91" /></div>
<p>The <a  href="http://www.developerdeveloperdeveloper.com/scotland2011/Schedule.aspx">DDD Scotland schedule</a> covered a number of interesting topics and I decided to jump between the tracks to try and get a bit of everything. I started off with <a  href="http://www.developerdeveloperdeveloper.com/scotland2011/ViewSession.aspx?SessionID=662">From .NET to Rail</a>s by <a  href="http://twitter.com/#%21/colin_gemmell">Colin Gemmell</a> which is particularly interesting to me since just the other day I tackled my first Ruby on Rails application and even wrote up a small <a  href="http://leggetter.posterous.com/installing-a-ruby-on-rails-development-enviro">blog post</a> on my findings. Colin&#8217;s enthusiasm is second to none and it was really interesting to hear that he finds himself to be more productive writing rails applications using <a  href="http://www.vim.org/">Vim</a> than he was building ASP.NET websites.</p>
<p>The second session I went to was<a  href="http://www.developerdeveloperdeveloper.com/scotland2011/ViewSession.aspx?SessionID=707"> Building seriously scalable websites with ASP.NET</a> with and without Windows by <a  href="http://twitter.com/#%21/chrishayuk">Chris Hay</a>. My reasoning behind attending this session was two-fold; I&#8217;ve met Chris briefly for a coffee around a month ago so wanted to make sure I caught up with him again and I&#8217;ve also been trying to build an IAAS (Infrastructure as a Service) product using a combination of Microsoft and non-MS components (Kwwika). I think <a  href="http://twitter.com/#%21/leggetter/status/66814414787051520">my tweet about the session</a> pretty much sums things up.</p>
<blockquote><p>.@chrishayuk is nuts, knows his stuff, is a bit disorganised, uses cool tech &amp; I have a lot more knowledge on scaling than I did 1 hour ago.</p></blockquote>
<p>I actually knew that Chris had been still putting the presentation together late in to the night before and was even updating things 10 minutes before the session started so the tweet was a bit &#8220;tongue in cheek&#8221;. The main thing was that in everything that Chris did there was a glimpse of another new exciting technology combined with some proven ones; <a  href="http://nodejs.org/">nodeJS</a>, <a  href="http://monodevelop.com/">MonoDevelop</a>, <a  href="http://redis.io/">redis</a>, <a  href="http://nginx.net/">nginx</a> and <a  href="http://haproxy.1wt.eu/">HAProxy</a> all got a mention along with CDNs, ASP.NET, IIS, Amazon EC2 and much more. He also covered techniques that can be used to speed up servers and page load times. Chris mentioned that he will be writing a book on the subjects he covered &#8211; where&#8217;s the pre-order link? <img src='http://www.leggetter.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I then sat in on two Grok talks. The first was by <a  href="http://twitter.com/#%21/aaronbassett">Aaron Bassett</a> of <a  href="http://www.thisislevelup.com/">Level Up</a> delivering 20 Django hints and tips in just 10 minutes. Wow! The second was a thought-provoking grok by <a  href="http://twitter.com/#%21/roblally">Rob Lally</a> (asked to come up with the talk only a few hours beforehand). Rob showed three ways of social interaction to try and achieve the same goal (I wished I had a video recorder) and then went on to discuss how we need to consider how we interact with others in order to achieve goals &#8211; with an emphasis on ensuring the goal, and the reason behind it, must be understood.</p>
<p>DDD Scotland also introduced an alternative track so I decided to give that a go next. <a  href="http://twitter.com/#%21/markrendle">Mark Rendle</a> gave a talk on <a  href="http://www.developerdeveloperdeveloper.com/scotland2011/ViewSession.aspx?SessionID=656">How to Manage Your Manager</a> (future managers beware <img src='http://www.leggetter.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ). He explained that managers and developers can be two very different animals but for them to get on they each need to understand how the other works and understand the driving factors behind their decisions. He covered things like <a  href="http://en.wikipedia.org/wiki/Job_shadowing">shadowing</a>, how to convince your manager that better hardware and software (e.g. faster computers, a 2nd monitor, productivity tools like <a  href="http://www.jetbrains.com/resharper/">ReSharper</a>) can improve your productivity and benefit them and general communication tips. I wish I&#8217;d known some of those tips about a year ago: for example, ask for a &#8220;respond by&#8221; date when sending an email and set appointments in your managers calendar as they really are calendar driven and without the calendar to prompt them they can easily forget (as I&#8217;ve found).</p>
<p>Then I attended a session on <a  href="http://www.developerdeveloperdeveloper.com/scotland2011/ViewSession.aspx?SessionID=697">SpecFlow &#8211; functional testing made easy</a> by <a  href="http://twitter.com/#!/stack72">Paul Stack</a>. This covered what BDD was and Paul explained why he had moved away from TDD. He then focused on showing how <a  href="http://www.specflow.org/">SpecFlow</a> made BDD, well, easy. Paul also demonstrated how <a  href="http://watin.org/">WatiN</a> can be used to write an acceptance framework for your application driven by specifications written in SpecFlow.</p>
<p>The final session I attended was another alternative track one called Ask the Speakers. This gave me the opportunity to raise my <a  href="http://www.leggetter.co.uk/2011/04/28/are-net-developers-scared-of-the-tech-community-and-cutting-edge-technologies.html">Are .NET developers scared of the tech community and cutting edge technologies?</a> question that I posed and blogged about earlier that week. It really go things going and there were some great points echoing the <a  href="http://www.leggetter.co.uk/2011/04/28/are-net-developers-scared-of-the-tech-community-and-cutting-edge-technologies.html#disqus_thread">comments</a> made in my post.</p>
<p>The day ended with some a whole group of us grabbing some food where I was lucky enough to be surrounded by <a  href="http://twitter.com/#%21/stack72">Paul Stack</a>, <a  href="http://twitter.com/#%21/chriscanal">Chris Canal</a> and <a  href="http://twitter.com/#%21/gep13">Gary Park</a> where we unsurprisingly discussed Continuous Integration, MVC, SOLID, Paul&#8217;s phone being stolen last week, jobs, tech stuff and quite a lot of nonsense. Generally fun chat!</p>
<p>This was a really good community event which leaned heavily towards the Microsoft technology stack. With my recently blog post stirring up so much comment it was great to see an event like this and raises my hopes that .NET developers definitely do have a sense of community and we just need to get together to re-ignite the interest in Scotland. Microsoft also need to get involved and for the moment one big event a year probably isn&#8217;t enough. <a  href="http://scottishdevelopers.com/">Scottish Developers</a> and <a  href="http://www.aberdeendevelopers.co.uk/">Aberdeen developers</a> are definitely doing what they can, and Scottish Developers in particular have now set a high standard with DDD Scotland, but we need to increase the interest in .NET technologies by attending events that aren&#8217;t purely .NET focused and representing the .NET community.</p>
<p><strong>More information</strong><br />
Here&#8217;s the schedule from the day and below that there are links to even more information such as other write-ups, slides and photos from DDD Scotland 2011:</p>
<div><a  href="http://www.developerdeveloperdeveloper.com/scotland2011/Schedule.aspx"><img class="aligncenter" style="max-width: 800px;" src="http://www.leggetter.co.uk/wp-content/uploads/2011/05/ddd_schedule.png" alt="" width="516" height="430" /></a></div>
<ul>
<li><a  href="http://www.flickr.com/photos/craigmurphy/5700045737/in/set-72157626551021127/lightbox/">Craig Murphy&#8217;s pictures of the event</a></li>
<li><a  href="http://paulstack.co.uk/blog/post/DDD-Scotland-2011.aspx">Paul Stack&#8217;s event write-up</a></li>
<li><a  href="http://www.joejag.com/wp/2011/05/ddd-scot-2011-review/">Joe Wright&#8217;s event writeup</a></li>
<li><a  href="http://holytshirt.blogspot.com/2011/05/slides-for-dark-parts-of-mono-from-ddd.html">Dark parts of mono &#8211; slides</a></li>
<li><a  href="http://www.slideshare.net/roundcrisis/cqrs-es-and-friends-7891964">CQRS (Command and Query Responsibility Segregation) and Friends &#8211; slides</a></li>
<li><a  href="http://www.certsandprogs.com/2011/05/resources-from-ddd-scotland-2011.html#axzz1LtDj1Qwg">Defensive Programming 101 &#8211; resources</a></li>
<li><a  href="http://www.slideshare.net/sebrose/unit-testing-tdd-and-the-walking-skeleton">Unit Testing, TDD and the Walking Skeleton &#8211; slides</a></li>
<li><a  href="http://www.flickr.com/photos/henrikniemann/sets/72157626555877493/">Henrik Niemann&#8217;s pics from the event</a> (and a couple of building shots?)</li>
</ul>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2011/04/28/are-net-developers-scared-of-the-tech-community-and-cutting-edge-technologies.html' rel='bookmark' title='Are .NET developers scared of the tech community and cutting edge technologies?'>Are .NET developers scared of the tech community and cutting edge technologies?</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>
<li><a href='http://www.leggetter.co.uk/2009/06/27/bing-com-round-table.html' rel='bookmark' title='Bing.com round table'>Bing.com round table</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2011/05/09/ddd-scotland-2011.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Are .NET developers scared of the tech community and cutting edge technologies?</title>
		<link>http://www.leggetter.co.uk/2011/04/28/are-net-developers-scared-of-the-tech-community-and-cutting-edge-technologies.html</link>
		<comments>http://www.leggetter.co.uk/2011/04/28/are-net-developers-scared-of-the-tech-community-and-cutting-edge-technologies.html#comments</comments>
		<pubDate>Thu, 28 Apr 2011 13:32:09 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Refresh Edinburgh]]></category>
		<category><![CDATA[Scotland]]></category>
		<category><![CDATA[TechMeetup]]></category>

		<guid isPermaLink="false">http://www.leggetter.co.uk/?p=12598</guid>
		<description><![CDATA[<p>I&#8217;m a .NET guy and I&#8217;m excited and interested in cutting edge technologies. I&#8217;ve found the lack of a .NET community (particularly in Scotland) and not seeing enough developers who primarily using Microsoft technologies getting involved with tech communities really frustrating .</p> <p>My feeling is that there aren&#8217;t a lot of regular .NET events or general [...]
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2011/05/09/ddd-scotland-2011.html' rel='bookmark' title='DDD Scotland 2011 &#8211; Maybe .NET developers aren&#8217;t scared of the tech community'>DDD Scotland 2011 &#8211; Maybe .NET developers aren&#8217;t scared of the tech community</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>
<li><a href='http://www.leggetter.co.uk/2010/06/19/want-to-try-out-the-kwwika-api-but-dont-want-to-register.html' rel='bookmark' title='Want to try out the Kwwika API but don&#8217;t want to register?'>Want to try out the Kwwika API but don&#8217;t want to register?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a .NET guy and I&#8217;m excited and interested in cutting edge technologies. I&#8217;ve found the lack of a .NET community (particularly in Scotland) and not seeing enough developers who primarily using Microsoft technologies getting involved with tech communities <em>really</em> frustrating .</p>
<p>My feeling is that there aren&#8217;t a lot of regular .NET events or general tech meetups involving .NET. This is for a number of reasons; bad feeling towards Microsoft, difficult access to Microsoft technologies due to cost and Microsoft&#8217;s undoubted focus on enterprise to name but a few. With the exception of Aberdeen <a  href="http://techmeetup.co.uk/">techmeetup</a> (due to all the Oil companies up there) the majority of developers at techmeetup events don&#8217;t seem to be using Microsoft technologies. That doesn&#8217;t necessarily mean that there aren&#8217;t the developers &#8211; my feeling is that they just don&#8217;t go to those sorts of things. Techmeetup Edinburgh, <a  href="http://refreshedinburgh.org/">Refresh Edinburgh</a> and Techmeetup Glasgow is full of non-MS guys.</p>
<p>The only .NET events and communities, accessible to me, that I know about are:</p>
<ul>
<li><a  href="http://www.aberdeendevelopers.co.uk/">Aberdeen .NET User Group</a>, <a  href="http://scotalt.net/">Scot ALT.NET</a> (seems pretty inactive)</li>
<li><a  href="http://www.developerdeveloperdeveloper.com/scotland2011/">Developer Developer Developer Scotland</a> (held once a year &#8211; I&#8217;m going to it)</li>
<li><a  href="http://scottishdevelopers.com/category/events/book-club-events/">A book club</a> (just heard about this today)</li>
</ul>
<p>Most of this can be found via the <a  href="http://scottishdevelopers.com/">Scottish Developers</a> site. If I&#8217;m honest I&#8217;m not all that bothered that there are .NET focused groups, it&#8217;s more that the .NET devs don&#8217;t seem to get involved in the existing communities.</p>
<p>Are tech communities driven by the startup up scene and this is why we don&#8217;t see developers who use .NET at these events? I bet 95% of all startups do not use Microsoft technologies. Why? <a  href="http://www.moneydashboard.com/">Money Dashboard</a>, an Edinburgh (or close-by), startup built things on the Microsoft technology stack. Are there any others?</p>
<p>Another annoyance I have is that a lot Microsoft devs don&#8217;t seem to want to try out new technologies. Is this because they work at financial services companies who are still using .NET 2.0, have some legacy VBScript systems to maintain and are still targeting IE6? Another way of looking at this is that Ruby, PHP and Python developers are commonly found at tech events, are always trying out new technologies and aren&#8217;t afraid to upgrade to get new features following a new release of something.</p>
<p>Am I wrong?</p>
<p>If I&#8217;m not wrong why is this the case and what are Microsoft doing about it? What are we doing about it?</p>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2011/05/09/ddd-scotland-2011.html' rel='bookmark' title='DDD Scotland 2011 &#8211; Maybe .NET developers aren&#8217;t scared of the tech community'>DDD Scotland 2011 &#8211; Maybe .NET developers aren&#8217;t scared of the tech community</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>
<li><a href='http://www.leggetter.co.uk/2010/06/19/want-to-try-out-the-kwwika-api-but-dont-want-to-register.html' rel='bookmark' title='Want to try out the Kwwika API but don&#8217;t want to register?'>Want to try out the Kwwika API but don&#8217;t want to register?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2011/04/28/are-net-developers-scared-of-the-tech-community-and-cutting-edge-technologies.html/feed</wfw:commentRss>
		<slash:comments>26</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>Windows Azure &#8211; 503 Service Unavailable</title>
		<link>http://www.leggetter.co.uk/2009/08/28/windows-azure-503-service-unavailable.html</link>
		<comments>http://www.leggetter.co.uk/2009/08/28/windows-azure-503-service-unavailable.html#comments</comments>
		<pubDate>Thu, 27 Aug 2009 23:44:57 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Windows Azure]]></category>

		<guid isPermaLink="false">http://www.leggetter.co.uk/?p=271</guid>
		<description><![CDATA[<p>I finally got around to trying out ASP.NET MVC and while I was at it I thought I&#8217;d also give Windows Azure a whirl. Windows Azure doesn&#8217;t support ASP.NET MVC out of the box but Jim over on MSDN Blogs has written up the details of how to get <a href="http://blogs.msdn.com/jnak/archive/2008/10/28/asp-net-mvc-projects-running-on-windows-azure.aspx">ASP.Net MVC Projects running on Windows [...]
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2009/10/06/response-redirect-in-windows-azure.html' rel='bookmark' title='Response.Redirect in Windows Azure'>Response.Redirect in Windows Azure</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/02/02/get-windows-temporary-directory.html' rel='bookmark' title='C# &#8211; Get Windows Temporary Directory'>C# &#8211; Get Windows Temporary Directory</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I finally got around to trying out ASP.NET MVC and while I was at it I thought I&#8217;d also give Windows Azure a whirl. Windows Azure doesn&#8217;t support ASP.NET MVC out of the box but Jim over on MSDN Blogs has written up the details of how to get <a  href="http://blogs.msdn.com/jnak/archive/2008/10/28/asp-net-mvc-projects-running-on-windows-azure.aspx">ASP.Net MVC Projects running on Windows Azure</a>.</p>
<h3>Problem</h3>
<p>So, I followed the instruction from the blog and uploaded the package and configuration file, waited for the staging application to get into a runnable state, and clicked on the staging link&#8230;</p>
<blockquote><p>Windows Azure &#8211; 503 Service Unavailable</p></blockquote>
<p>Clearly not a good thing! In addition to this error I occasionally got a random network error or a full-on connection error reported by the browser.</p>
<p>I tried googling for this error but there was nothing about this problem after deploying to the real Windows Azure hosting (the cloud). As far as I can tell there&#8217;s no way of getting any debug information or logs to work out what&#8217;s going wrong. Maybe this is something that Microsoft will add later on?</p>
<h3>Solution</h3>
<p>Then it struck me that I hadn&#8217;t actually set up any kind of TableStorage on my Windows Azure hosting so I removed all mentions of storage and database connections from the MVC application. This included editing Web.config and removing the following.</p>
<ul>
<li>The &lt;section name=&#8221;authenticationService&#8221; type=&#8221;System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&#8243; requirePermission=&#8221;false&#8221; allowDefinition=&#8221;MachineToApplication&#8221; /&gt; section element.</li>
<li>The &lt;connectionStrings&gt; element</li>
<li>The &lt;membership&gt;element</li>
<li>The &lt;authentication mode=&#8221;Forms&#8221;&gt; element</li>
<li>The &lt;profile&gt; element</li>
<li>The &lt;roleManager&gt;element</li>
</ul>
<p><strong><em>Update: I&#8217;ve found that without the &lt;authentication&gt;element I started getting the error below so you may want to instead replace it with :</em></strong></p>
<blockquote><p>CCT: Role instances did not start within the time allowed.  Please try again.  If you continue to encounter this behavior please try shutting down the Development Fabric.</p></blockquote>
<p>I&#8217;m guessing that not all of these elements actually need to be removed but doing so resulted in the MVC ASP.NET application working in Windows Azure.</p>
<p><strong><em>Update 2: ServiceDefinition.csdef</em></strong></p>
<p>If you happen to get network timeouts or 404 network connection issues it&#8217;s worth checking your ServiceDefinition.csdef to make sure that you&#8217;ve got port 80 configured. I noticed that mine had updated to port 8080 so obviously I couldn&#8217;t access the staging site on port 80 like I was trying. If you do have the port set to something else other than port 80 you can use that port to access your application but the ServiceDefinition.csdef does have a comment in there telling you your application should be on port 80 so you are probably best to stick with that.</p>
<blockquote><p>&lt;!&#8211; Must use port 80 for http and port 443 for https when running in the cloud &#8211;&gt;<br />
&lt;InputEndpoint name=&#8221;HttpIn&#8221; protocol=&#8221;http&#8221; port=&#8221;80&#8243; /&gt;</p></blockquote>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2009/10/06/response-redirect-in-windows-azure.html' rel='bookmark' title='Response.Redirect in Windows Azure'>Response.Redirect in Windows Azure</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/02/02/get-windows-temporary-directory.html' rel='bookmark' title='C# &#8211; Get Windows Temporary Directory'>C# &#8211; Get Windows Temporary Directory</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2009/08/28/windows-azure-503-service-unavailable.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>System.Security.SecurityException: That assembly does not allow partially trusted callers</title>
		<link>http://www.leggetter.co.uk/2009/08/26/system-security-securityexception-that-assembly-does-not-allow-partially-trusted-callers.html</link>
		<comments>http://www.leggetter.co.uk/2009/08/26/system-security-securityexception-that-assembly-does-not-allow-partially-trusted-callers.html#comments</comments>
		<pubDate>Tue, 25 Aug 2009 23:51:12 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C# Snippets]]></category>
		<category><![CDATA[Windows Azure]]></category>

		<guid isPermaLink="false">http://www.leggetter.co.uk/?p=268</guid>
		<description><![CDATA[<p>I was writing a Windows Azure ASP.NET MVC application and when making a call to a page I received the following exception:</p> <p>System.Security.SecurityException: That assembly does not allow partially trusted callers</p> <p>In my application I&#8217;m using <a href="http://www.castleproject.org/container/index.html">Castle Windsor</a> for dependency injection and when trying to resolve a service using:</p> } <p>IGravatar gravatar = MvcApplication.Container.Resolve&#60;IGravatar&#62;();</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>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I was writing a Windows Azure ASP.NET MVC application and when making a call to a page I received the following exception:</p>
<blockquote><p>System.Security.SecurityException: That assembly does not allow partially trusted callers</p></blockquote>
<p>In my application I&#8217;m using <a  href="http://www.castleproject.org/container/index.html">Castle Windsor</a> for dependency injection and when trying to resolve a service using:</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<blockquote><p>IGravatar gravatar = MvcApplication.Container.Resolve&lt;IGravatar&gt;();</p></blockquote>
<p>I received this message. To solve things I needed to update the WebRole element in the ServiceDefinitions.csdef file so that enableNativeCodeExecution is enabled.</p>
<blockquote><p>&lt;WebRole name=&#8221;TwitterGravatarMVC&#8221; enableNativeCodeExecution=&#8221;true&#8221;&gt;</p></blockquote>
<p>I found <a  href="http://social.msdn.microsoft.com/Forums/en-US/netservices/thread/c2e49731-9e72-49b6-9fb3-1243c85b265d">the solution</a>, detailed above, on the<a  href="http://social.msdn.microsoft.com/Forums/en-US/netservices/thread/c2e49731-9e72-49b6-9fb3-1243c85b265d"> Azure Services Platform Developer Centre forum</a>.</p>
<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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2009/08/26/system-security-securityexception-that-assembly-does-not-allow-partially-trusted-callers.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Live Mesh &#8211; my experience</title>
		<link>http://www.leggetter.co.uk/2008/11/30/live-mesh-my-experience.html</link>
		<comments>http://www.leggetter.co.uk/2008/11/30/live-mesh-my-experience.html#comments</comments>
		<pubDate>Sun, 30 Nov 2008 22:52:22 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Live Mesh]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Synchronisation]]></category>

		<guid isPermaLink="false">http://www.leggetter.co.uk/?p=63</guid>
		<description><![CDATA[<p>I think that <a title="Live Mesh" href="http://www.mesh.com">Live Mesh</a> will be really useful. I think it provides great benefit to individual users, such as myself, and has great potential to be used by <a title="Independent Software Solutions" href="http://independentsoftwaresolutions.com">software solution developers</a>. I&#8217;m presently using it to synchronise some files that I want to backup and be available [...]
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2010/10/08/were-starting-to-live-in-a-thank-you-economy-but-you-still-expect-something-for-that-thanks.html' rel='bookmark' title='We&#8217;re starting to live in a Thank You Economy but you still expect something for that thanks'>We&#8217;re starting to live in a Thank You Economy but you still expect something for that thanks</a></li>
<li><a href='http://www.leggetter.co.uk/2007/01/29/elephantcouk-bad-experience.html' rel='bookmark' title='Whinge of the Week: Elephant.co.uk &#8211; bad experience'>Whinge of the Week: Elephant.co.uk &#8211; bad experience</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I think that <a  title="Live Mesh" href="http://www.mesh.com">Live Mesh</a> will be really useful. I think it provides great benefit to individual users, such as myself, and has great potential to be used by <a  title="Independent Software Solutions" href="http://independentsoftwaresolutions.com">software solution developers</a>. I&#8217;m presently using it to synchronise some files that I want to backup and be available wherever I am.</p>
<p><a  href="http://www.leggetter.co.uk/wp-content/uploads/2008/11/livemesh.png" class="thickbox no_icon" rel="gallery-63" title="Live Mesh"><img class="alignnone size-medium wp-image-64" title="Live Mesh" src="http://www.leggetter.co.uk/wp-content/uploads/2008/11/livemesh-300x214.png" alt="" width="300" height="214" /></a></p>
<p>I originally had a lot of web files being synchronised, around 700MB, but the synchronisation was taking ages and killing my CPU. CPU was sitting at 100% and there was no sign of things completing. I think it was having a problem with the volume of small files.</p>
<p>To summarise: it&#8217;s a great product with bags of potential but something needs to be done to reduce the CPU usage when dealing with the synchronisation of a large volume of small files.</p>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2010/10/08/were-starting-to-live-in-a-thank-you-economy-but-you-still-expect-something-for-that-thanks.html' rel='bookmark' title='We&#8217;re starting to live in a Thank You Economy but you still expect something for that thanks'>We&#8217;re starting to live in a Thank You Economy but you still expect something for that thanks</a></li>
<li><a href='http://www.leggetter.co.uk/2007/01/29/elephantcouk-bad-experience.html' rel='bookmark' title='Whinge of the Week: Elephant.co.uk &#8211; bad experience'>Whinge of the Week: Elephant.co.uk &#8211; bad experience</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2008/11/30/live-mesh-my-experience.html/feed</wfw:commentRss>
		<slash:comments>0</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>.NET Obfuscators</title>
		<link>http://www.leggetter.co.uk/2008/06/26/net-obfuscators.html</link>
		<comments>http://www.leggetter.co.uk/2008/06/26/net-obfuscators.html#comments</comments>
		<pubDate>Thu, 26 Jun 2008 21:45:32 +0000</pubDate>
		<dc:creator>Phil Leggetter</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Obfusators]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.leggetter.co.uk/?p=53</guid>
		<description><![CDATA[<p>As I was cleaning up the contents of my desktop I came across a text file containing a list of links to .NET obfuscator offerings. I created this list when researching options about six months ago. The main criteria was that the obfuscator could be executed as part of an automated build process.</p> <p>Here&#8217;s the [...]
Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2011/03/31/who-curates-the-real-time-web.html' rel='bookmark' title='Who Curates the Real-Time Web?'>Who Curates the Real-Time Web?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>As I was cleaning up the contents of my desktop I came across a text file containing a list of links to .NET obfuscator offerings. I created this list when researching options about six months ago. The main criteria was that the obfuscator could be executed as part of an automated build process.</p>
<p>Here&#8217;s the contents of the list:</p>
<ul>
<li><a  href="http://www.secureteam.net">http://www.secureteam.net</a></li>
<li><a  href="http://www.remotesoft.com/salamander/obfuscator.html">http://www.remotesoft.com/salamander/obfuscator.html</a></li>
<li><a  href="http://www.smartassembly.com/">http://www.smartassembly.com/</a></li>
<li><a  href="http://www.preemptive.com/products/dotfuscator/index.html">http://www.preemptive.com/products/dotfuscator/index.html</a></li>
<li><a  href="http://www.9rays.net/products/Spices.Obfuscator/">http://www.9rays.net/products/Spices.Obfuscator/</a></li>
<li><a  href="http://www.wiseowl.com/products/products.aspx">http://www.wiseowl.com/products/products.aspx</a></li>
<li><a  href="http://www.eziriz.com/comparison.htm">http://www.eziriz.com/comparison.htm</a></li>
</ul>
<p>Related posts:<ol>
<li><a href='http://www.leggetter.co.uk/2011/03/31/who-curates-the-real-time-web.html' rel='bookmark' title='Who Curates the Real-Time Web?'>Who Curates the Real-Time Web?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leggetter.co.uk/2008/06/26/net-obfuscators.html/feed</wfw:commentRss>
		<slash:comments>0</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 21/127 queries in 0.329 seconds using disk: basic

Served from: www.leggetter.co.uk @ 2012-02-04 21:16:40 -->
