<?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>Will's Blog &#187; Coding</title>
	<atom:link href="http://will.hughesfamily.net.au/category/it/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://will.hughesfamily.net.au</link>
	<description>Travel, Photography, Geek Stuff</description>
	<lastBuildDate>Mon, 11 Jan 2010 21:42:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>C# / Visual Studio : Debug &amp; Console Output not showing</title>
		<link>http://will.hughesfamily.net.au/20090910/c-visual-studio-debug-console-output-not-showing/</link>
		<comments>http://will.hughesfamily.net.au/20090910/c-visual-studio-debug-console-output-not-showing/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 01:56:59 +0000</pubDate>
		<dc:creator>Will</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Randomness]]></category>

		<guid isPermaLink="false">http://will.hughesfamily.net.au/?p=998</guid>
		<description><![CDATA[A few months ago for some unknown reason the Output pane in Visual Studio stopped displaying output from my application. I&#8217;d get the build notices, exceptions, and thread/process exit information but any calls to Debug or Console to output information wouldn&#8217;t display. It turns out that you can de-select &#8220;Program Output&#8221; &#8211; and somehow it&#8217;d [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago for some unknown reason the Output pane in Visual Studio stopped displaying output from my application. </p>
<p>I&#8217;d get the build notices, exceptions, and thread/process exit information but any calls to Debug or Console to output information wouldn&#8217;t display. </p>
<p><img src="http://will.hughesfamily.net.au/wp-content/uploads/2009/09/tickprogramoutput.jpg" alt="tickprogramoutput" title="tickprogramoutput" width="370" height="367" style="padding-left: 10px;" class="alignright size-full wp-image-1000" />It turns out that you can de-select &#8220;Program Output&#8221; &#8211; and somehow it&#8217;d become deselected. Even now it still turns itself off, apparently by random. </p>
<p>Right clicking in the Output pane should let you re-select that value. </p>
]]></content:encoded>
			<wfw:commentRss>http://will.hughesfamily.net.au/20090910/c-visual-studio-debug-console-output-not-showing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making WCF and ELMAH play nice together.</title>
		<link>http://will.hughesfamily.net.au/20090505/making-wcf-and-elmah-play-nice-together/</link>
		<comments>http://will.hughesfamily.net.au/20090505/making-wcf-and-elmah-play-nice-together/#comments</comments>
		<pubDate>Tue, 05 May 2009 11:42:44 +0000</pubDate>
		<dc:creator>Will</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://will.hughesfamily.net.au/?p=972</guid>
		<description><![CDATA[Edit: This post was linked from Stack Overflow &#8211; you might want to check back there for more/better discussion about the topic. Recently Jeff Attwood wrote about how they are using ELMAH to get more information about the types of errors occurring in Stack Overflow. Effectively ELMAH is designed as a &#8216;drop in&#8217; fault capturing [...]]]></description>
			<content:encoded><![CDATA[<p>Edit: This post was linked from Stack Overflow &#8211; you might want <a href="http://stackoverflow.com/questions/895901/exception-logging-for-wcf-services-using-elmah">to check back there for more/better discussion about </a>the topic.</p>
<p>Recently Jeff Attwood wrote about how they are using ELMAH to get more information about the types of errors occurring in Stack Overflow.</p>
<p>Effectively ELMAH is designed as a &#8216;drop in&#8217; fault capturing system for ASP.NET. It works really well there, and for many situations you can get along just fine without even needing to recompile your application (it does need some editing of the web.config though).</p>
<p>I wanted a way to capture more detail about the faults occurring in our dev and production environments, especially when working with WCF &#8211; since a lot of error detail tends to be hidden, or is difficult to reproduce.</p>
<p>Dropping in ELMAH into a WCF application will by default mean you miss the vast majority of errors &#8211; WCF swallows the error, and doesn&#8217;t let it get back up to ASP.NET.</p>
<p>There&#8217;s two ways you can go about fixing this:<br />
<em>Side Note: If you&#8217;re not hosting WCF in ASP.NET, then Option 2 may not be directly possible for you without some modification. </em></p>
<p><strong>#1 &#8211; Wrap everything in try/catch blocks (if you didn&#8217;t already) and sprinkle this line around everywhere: </strong></p>
<pre>Elmah.ErrorSignal.FromCurrentContext().Raise(YourExceptionHere);</pre>
<p><strong>#2 Add a HttpHandler, and Decorate your Service(s) with an Error Handling attribute. </strong></p>
<p>I borrowed the ServiceErrorBehaviourAttribute code from somewhere else, and I can&#8217;t find the source of it at the moment. Effectively this was so I could manipulate the HTTP Status Codes going back to the client when there was an error.  It just so happens that this is a great way of capturing Exceptions and sending them to ELMAH at the same time.</p>
<pre style="overflow: scroll; width: 400px; height: 300px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Collections.ObjectModel;
using System.Net;
using System.Web;
using System.IO;
using Elmah;
namespace YourApplication
{
	/// &lt;summary&gt;
	/// Your handler to actually tell ELMAH about the problem.
	/// &lt;/summary&gt;
    public class HttpErrorHandler : IErrorHandler
    {
        public bool HandleError(Exception error)
        {
            return false;
        }

        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            if (error != null ) // Notify ELMAH of the exception.
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(error);
            }
        }
    }
	/// &lt;summary&gt;
	/// So we can decorate Services with the [ServiceErrorBehaviour(typeof(HttpErrorHandler))]
	/// ...and errors reported to ELMAH
	/// &lt;/summary&gt;
	public class ServiceErrorBehaviourAttribute : Attribute, IServiceBehavior
    {
        Type errorHandlerType;

        public ServiceErrorBehaviourAttribute(Type errorHandlerType)
        {
            this.errorHandlerType = errorHandlerType;
        }

        public void Validate(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
        }

        public void AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Collection endpoints, BindingParameterCollection parameters)
        {
        }

        public void ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            IErrorHandler errorHandler;
            errorHandler = (IErrorHandler)Activator.CreateInstance(errorHandlerType);
            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
                channelDispatcher.ErrorHandlers.Add(errorHandler);
            }
        }
    }
}</pre>
<p>Once you&#8217;ve added that, then it&#8217;s just a matter of decorating your Service like so:</p>
<pre>    [ServiceContract(Namespace = "http://example.com/api/v1.0/")]
    [ServiceErrorBehaviour(typeof(HttpErrorHandler))]
    public class MyServiceService
    {
      // ...
    }</pre>
