<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Coding Adventure</title>
	
	<link>http://blog.codingadventure.com</link>
	<description>The adventure of writing meaningful code.</description>
	<lastBuildDate>Fri, 20 Aug 2010 23:21:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CodingAdventure" /><feedburner:info uri="codingadventure" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>[InvalidCrossThreadAccess] UI thread on Windows Phone 7</title>
		<link>http://feedproxy.google.com/~r/CodingAdventure/~3/ipEy_kHUhrE/</link>
		<comments>http://blog.codingadventure.com/2010/08/20/invalidcrossthreadaccess-ui-thread-on-windows-phone-7/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 23:21:49 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[threads]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[windows phone 7]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=320</guid>
		<description><![CDATA[When working with asynch operations on WP7  one of the easiest gotchas is accessing UI elements from different threads. The typical error looks sorta like this [InvalidCrossThreadAccess]. It is very easy to solve. The easiest way to solve the problem is using BeginInvoke : Deployment.Current.Dispatcher.BeginInvoke(() =&#62; { textBox1.Text = responseString; });]]></description>
			<content:encoded><![CDATA[<p>When working with asynch operations on WP7  one of the easiest gotchas is accessing UI elements from different threads. The typical error looks sorta like this [InvalidCrossThreadAccess].</p>
<p>It is very easy to solve. The easiest way to solve the problem is using <a href="http://msdn.microsoft.com/en-us/library/cc190259(VS.95).aspx">BeginInvoke </a>:</p>
<pre class="brush: csharp;">
Deployment.Current.Dispatcher.BeginInvoke(() =&gt;
{

      textBox1.Text = responseString;

});
</pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p><img src="http://feeds.feedburner.com/~r/CodingAdventure/~4/ipEy_kHUhrE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codingadventure.com/2010/08/20/invalidcrossthreadaccess-ui-thread-on-windows-phone-7/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.codingadventure.com/2010/08/20/invalidcrossthreadaccess-ui-thread-on-windows-phone-7/</feedburner:origLink></item>
		<item>
		<title>LINQ-To-SQL Improving Performance</title>
		<link>http://feedproxy.google.com/~r/CodingAdventure/~3/CpzQ6-U-XMA/</link>
		<comments>http://blog.codingadventure.com/2010/07/25/linq-to-sql-improving-performance/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 02:34:19 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=279</guid>
		<description><![CDATA[Linq to SQL is great. I love it because it adds a simple abstraction layer that can greatly speed up building a data access layer. If not used properly, LINQ to SQL can also create performance issues. Here are my general LINQ to SQL guidelines when I work in projects: Use the &#8220;using&#8221; statement when]]></description>
			<content:encoded><![CDATA[<p>Linq to SQL is great. I love it because it adds a simple abstraction layer that can greatly speed up building a data access layer.</p>
<p>If not used properly, LINQ to SQL can also create performance issues. Here are my general LINQ to SQL guidelines when I work in projects:</p>
<p><strong><br />
</strong></p>
<h2>Use the &#8220;using&#8221; statement when working with a context</h2>
<p>This is mostly a general C# programming guideline but there have been several times when I see programmers missing this step. Here is more information from <a href="http://msdn.microsoft.com/en-us/library/yh598w02(VS.80).aspx">MSDN</a>.</p>
<blockquote><p>The <strong>using</strong> statement allows the programmer to specify when objects that use resources should release them. The object provided to the <strong>using </strong>statement must implement the <a href="http://msdn.microsoft.com/en-us/library/system.idisposable(v=VS.80).aspx">IDisposable</a> interface. This interface provides the <a href="http://msdn.microsoft.com/en-us/library/system.idisposable.dispose(v=VS.80).aspx">Dispose</a> method, which should release the object&#8217;s resources.</p>
<p>A <strong>using</strong> statement can be exited either when the end of the <strong>using</strong> statement is reached or if an exception is thrown and control leaves the statement block before the end of the statement.</p></blockquote>
<p>Here is an example:</p>
<pre class="brush: csharp;">
using (NorthwindDataContext context = new NorthwindDataContext())
{
  //do stuff here
}
</pre>
<p><strong><br />
</strong></p>
<h2><strong>Compiled queries</strong></h2>
<p>To query something with LINQ to SQL there are several &#8220;startup&#8221; procedures. This procedures are not too bad when queries are not used too often. If the same query is done several times, its heavy and it is the core of the product then it is VERY important to make it a compiled query.</p>
<p>I will not go into too many details about this because there are several posts about the subject:</p>
<ul>
<li><a href="http://linqinaction.net/blogs/jwooley/archive/2007/09/05/linq-to-sql-compiled-queries.aspx">LINQ to SQL Compiled Queries</a></li>
<li><a href="http://www.davidhayden.com/blog/dave/archive/2008/02/19/HighPerformanceLINQToSQLCompiledQueriesORMappersEcommerceWebsites.aspx">High Performance LINQ To SQL &#8211; Compiled Queries &#8211; O/R Mappers &#8211; Ecommerce Websites</a></li>
</ul>
<p><strong><br />
</strong></p>
<h2>Use multiple tiny contexts instead of big bulky ones</h2>
<p>Contexts are meant to keep track of the objects in the database. By having small contexts with a single purpose then the burden of tracking is lessen and therefore there is less memory consumption.</p>
<p><strong><br />
</strong></p>
<h2>Do not keep track of object changes in the database unless its needed</h2>
<p>There are two good ways to improve the performance of queries that do not involve concurrency issues:</p>
<ol>
<li><a href="http://msdn.microsoft.com/en-us/library/Bb399369(v=VS.90).aspx">Optimistic concurrency  = off</a></li>
<li>Object tracking = off</li>
</ol>
<p>For object tracking, is super easy to turn off:</p>
<pre class="brush: csharp;">
context.ObjectTrackingEnabled = false;
</pre>
<p><a href="http://www.west-wind.com/Weblog/posts/313037.aspx">Sadly, as  Rick Strahl covers in his blog there are a few things/issues to consider when turning off Object Tracking.</a></p>
<p><strong><br />
</strong></p>
<h2>Combine Queries and custom expressions</h2>
<p>Combining queries is a good idea when working with databases, just grab what you need and aggregate the data into a POCO model or anonymous type. Finally, if extreme fine control is needed, there is always <a href="http://weblogs.asp.net/scottgu/archive/2007/08/27/linq-to-sql-part-8-executing-custom-sql-expressions.aspx">custom expressions</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p><img src="http://feeds.feedburner.com/~r/CodingAdventure/~4/CpzQ6-U-XMA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codingadventure.com/2010/07/25/linq-to-sql-improving-performance/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.codingadventure.com/2010/07/25/linq-to-sql-improving-performance/</feedburner:origLink></item>
		<item>
		<title>TeamCity Agent has unregistered (will upgrade)</title>
		<link>http://feedproxy.google.com/~r/CodingAdventure/~3/ubwylA4v6nk/</link>
		<comments>http://blog.codingadventure.com/2010/07/24/teamcity-agent-has-unregistered-will-upgrade/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 06:03:24 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=272</guid>
		<description><![CDATA[Recently I was setting up Teamcity and the build agent kept going down. It was starting and stopping. Sometimes it was &#8220;starting&#8230;&#8221; for a long time. After doing a bit of research I came across this. The agents would appear only for seconds under team city and then go down as inactive with the message &#8220;Agent has]]></description>
			<content:encoded><![CDATA[<p>Recently I was setting up Teamcity and the build agent kept going down. It was starting and stopping. Sometimes it was &#8220;starting&#8230;&#8221; for a long time.</p>
<p>After doing a bit of research I came across <a href="http://devnet.jetbrains.net/thread/286003">this</a>. The agents would appear only for seconds under team city and then go down as inactive with the message &#8220;Agent has unregistered (will upgrade)&#8221;. The culprit was my antivirus. Apparently this is a common issue but I have not seen many people blog about it.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p><img src="http://feeds.feedburner.com/~r/CodingAdventure/~4/ubwylA4v6nk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codingadventure.com/2010/07/24/teamcity-agent-has-unregistered-will-upgrade/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codingadventure.com/2010/07/24/teamcity-agent-has-unregistered-will-upgrade/</feedburner:origLink></item>
		<item>
		<title>Measuring Quality</title>
		<link>http://feedproxy.google.com/~r/CodingAdventure/~3/tYaVOPXA-to/</link>
		<comments>http://blog.codingadventure.com/2010/07/16/measuring-quality/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 04:56:38 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Software Management]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=255</guid>
		<description><![CDATA[Many developers forget that in our industry almost everything we do is a service. We are performing work for others at some level. In many cases there will errors in the service provided and then it is when we can measure the quality of the service. In my opinion, it is an error to try]]></description>
			<content:encoded><![CDATA[<p>Many developers forget that in our industry almost everything we do is a service. We are performing work for others at some level. In many cases there will errors in the service provided and then it is when we can measure the quality of the service.</p>
<p>In my opinion, it is an error to try to rate quality of a service as a relation between bugs and release version (this measures how effective are processes). I like to measure quality as a fixed bugs, release version and days to release correlation. This way, we can measure how good is the service by measuring how fast the bugs can be fixed (and properly fixed).</p>
<p>I am not a fan of the <a href="http://www.codinghorror.com/blog/2009/12/version-1-sucks-but-ship-it-anyway.html">even if version 1 sucks, ship it anyway</a> theory but it has some good points. Most of the clients that love my work are happy because any bugs that appeared on the systems have been fixed <strong>fast</strong> (and remain fixed).</p>
<p>Even google services go down but we all keep using them because <a href="http://www.google.com/appsstatus#hl=en">google fixes them right away</a>. <strong>How can one measure how good is a service? It can be measured by how fast it can respond to change.</strong></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p><img src="http://feeds.feedburner.com/~r/CodingAdventure/~4/tYaVOPXA-to" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codingadventure.com/2010/07/16/measuring-quality/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codingadventure.com/2010/07/16/measuring-quality/</feedburner:origLink></item>
		<item>
		<title>Sophos and SVN</title>
		<link>http://feedproxy.google.com/~r/CodingAdventure/~3/-Z7Uc6k8LKs/</link>
		<comments>http://blog.codingadventure.com/2010/07/03/sophos-and-svn/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 21:29:08 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=227</guid>
		<description><![CDATA[If you use Sophos Antivirus you might be getting Tortoise SVN related erros. It took me a while to figure it out. The best way to fix it is to exclude your projects directory from Sophos active scan.]]></description>
			<content:encoded><![CDATA[<p>If you use Sophos Antivirus you might be getting Tortoise SVN related erros. It took me a while to figure it out. The best way to fix it is to exclude your projects directory from Sophos active scan.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p><img src="http://feeds.feedburner.com/~r/CodingAdventure/~4/-Z7Uc6k8LKs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codingadventure.com/2010/07/03/sophos-and-svn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codingadventure.com/2010/07/03/sophos-and-svn/</feedburner:origLink></item>
		<item>
		<title>StructureMap Multiple Parameters</title>
		<link>http://feedproxy.google.com/~r/CodingAdventure/~3/8aL0Vnu5y5s/</link>
		<comments>http://blog.codingadventure.com/2010/07/03/structuremap-multiple-parameters/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 08:28:30 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Inversion of Control]]></category>
		<category><![CDATA[StructureMap]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=242</guid>
		<description><![CDATA[One of the common questions about IOC is how to pass parameters. This question is specially common with StructureMap since a lot of the old methods have been deprecated. Here is a quick Example: public class DataSource : IDataSource { public DataSource(string URL, string account, string password) { //your code here } } ObjectFactory.Initialize(x =&#62;]]></description>
			<content:encoded><![CDATA[<p>One of the common questions about <a href="http://blog.codingadventure.com/2010/02/04/inversion-of-control/">IOC</a> is how to pass parameters. This question is specially common with <a href="http://structuremap.github.com/structuremap/index.html">StructureMap</a> since a lot of the old methods have been deprecated.</p>
<p>Here is a quick Example:</p>
<pre class="brush: csharp;">

public class DataSource : IDataSource
{
        public DataSource(string URL, string account, string password)
        {
                     //your code here
         }

}
</pre>
<pre class="brush: csharp;">

ObjectFactory.Initialize(x =&gt;
{
      x.For&lt;IDataSource&gt;().Use&lt;DataSource&gt;()
           .Ctor&lt;string&gt;(&quot;URL&quot;).Is(URL)
           .Ctor&lt;string&gt;(&quot;account&quot;).Is(account)
           .Ctor&lt;string&gt;(&quot;password&quot;).Is(password)
           ;
}
</pre>
<p>and you can call it like this:</p>
<pre class="brush: csharp;">

private IDataSource ds = ObjectFactory.GetInstance&lt;IDataSource&gt;();
</pre>
<p>There is a huge amount of benefits as I mentioned in my <a href="http://blog.codingadventure.com/2010/02/04/inversion-of-control/">previous post</a>, including saving a lot of typing since all parameters are preconfigured.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p><img src="http://feeds.feedburner.com/~r/CodingAdventure/~4/8aL0Vnu5y5s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codingadventure.com/2010/07/03/structuremap-multiple-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codingadventure.com/2010/07/03/structuremap-multiple-parameters/</feedburner:origLink></item>
		<item>
		<title>VLC Performance</title>
		<link>http://feedproxy.google.com/~r/CodingAdventure/~3/R15UaNQeuR8/</link>
		<comments>http://blog.codingadventure.com/2010/07/02/vlc-performance/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 00:19:00 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=236</guid>
		<description><![CDATA[I was not a big fan of VLC. It felt a bit slow and it did not seem to render as smothly as MPC. Now that with the latest release of VLC that has truly changed. VLC 1.1.0 meets all my expectations. They did an excelent job with the GPU and DSP decoding. Here is the developers log from]]></description>
			<content:encoded><![CDATA[<p>I was not a big fan of <a href="http://en.wikipedia.org/wiki/VLC_media_player">VLC</a>. It felt a bit slow and it did not seem to render as smothly as <a href="http://en.wikipedia.org/wiki/Media_Player_Classic">MPC</a>.</p>
<p>Now that with the latest release of VLC that has truly changed. VLC 1.1.0 meets all my expectations. They did an excelent job with the GPU and DSP decoding.</p>
<p>Here is the developers log from GIT: <a href="http://git.videolan.org/?p=vlc/vlc-1.1.git;a=tag;h=1.1.0">http://git.videolan.org/?p=vlc/vlc-1.1.git;a=tag;h=1.1.0</a></p>
<blockquote><p>VLC 1.1.0 - &#8216;The Luggage&#8217;<br />
The first release of the 1.1.x branch of VLC</p>
<p>This is a major release, adding major features, notably:<br />
- GPU and DSP decoding on selected platforms<br />
- New support for codecs, demuxers and muxers<br />
- Lua extensions and Lua content extensions (luaSD)<br />
- Improved interfaces<br />
- Video Output rework<br />
- Removal of lots of modules, rewrite of many<br />
- Improved performances, in CPU, RAM and I/O<br />
- New libVLC and bindings<br />
- New or improved ports on misc platforms<br />
And so many bugs and other features&#8230;</p></blockquote>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p><img src="http://feeds.feedburner.com/~r/CodingAdventure/~4/R15UaNQeuR8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codingadventure.com/2010/07/02/vlc-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codingadventure.com/2010/07/02/vlc-performance/</feedburner:origLink></item>
		<item>
		<title>Windows Azure Tools for Microsoft Visual Studio 1.2 (June 2010)</title>
		<link>http://feedproxy.google.com/~r/CodingAdventure/~3/3t0-bn1UsgM/</link>
		<comments>http://blog.codingadventure.com/2010/06/29/windows-azure-tools-for-microsoft-visual-studio-1-2-june-2010/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 19:43:57 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=229</guid>
		<description><![CDATA[I am very happy Microsoft updated the Azure Tools to have full integration with Visual Studio. It is extremely easy to set up, just a few clicks to create a certificate and upload it. The process is all guided and it took me around 30 seconds. After the certificate has been uploaded you can deploy]]></description>
			<content:encoded><![CDATA[<p>I am very happy Microsoft updated the Azure Tools to have full integration with Visual Studio. It is extremely easy to set up, just a few clicks to create a certificate and upload it. The process is all guided and it took me around 30 seconds. After the certificate has been uploaded you can deploy from Visual Studio with a neat status bar.</p>
<p>There are some other neat features like IntelliTrace and others that are now available.</p>
<p>Here is a link to the latest release: <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2274a0a8-5d37-4eac-b50a-e197dc340f6f&amp;displaylang=en">Windows Azure Tools for Microsoft Visual Studio 1.2 (June 2010)</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p><img src="http://feeds.feedburner.com/~r/CodingAdventure/~4/3t0-bn1UsgM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codingadventure.com/2010/06/29/windows-azure-tools-for-microsoft-visual-studio-1-2-june-2010/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.codingadventure.com/2010/06/29/windows-azure-tools-for-microsoft-visual-studio-1-2-june-2010/</feedburner:origLink></item>
		<item>
		<title>Complete control over XML in WCF</title>
		<link>http://feedproxy.google.com/~r/CodingAdventure/~3/-y_SyIfQFTo/</link>
		<comments>http://blog.codingadventure.com/2010/06/26/complete-control-over-xml-in-wcf/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 02:49:35 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=210</guid>
		<description><![CDATA[Sometimes it is needed to have complete control over how WCF manipulates the data being returned. By default, WCF serializes objects and returns them as XML. Sadly, there is not much control on how to create templates over how objects will be serialized (flat structure, hierarchical, etc). In many cases this does not matter. A few weeks]]></description>
			<content:encoded><![CDATA[<p>Sometimes it is needed to have complete control over how WCF manipulates the data being returned. By default, WCF serializes objects and returns them as XML. Sadly, there is not much control on how to create templates over how objects will be serialized (flat structure, hierarchical, etc). In many cases this does not matter. A few weeks ago I stumbled for the first time when I need 100% control over how the XML was formated and being sent.</p>
<p>To send custom formated XML use the message envelope and not the string datatype. If the envelope is not used, it will add extra meta content.</p>
<p>Here is how it can be done:</p>
<pre class="brush: csharp;">
public Message GetMessage(string xml)
{
    XmlDocument x = new XmlDocument();

    //This is very important as it will VALIDATE the XML. Saved my butt a few times.
    x.LoadXml(xml);

    XmlElementBodyWriter writer = new XmlElementBodyWriter(x.DocumentElement);

    Message msg = Message.CreateMessage(MessageVersion.None,
                OperationContext.Current.OutgoingMessageHeaders.Action, writer);

    return msg;
}

public class XmlElementBodyWriter : BodyWriter
{
    XmlElement xmlElement;

    public XmlElementBodyWriter(XmlElement xmlElement)
                : base(true)
    {
         this.xmlElement = xmlElement;
    }

    protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
    {
         xmlElement.WriteTo(writer);
    }
 }
</pre>
<p>Also a little warning, the string passed in should be formated and already encoded in the format you want. This can make a huge difference specially when internationalization is involved.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p><img src="http://feeds.feedburner.com/~r/CodingAdventure/~4/-y_SyIfQFTo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codingadventure.com/2010/06/26/complete-control-over-xml-in-wcf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codingadventure.com/2010/06/26/complete-control-over-xml-in-wcf/</feedburner:origLink></item>
		<item>
		<title>Value Objects in F#</title>
		<link>http://feedproxy.google.com/~r/CodingAdventure/~3/RkMUZvQeDDg/</link>
		<comments>http://blog.codingadventure.com/2010/06/23/value-objects-in-f/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 07:26:10 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=202</guid>
		<description><![CDATA[Value Objects are objects that can be shared across different parts of a program. This can have great benefits in performance. Because  the objects are shared it is very important for value objects to be immutable. If value objects are not immutable then any part of the program can change the values and all the other parts can]]></description>
			<content:encoded><![CDATA[<p>Value Objects are objects that can be shared across different parts of a program. This can have great benefits in performance. Because  the objects are shared it is very important for value objects to be immutable. If value objects are not immutable then any part of the program can change the values and all the other parts can do calculation with erroneous data.</p>
<p>One of my goals was to make immutable objects in F# to take advantage of parallelization and automatic compiler optimizations:</p>
<pre class="brush: csharp;">

type City(Name:string, X: float, Y:float) =

member t.Name = Name

member t.X = X

member t.Y = Y

type NeighborCities(city1:string, city2:string) =

member x.fromCity = city1

member x.toCity = city2
</pre>
<p>Objects created in this manner in F# are immutable. Even when they are accessed in other projects outside their definition, their members are read-only. This was specially helpful on the distributed traveling salesman problem I built last year.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p><img src="http://feeds.feedburner.com/~r/CodingAdventure/~4/RkMUZvQeDDg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codingadventure.com/2010/06/23/value-objects-in-f/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.codingadventure.com/2010/06/23/value-objects-in-f/</feedburner:origLink></item>
	</channel>
</rss>