<p>&#8230;and then making sure ELMAH is added as a reference, and adding it&#8217;s entries to your web.config.</p>
<p>Then you&#8217;ll be getting a whole stack of errors you otherwise may not have seen.</p>
<p>It&#8217;s also possible to log exceptions from higher up the chain (eg Databases, Files, etc) by using the line of code from Option 1.</p>
<p><strong>Issues</strong></p>
<p>Whilst ELMAH is great for capturing information about the request, I havn&#8217;t yet found any way to capture the original HTTP Request &#8211; this would be the ultimate goal for me.</p>
<p>It&#8217;s also not particularly easy to capture additional information (such as database records, or objects in cache, etc)  without rolling your own copy of ELMAH.</p>
<p>All in all though &#8211; for a few minutes work, it&#8217;s one additional way to capture errors that your existing code may not be able to.</p>
<p>Yes, ELMAH even captures errors (in most situations) when your WCF services can&#8217;t start up (eg your fubar&#8217;ed some attributes).</p>
<p>Hope that helps.</p>
<p>NB: Use this code at your own risk, don&#8217;t blame me if it brings down your multi-million-dollar-per-hour application and causes you to go bankrupt.</p>
]]></content:encoded>
			<wfw:commentRss>http://will.hughesfamily.net.au/20090505/making-wcf-and-elmah-play-nice-together/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>.NET 3.5 Helper Methods &#8211; Serialize Objects to XML</title>
		<link>http://will.hughesfamily.net.au/20090309/net-35-helper-methods-serialize-objects-to-xml/</link>
		<comments>http://will.hughesfamily.net.au/20090309/net-35-helper-methods-serialize-objects-to-xml/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 11:55:12 +0000</pubDate>
		<dc:creator>Will</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://will.hughesfamily.net.au/20090309/net-35-helper-methods-serialize-objects-to-xml/</guid>
		<description><![CDATA[Two methods that I keep finding myself needing are a way to Serialize and Deserialize objects in .NET 3.5. Either for Unit Testing against a WebService of some kind, or for storing objects in memory to disk in XML for human-readable niceties. Don&#8217;t forget to add in appropriate error handling code as needed. With .NET [...]]]></description>
			<content:encoded><![CDATA[<p>Two methods that I keep finding myself needing are a way to Serialize and Deserialize objects in .NET 3.5. </p>
<p>Either for Unit Testing against a WebService of some kind, or for storing objects in memory to disk in XML for human-readable niceties. </p>
<p>Don&#8217;t forget to add in appropriate error handling code as needed.</p>
<p>With .NET 3.5 SP1, these methods will serialize (almost) any object to either XML or JSON, it was based in part off an example given in a long since forgotten forum post. </p>
<p>&nbsp;</p>
<pre>using System.IO;
using System.Runtime.Serialization; // System.Runtime.Serialization.dll (.NET 3.0)
using System.Runtime.Serialization.Json; // System.ServiceModel.Web.dll (.NET 3.5)
using System.Text;
namespace Serialization
{
    public static class Helpers
    {
        /// &lt;summary&gt;
        /// Declare the Serializer Type you want to use.
        /// &lt;/summary&gt;
        public enum SerializerType
        {
            Xml, // Use DataContractSerializer
            Json // Use DataContractJsonSerializer
        }

        public static T Deserialize&lt;T&gt;(string SerializedString, SerializerType UseSerializer)
        {
            // Get a Stream representation of the string.
            using (Stream s = new MemoryStream(UTF8Encoding.UTF8.GetBytes(SerializedString)))
            {
                T item;
                switch (UseSerializer)
                {
                    case SerializerType.Json:
                        // Declare Serializer with the Type we're dealing with.
                        var serJson = new DataContractJsonSerializer(typeof(T));
                        // Read(Deserialize) with Serializer and cast
                        item = (T)serJson.ReadObject(s);
                        break;
                    case SerializerType.Xml:
                    default:
                        var serXml = new DataContractSerializer(typeof(T));
                        item = (T)serXml.ReadObject(s);
                        break;
                }
                return item;
            }
        }

        public static string Serialize&lt;T&gt;(T ObjectToSerialize, SerializerType UseSerializer)
        {
            using (MemoryStream serialiserStream = new MemoryStream())
            {
                string serialisedString = null;
                switch (UseSerializer)
                {
                    case SerializerType.Json:
                        // init the Serializer with the Type to Serialize
                        DataContractJsonSerializer serJson = new DataContractJsonSerializer(typeof(T));
                        // The serializer fills the Stream with the Object's Serialized Representation.
                        serJson.WriteObject(serialiserStream, ObjectToSerialize);
                        break;
                    case SerializerType.Xml:
                    default:
                        DataContractSerializer serXml = new DataContractSerializer(typeof(T));
                        serXml.WriteObject(serialiserStream, ObjectToSerialize);
                        break;
                }
                // Rewind the stream to the start so we can now read it.
                serialiserStream.Position = 0;
                using (StreamReader sr = new StreamReader(serialiserStream))
                {
                    // Use the StreamReader to get the serialized text out
                    serialisedString = sr.ReadToEnd();
                    sr.Close();
                }
                return serialisedString;
            }
        }
    }
}
</pre>
<p>Hopefully others will find this useful.</p>
<p>&nbsp;</p>
<p><strong>Updated -</strong> A little more generic now &#8211; can serialize to either Json or Xml as needed by altering the type param.</p>
]]></content:encoded>
			<wfw:commentRss>http://will.hughesfamily.net.au/20090309/net-35-helper-methods-serialize-objects-to-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pains of Moving from VB.NET to C# &#8211; Optional Method Parameters</title>
		<link>http://will.hughesfamily.net.au/20080819/pains-of-moving-from-vbnet-to-c-optional-method-parameters/</link>
		<comments>http://will.hughesfamily.net.au/20080819/pains-of-moving-from-vbnet-to-c-optional-method-parameters/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 02:25:58 +0000</pubDate>
		<dc:creator>Will</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://will.hughesfamily.net.au/20080819/pains-of-moving-from-vbnet-to-c-optional-method-parameters/</guid>
		<description><![CDATA[So one of the things you find in C# when you move from VB.NET is that you can&#8217;t do Optional parameters on methods. Actually, you can &#8211; it&#8217;s just that the compiler in VB.NET is giving you a free ride by generating overloaded values for you automatically. Correction, Looks like C# is being difficult, see [...]]]></description>
			<content:encoded><![CDATA[<p>So one of the things you find in C# when you move from VB.NET is that you can&#8217;t do Optional parameters on methods. </p>
<p>Actually, you can &#8211; <strike>it&#8217;s just that the compiler in VB.NET is giving you a free ride by generating overloaded values for you automatically</strike>. Correction, Looks like C# is being difficult, see <a href="http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85556.aspx">this FAQ</a>.&nbsp; </p>
<p>Anyway, say you have a VB.NET function like so: </p>
<blockquote><p>Public Sub TestFunction(Param1 as String, Optional Param2 as String = &#8220;Default Value&#8221;)<br />&nbsp;&nbsp;&nbsp; // Do Stuff <br />End Sub </p>
</blockquote>
<p>In C# you can achieve the same thing by writing a stub like so:<br />
<blockquote>
<p>public void TestFunction(string Param1) <br />{<br /> TestFunction(Param1, &#8220;Default Value&#8221;); <br />}
<p>public void TestFunction(string Param1, string Param2) <br />{<br /> // Do Stuff<br />}</p>
</blockquote>
<p>Yeah, it&#8217;s a little more code to write &#8211; but it&#8217;s really not that difficult to manage unless you have truely obscene numbers of optional parameters.
<p><a href="http://articles.techrepublic.com.com/5100-10878_11-1050652.html">TechRepublic has a look</a> at the same issue too, and gives Parameter arrays as an alternative. Under .NET 3.0+ with Anonymous types you can use some reflection niceties to do some other, similar things too.
<p>On a different note, reading VB code after nearly a year straight of C# development feels a little strange. </p>
]]></content:encoded>
			<wfw:commentRss>http://will.hughesfamily.net.au/20080819/pains-of-moving-from-vbnet-to-c-optional-method-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Kerberos / SSO to Work in Flex</title>
		<link>http://will.hughesfamily.net.au/20080724/getting-kerberos-sso-to-work-in-flex/</link>
		<comments>http://will.hughesfamily.net.au/20080724/getting-kerberos-sso-to-work-in-flex/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 17:25:19 +0000</pubDate>
		<dc:creator>Will</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://will.hughesfamily.net.au/20080724/getting-kerberos-sso-to-work-in-flex/</guid>
		<description><![CDATA[Because Adobe currently don&#8217;t support Kerberos in Flex, that limits the ability to do cool Single Sign On stuff through Air and on various sites. So, how to solve this?&#160; Well, this is just a theory, but it seems to work ok on paper. The basic idea is that you have something else do the [...]]]></description>
			<content:encoded><![CDATA[<p>Because Adobe currently <a href="http://bugs.adobe.com/jira/browse/SDK-14554?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel">don&#8217;t support Kerberos in Flex</a>, that limits the ability to do cool Single Sign On stuff through Air and on various sites. </p>
<p>So, how to solve this?&nbsp; Well, this is just a theory, but it seems to work ok on paper. </p>
<p>The basic idea is that you have something <em>else</em> do the authentication, and generate a One Time Key. That Key is then passed to your Flex app (eg via the Command Line for Air, or a Flashvar in the browser), which then uses this OTK to authenticate and grab a Session key like you normally would. </p>
<p>The point of using a One Time Key which is then discarded after use,&nbsp; is so that someone malicious can&#8217;t grab (say) your process list and reuse that authentication token. </p>
<p>So, for Windows Air clients &#8211; you could build a quick-and-dirty preloader (.NET makes this really easy) which does your Kerberos authentication using (say) your Windows Identity against Active Directory. </p>
<p>For Mac Air clients &#8211; You&#8217;d also need to build a preloader (Mono? <img src='http://will.hughesfamily.net.au/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ). Whether you can achieve SSO this way would depend on how the OSX Identity stuff works under a domain (or the equivilent analog in OSX world) model, but at the very least you could do your Kerberos authentication here.</p>
<p>And for Server-side components, well, that&#8217;s pretty damn obvious &#8211; you generate the OTK on the server and deliver it down (over SSL!) as part of the page. </p>
<p>Anyway, hope this helps someone who&#8217;s pondering the way to solve this. </p>
]]></content:encoded>
			<wfw:commentRss>http://will.hughesfamily.net.au/20080724/getting-kerberos-sso-to-work-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Distributed Object Caching: Memcached &amp; Velocity</title>
		<link>http://will.hughesfamily.net.au/20080627/distributed-object-caching-memcached-velocity/</link>
		<comments>http://will.hughesfamily.net.au/20080627/distributed-object-caching-memcached-velocity/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 14:35:49 +0000</pubDate>
		<dc:creator>Will</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Velocity]]></category>

		<guid isPermaLink="false">http://will.hughesfamily.net.au/20080627/distributed-object-caching-memcached-velocity/</guid>
		<description><![CDATA[I&#8217;m working on a new project at work where we&#8217;re dealing with data that updates frequently, at unpredictable times, used in across several different front-end services, and needs to scale to pretty decent traffic levels without going nuts on buying more hardware. So, given all that, one of the things we&#8217;re looking at is using [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a new project at work where we&#8217;re dealing with data that updates frequently, at unpredictable times, used in across several different front-end services, and needs to scale to pretty decent traffic levels without going nuts on buying more hardware. </p>
<p>So, given all that, one of the things we&#8217;re looking at is using a distributed object caching layer, such as memcached.&nbsp; If you&#8217;re not sure what this technology does, the quick summary is that it is used to store commonly accessed data in memory on your servers. One of the most common uses is to cache results from database queries.&nbsp; </p>
<p><a href="http://www.danga.com/memcached/">memcached</a> started it&#8217;s life at <a href="http://www.danga.com/">Danga Interactive</a> to solve issues scaling <a href="http://www.livejournal.com/">LiveJournal</a> at 20 million+ pageviews per day. It has a proven track record in the Unix world, and a fairly significant base of knowledge on what works and various workarounds and solutions. </p>
<p>Whilst memcached is from Unix, there are also Windows based ports of the server, and also <a href="https://sourceforge.net/projects/memcacheddotnet/">.NET clients</a> so using it in our environment shouldn&#8217;t be an issue from the technical side.&nbsp; </p>
<p>Recently Microsoft also announced their entry into this space with a project code named <a href="http://blogs.msdn.com/velocity/">Velocity</a>. It&#8217;s pretty similar to memcached, but also has some additional functions allowing things like Tagging and Regionalising (Partitioning) data.&nbsp; There&#8217;s also more support at the moment for different cache expiry methods, and the roadmap includes additional redundancy bits too. </p>
<p>For anyone who is considering how their applications will scale up, there&#8217;s plenty more to read on the subject. </p>
<p>Dare Obasanjo has a post from July 2007 about <a href="http://www.25hoursaday.com/weblog/2007/07/05/ASPNETCachingVsMemcachedSeekingEfficientDataPartitioningLookupAndRetrieval.aspx">memcached on Windows</a>, and also more recently about <a href="http://www.25hoursaday.com/weblog/2008/06/06/VelocityADistributedInMemoryCacheFromMicrosoft.aspx">Velocity</a>.&nbsp; Scott Hanselman (Who I&#8217;m happy to say is coming to Tech.Ed Australia 2008!) has a podcast up about <a href="http://www.hanselman.com/blog/HanselminutesPodcast116DistributedCachingWithMicrosoftsVelocity.aspx">Velocity</a>, talking with Anil Nori &#8211; one of the smart fellows responsible for Velocity.</p>
<p>I&#8217;ll write some more on this as we progress down the build of this application.</p>
]]></content:encoded>
			<wfw:commentRss>http://will.hughesfamily.net.au/20080627/distributed-object-caching-memcached-velocity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LINQ to SQL Caching Gotcha</title>
		<link>http://will.hughesfamily.net.au/20080624/linq-to-sql-caching-gotcha/</link>
		<comments>http://will.hughesfamily.net.au/20080624/linq-to-sql-caching-gotcha/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 07:17:19 +0000</pubDate>
		<dc:creator>Will</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://will.hughesfamily.net.au/?p=910</guid>
		<description><![CDATA[So, today I discovered an issue which related to me doing two calls something a little like this: - Execute dc.sp_Proc1 - If some condition exists, execute dc.sp_Proc2, and then Execute dc.sp_Proc1 again with the same parameters. - Insert some records into the database. The problem is, the first time you execute the sproc, it [...]]]></description>
			<content:encoded><![CDATA[<p>So, today I discovered an issue which related to me doing two calls something a little like this: </p>
<p>- Execute dc.sp_Proc1<br />
- If some condition exists, execute dc.sp_Proc2, and then Execute dc.sp_Proc1 again with the same parameters.<br />
- Insert some records into the database. </p>
<p>The problem is, the first time you execute the sproc, it caches the result. This would be okay for most instances, but in mine &#8211; I&#8217;m actually after the updated result. </p>
<p>A quick bit of googling revealed <a href="http://www.rocksthoughts.com/blog/archive/2008/01/14/linq-to-sql-caching-gotcha.aspx">this post by Chris Rock</a>.  This approach of &#8220;turn off object tracking&#8221; works Ok if you don&#8217;t need to insert records on that Data Context.  </p>
<p>My quick, dirty, and (possibly) really wrong approach was just to spin up a new Data Context, and re-execute that sproc. </p>
<p>I promise I&#8217;ll find a more sane way of fixing this <img src='http://will.hughesfamily.net.au/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://will.hughesfamily.net.au/20080624/linq-to-sql-caching-gotcha/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>LINQ to SQL Learnings: Getting rid of the CRUD</title>
		<link>http://will.hughesfamily.net.au/20080609/linq-to-sql-learnings-getting-rid-of-the-crud/</link>
		<comments>http://will.hughesfamily.net.au/20080609/linq-to-sql-learnings-getting-rid-of-the-crud/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 18:39:52 +0000</pubDate>
		<dc:creator>Will</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://will.hughesfamily.net.au/20080609/linq-to-sql-learnings-getting-rid-of-the-crud/</guid>
		<description><![CDATA[With many web 2.0 applications there&#8217;s a basic three-tier architecture..&#160;&#160; In our case the client is a Flex 3/Caringorm application, the Services are WCF/ASP.NET Web Services, and the Database SQL 2005. One of the typical approaches to creating Web Services for this type of system is to use a CRUD type pattern. That is: all [...]]]></description>
			<content:encoded><![CDATA[<p>With many web 2.0 applications there&#8217;s a basic three-tier architecture..&nbsp;&nbsp; <a href="http://will.hughesfamily.net.au/20080308/linq-to-sql-wcf-json-and-flex-oh-my/">In our case</a> the client is a Flex 3/Caringorm application, the Services are WCF/ASP.NET Web Services, and the Database SQL 2005. </p>
<p>One of the typical approaches to creating Web Services for this type of system is to use a CRUD type pattern. That is: all methods are based around either Creating, Retrieving, Updating, or Deleting records.&nbsp; In most usually done on a per-table basis, and means that you&#8217;re effectively making the Web Services a HTTP enabled SQL client. </p>
<p>For our situation, this wasn&#8217;t really appropriate for a number of reasons, including complex relationships between tables, and a need to reduce the amount of network traffic. </p>
<p>Another concern, although relatively minor, is to reduce the amount of work needed by the Flex team to implement the Web Services.&nbsp; </p>
<p>Ideally, we wanted to be able to share business objects as widely as possible, to reduce the amount of rework needed by everyone involved in implementing the interfaces. </p>
<p>Therefore we chose to go with task, or semantic based methods, and using the objects as needed by the Flex front-end.&nbsp; The work of validation, and mapping to appropriate tables would be done by the Web services. </p>
<p>An example of this might be that a Document had many properties, such as Media Items (pictures, video, etc), Tags, Authors, etc.&nbsp; However, within the database there might be a necessity to track Document Versions, What versions are Live, the relationships between Documents, Document Versions and Media Items.&nbsp; </p>
<p>Because the objects that I needed to send/receive didn&#8217;t match the objects that needed to be saved in the database, I needed to write a lot of &#8220;left hand/right hand code&#8221;: ServiceDocument.Property =&nbsp;&nbsp; SQLDocument.Property.&nbsp; Most of this was fairly simple code to write, but tracking the places where this takes place can be grow to become quite a challenge when the solution grows to dozens of tables. </p>
<p>This is an approximate list of what I need to do to add a property to one table:</p>
<ul>
<li>Add the Property to the Service Types</li>
<li>Add conversion pieces to transpose the Service Type to/from the LINQ to SQL Object equivalents. </li>
<li>Add the column to the Table in the Database Model for LINQ to SQL</li>
<li>Add the column to all Stored Procedures in the Database Model which reference this, removing and re-adding them if this means new properties too.&nbsp; Don&#8217;t forget to ensure the return types on the re-added Stored Procedures are set correctly. </li>
<li>Add the columns to the actual Stored Procedures, update parameters, etc</li>
<li>Add the column to the actual Table </li>
</ul>
<p>I can only imagine the Version Control conflict chaos that would ensue if you had several people making these changes concurrently. </p>
<p>I highly recommend grouping changes into a per-table basis, because it can take a while to go through all the additional pieces you have referencing the LINQ to SQL and Service Type object equivilents. </p>
]]></content:encoded>
			<wfw:commentRss>http://will.hughesfamily.net.au/20080609/linq-to-sql-learnings-getting-rid-of-the-crud/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LINQ to SQL Learnings: SqlDateTime Overflow on Autogenerated Column</title>
		<link>http://will.hughesfamily.net.au/20080609/linq-to-sql-learnings-sqldatetime-overflow-on-autogenerated-column/</link>
		<comments>http://will.hughesfamily.net.au/20080609/linq-to-sql-learnings-sqldatetime-overflow-on-autogenerated-column/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 17:10:11 +0000</pubDate>
		<dc:creator>Will</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://will.hughesfamily.net.au/20080609/linq-to-sql-learnings-sqldatetime-overflow-on-autogenerated-column/</guid>
		<description><![CDATA[This is the first in (hopefully) a series of quick things I&#8217;ve picked up whilst tackling the previously mentioned project.&#160; So, I have a table something like this: CREATE TABLE [dbo].[Product](&#160; [ProductID] [int] IDENTITY(1,1) NOT NULL, &#160; [Name] [nvarchar](100) NOT NULL,&#160;&#160; [Price] [int] NOT NULL,&#160;&#160;&#160; [LastSaveTimestamp] [datetime] NOT NULL CONSTRAINT [DF_Product_SaveTimestamp]&#160; DEFAULT (getutcdate())) ON [PRIMARY] [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first in (hopefully) a series of quick things I&#8217;ve picked up whilst tackling the <a href="http://will.hughesfamily.net.au/20080308/linq-to-sql-wcf-json-and-flex-oh-my/">previously mentioned project</a>.&nbsp; </p>
<p>So, I have a table something like this: </p>
<p><span style="font-size: 10pt; color: blue">CREATE</span><span style="font-size: 10pt"> <span style="color: blue">TABLE</span> [dbo]<span style="color: gray">.</span>[Product]<span style="color: gray">(<br />&nbsp; </span></span><span style="font-size: 10pt">[ProductID] [int] <span style="color: blue">IDENTITY</span><span style="color: gray">(</span>1<span style="color: gray">,</span>1<span style="color: gray">)</span> <span style="color: gray">NOT</span> <span style="color: gray">NULL, <br />&nbsp; </span></span><span style="font-size: 10pt">[Name] [nvarchar]<span style="color: gray">(</span>100<span style="color: gray">)</span> <span style="color: gray">NOT</span> <span style="color: gray">NULL,</span></span><br />&nbsp;&nbsp; <span style="font-size: 10pt">[Price] [int] <span style="color: gray">NOT</span> <span style="color: gray">NULL,</span></span><br />&nbsp;&nbsp;&nbsp; <span style="font-size: 10pt">[LastSaveTimestamp] [datetime] <span style="color: gray">NOT</span> <span style="color: gray">NULL</span> <span style="color: blue">CONSTRAINT</span> [DF_Product_SaveTimestamp<wbr>]&nbsp; <span style="color: blue">DEFAULT</span> <span style="color: gray">(</span><span style="color: fuchsia">getutcdate</span><span style="color: gray">())<br /></span></span><span style="font-size: 10pt; color: gray">)</span><span style="font-size: 10pt"> <span style="color: blue">ON</span> [PRIMARY]</span></p>
<p><span style="font-size: 10pt">The key here is the default value on the column: LastSaveTimestamp. </span></p>
<p><span style="font-size: 10pt">If I then try to, say insert a new column into this table, for example using this code: </span></p>
<p><span style="font-size: 10pt"><span style="color: rgb(43,145,175)">&nbsp; DatabaseContext</span> dc = <span style="color: blue">new</span> <span style="color: rgb(43,145,175)">DatabaseContext</span>(); <br /></span><span style="font-size: 10pt">&nbsp; <span style="color: rgb(43,145,175)">Product</span> product = <span style="color: blue">new</span> <span style="color: rgb(43,145,175)">Product</span>();<br /></span><span style="font-size: 10pt">&nbsp; product.Name = <span style="color: rgb(163,21,21)">&#8220;test product&#8221;</span>;<br /></span><span style="font-size: 10pt">&nbsp; product.Price = 50;<br /></span><span style="font-size: 10pt">&nbsp; dc.Products.InsertOnSubmit<wbr>(product);<br /></span><span style="font-size: 10pt">&nbsp; dc.SubmitChanges(System<wbr>.Data.Linq.<span style="color: rgb(43,145,175)">ConflictMode</span>.FailOnFirstConflict);</span></p>
<p><span style="font-size: 10pt">Then I&#8217;d get an exception like: </span></p>
<blockquote><p><span style="font-size: 10pt"></span>System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM..</p>
</blockquote>
<p>The fix is actually really simple &#8211; In the table designer / DBML, you need to tell it that the column is auto-generated. Unfortunately this doesn&#8217;t seem to be automatically detected. It&#8217;s one of a few &#8216;just plain weird&#8217; situations.&nbsp; </p>
<p>AzamSharp has the <a href="http://geekswithblogs.net/AzamSharp/archive/2008/01/10/118446.aspx">fix details</a>, with a handy-dandy screenshot over on his blog. </p>
]]></content:encoded>
			<wfw:commentRss>http://will.hughesfamily.net.au/20080609/linq-to-sql-learnings-sqldatetime-overflow-on-autogenerated-column/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two WCF Stumbles</title>
		<link>http://will.hughesfamily.net.au/20080316/two-wcf-stumbles/</link>
		<comments>http://will.hughesfamily.net.au/20080316/two-wcf-stumbles/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 14:10:15 +0000</pubDate>
		<dc:creator>Will</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://will.hughesfamily.net.au/20080316/two-wcf-stumbles/</guid>
		<description><![CDATA[Here&#8217;s two things that caused me a bit of pain when working with WCF. Hopefully these pointers should help you get back to more productive things. No Output when returning Serialized / Serialised objects. I had been working on adding a significant number of methods and properties to a series of classes, and when I [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s two things that caused me a bit of pain when working with WCF. Hopefully these pointers should help you get back to more productive things.</p>
<h3>No Output when returning Serialized / Serialised objects. </h3>
<p>I had been working on adding a significant number of methods and properties to a series of classes, and when I went to test the service I got literally no output. </p>
<p>Debug points indicated that all properties were there, and valid &#8211; but still WCF wasn&#8217;t returning anything. There was no exceptions&nbsp; being returned to the client. </p>
<p>The best tool for debugging these sorts of solutions is to first of all enable Tracing and MessageLogging.&nbsp; This is done via the WCF Service Configuration Editor, on the Diagnostics tab.&nbsp; </p>
<p>Once you&#8217;ve done that, and re-run the projects &#8211; you can open up Service Trace Viewer.&nbsp; For me under Visual Studio 2008, this was under Microsoft Windows SDK v6.0A &gt; Tools.</p>
<p><img height="251" alt="image" src="http://will.hughesfamily.net.au/wp-content/uploads/2008/03/image.png" width="240" border="0"> </p>
<p>This tool then lets you open up the trace log generated in your solution directory, and see all the activity that&#8217;s been happening. </p>
<p><img height="301" alt="debugging-wcf-services" src="http://will.hughesfamily.net.au/wp-content/uploads/2008/03/debugging-wcf-services.jpg" width="502" border="0"> </p>
<p>From here, it was just a matter of scrolling down to the activity entry that had the yellow hilighting (indicating a warning), selecting it &#8211; then clicking on the Errors. </p>
<p>For me, the first time this happened to me, it was because <a href="http://will.hughesfamily.net.au/20080313/wcf-service-giving-blank-or-no-response/">I had stuffed up the DataMember Name values</a>. It has also occurred for other reasons, such as a property not being populated, when I had specified that it was both required, and also that it could not emit a default value. </p>
<h3>Can&#8217;t get mex to work</h3>
<p>No, this isn&#8217;t a misguided racial slur. I was having issues setting up the mexHttpBinding on an ASP.NET AJAX WCF Service. </p>
<p>The solutions all point towards the same thing, that you need to set up an endpoint, and set the contract to IMetaDataExchange, then set the behaviour to have &lt;serviceMetadata /&gt;. Except that it just wouldn&#8217;t let me add that property to my endpoint behaviour, and whenever I changed it to a service behaviour it would then not allow me&nbsp; to set the other properties I needed for that. </p>
<p>Well, perhaps I&#8217;m particularly slow &#8211; but hopefully this pointer will help someone else. </p>
<p>1: Create a NEW service behaviour: </p>
<blockquote><pre>
&lt;serviceBehaviors&gt;
&nbsp; &lt;behavior name="MyServiceBehavior"&gt;
&nbsp;&nbsp;&nbsp; &lt;serviceMetadata
      httpGetEnabled="true"/&gt;
    &lt;serviceDebug
     includeExceptionDetailInFaults="true"
     /&gt;
&nbsp; &lt;/behavior&gt;&lt;/serviceBehaviors&gt;</pre>
</blockquote>
<p>2: Add a new endpoint to your&nbsp; <strong>existing</strong> service</p>
<pre>&lt;endpoint
   address="mex"
   binding="mexHttpBinding"
   bindingConfiguration=""
   contract="IMetadataExchange" /&gt;</pre>
<p>3: Add the behaviorConfiguration you added in Step 1 to the <strong>Service </strong>(NOT the endpoint). </p>
<pre>&lt;service
  <strong>behaviorConfiguration="MyServiceBehavior"</strong>
  name="MyProject.MyService"&gt;</pre>
<p>I kept trying to add it to the endpoint, and failing miserably. So much time spent back-and-forth on this! </p>
<p>&nbsp;</p>
<p>That&#8217;s it for this instalment of &#8220;WCF is great, but I wish the config was a bit easier to understand&#8221;. Stay tuned for more exciting episodes!</p>
]]></content:encoded>
			<wfw:commentRss>http://will.hughesfamily.net.au/20080316/two-wcf-stumbles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
