<?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>Nebulae Spiral &#187; code</title>
	<atom:link href="http://inmyshadow.net/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://inmyshadow.net</link>
	<description>Spiralling Golden... and maybe blogging about code.</description>
	<lastBuildDate>Tue, 23 Dec 2008 04:17:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>fun with fractals</title>
		<link>http://inmyshadow.net/2008/12/07/fun-with-fractals/</link>
		<comments>http://inmyshadow.net/2008/12/07/fun-with-fractals/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 10:23:54 +0000</pubDate>
		<dc:creator>Nebulae</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[dark forest]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[nebulae]]></category>
		<category><![CDATA[universe]]></category>

		<guid isPermaLink="false">http://inmyshadow.net/?p=288</guid>
		<description><![CDATA[check it out, kinda interesting.  This is what happens when I go on tangents.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://inmyshadow.net/mandelbrot-square/">check it out</a>, kinda interesting.  This is what happens when I go on tangents.</p>
]]></content:encoded>
			<wfw:commentRss>http://inmyshadow.net/2008/12/07/fun-with-fractals/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WCF and Ajax and LINQ to SQL, oh my!</title>
		<link>http://inmyshadow.net/2008/12/06/wcf-and-ajax-and-linq-to-sql-oh-my/</link>
		<comments>http://inmyshadow.net/2008/12/06/wcf-and-ajax-and-linq-to-sql-oh-my/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 04:14:47 +0000</pubDate>
		<dc:creator>Nebulae</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://inmyshadow.net/?p=202</guid>
		<description><![CDATA[If you haven&#8217;t taken a dive into the Windows Communication Foundation until now, this is a good place to start.  I just recently dove in myself, and I found that accessing a .svc service from Ajax isn&#8217;t as straightforward as the old .asmx services, but it&#8217;s not that complicated either.
While we&#8217;re at it, lets [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t taken a dive into the Windows Communication Foundation until now, this is a good place to start.  I just recently dove in myself, and I found that accessing a .svc service from Ajax isn&#8217;t as straightforward as the old .asmx services, but it&#8217;s not that complicated either.</p>
<p>While we&#8217;re at it, lets look at some linq too.</p>
<p>As a testament to my detest of the usual customer &#8211; order database example that has been strewn all over the internet for examples such as these, lets do something a little more interesting and fun, how about a content rating system, from the ground up?</p>
<p>For this example, we&#8217;re going to pretend that we&#8217;re working with a database that already exists.  you could reverse this action and use the visual studio interface to create your tables for you, but that&#8217;s a whole blog unto itself and I&#8217;m anxious to get to the Ajax part.  more info and an oh-so stimulating read here: <a href="http://msdn.microsoft.com/en-us/library/bb425822.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/bb425822.aspx</a></p>
<p>Define some tables &#8211; we&#8217;ll need users, content, comments on said content, and a rating.  a comment is content in itself, isn&#8217;t it?</p>
<p>To start off, create a database called &#8220;ContentRatingExample&#8221; and run these scripts against your sql server:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">USE</span> <span style="color: #66cc66;">&#91;</span>ContentRatingExample<span style="color: #66cc66;">&#93;</span>
GO
<span style="color: #808080; font-style: italic;">/****** Object:  Table [dbo].[Users]    Script Date: 12/06/2008 18:45:35 ******/</span>
<span style="color: #993333; font-weight: bold;">SET</span> ANSI_NULLS <span style="color: #993333; font-weight: bold;">ON</span>
GO
<span style="color: #993333; font-weight: bold;">SET</span> QUOTED_IDENTIFIER <span style="color: #993333; font-weight: bold;">ON</span>
GO
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>Users<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span>
	<span style="color: #66cc66;">&#91;</span>ID<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>uniqueidentifier<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>UserName<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>nvarchar<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> COLLATE SQL_Latin1_General_CP1_CI_AS <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>DateCreated<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>datetime<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
 CONSTRAINT <span style="color: #66cc66;">&#91;</span>PK_Users<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> CLUSTERED
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #66cc66;">&#91;</span>ID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ASC</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #66cc66;">&#40;</span>PAD_INDEX  <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> STATISTICS_NORECOMPUTE  <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> IGNORE_DUP_KEY <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> ALLOW_ROW_LOCKS  <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">ON</span><span style="color: #66cc66;">,</span> ALLOW_PAGE_LOCKS  <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">ON</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">USE</span> <span style="color: #66cc66;">&#91;</span>ContentRatingExample<span style="color: #66cc66;">&#93;</span>
GO
<span style="color: #808080; font-style: italic;">/****** Object:  Table [dbo].[Content]    Script Date: 12/06/2008 18:45:13 ******/</span>
<span style="color: #993333; font-weight: bold;">SET</span> ANSI_NULLS <span style="color: #993333; font-weight: bold;">ON</span>
GO
<span style="color: #993333; font-weight: bold;">SET</span> QUOTED_IDENTIFIER <span style="color: #993333; font-weight: bold;">ON</span>
GO
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>Content<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span>
	<span style="color: #66cc66;">&#91;</span>ID<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>uniqueidentifier<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>CreatedBy<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>uniqueidentifier<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>Content<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>nvarchar<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span>max<span style="color: #66cc66;">&#41;</span> COLLATE SQL_Latin1_General_CP1_CI_AS <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>Title<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>nvarchar<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> COLLATE SQL_Latin1_General_CP1_CI_AS <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>DateCreated<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>datetime<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>DateModified<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>datetime<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>Parent<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>uniqueidentifier<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
 CONSTRAINT <span style="color: #66cc66;">&#91;</span>PK_content<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> CLUSTERED
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #66cc66;">&#91;</span>ID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ASC</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #66cc66;">&#40;</span>PAD_INDEX  <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> STATISTICS_NORECOMPUTE  <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> IGNORE_DUP_KEY <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> ALLOW_ROW_LOCKS  <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">ON</span><span style="color: #66cc66;">,</span> ALLOW_PAGE_LOCKS  <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">ON</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">USE</span> <span style="color: #66cc66;">&#91;</span>ContentRatingExample<span style="color: #66cc66;">&#93;</span>
GO
<span style="color: #808080; font-style: italic;">/****** Object:  Table [dbo].[Ratings]    Script Date: 12/06/2008 18:46:44 ******/</span>
<span style="color: #993333; font-weight: bold;">SET</span> ANSI_NULLS <span style="color: #993333; font-weight: bold;">ON</span>
GO
<span style="color: #993333; font-weight: bold;">SET</span> QUOTED_IDENTIFIER <span style="color: #993333; font-weight: bold;">ON</span>
GO
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>Ratings<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span>
	<span style="color: #66cc66;">&#91;</span>ID<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>uniqueidentifier<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>UserID<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>uniqueidentifier<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>ContentID<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>uniqueidentifier<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>Rating<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>tinyint<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>DateCreated<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>datetime<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
 CONSTRAINT <span style="color: #66cc66;">&#91;</span>PK_Ratings<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> CLUSTERED
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #66cc66;">&#91;</span>ID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ASC</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #66cc66;">&#40;</span>PAD_INDEX  <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> STATISTICS_NORECOMPUTE  <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> IGNORE_DUP_KEY <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> ALLOW_ROW_LOCKS  <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">ON</span><span style="color: #66cc66;">,</span> ALLOW_PAGE_LOCKS  <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">ON</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span></pre></div></div>

<p>Have a look, pretty simple little database.  A table for users, a table for Content, a table for ratings.  Note that the Content table has a parent column, this will be a reference to the id of the content so we can recurse and get all the comments for a content object, and all of their comments, allowing n-depth threading.  The user db is really simplistic, we don&#8217;t care about user profiles or anything at this point other then a friendly name to display.  The rest is self explanatory.</p>
<p>Lets jump over to visual studio now and create a new project.  Select a Class Library project and call it Common, Create a new solution for it and Call that ContentRating, and make sure &#8220;Create Directory for solution&#8221; is checked.</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-2.jpg"><img class="alignnone size-medium wp-image-208" title="untitled-2" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-2-300x193.jpg" alt="" width="300" height="193" /></a></p>
<p>Now, Add another project to that solution, call it &#8220;ContentRatingService&#8221; and select the type &#8220;WCF Service Application&#8221; from the Visual C# -&gt; Web Templates.</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-2.jpg"><img class="alignnone size-medium wp-image-208" title="untitled-2" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-2-300x193.jpg" alt="" width="300" height="193" /></a></p>
<p>Then add a website to the solution, call it UI.</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-3.jpg"><img class="alignnone size-medium wp-image-209" title="untitled-3" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-3-300x193.jpg" alt="" width="300" height="193" /></a></p>
<p>To this UI project, add a couple new folders: Includes and UserControls.  Inside the Includes folder, add 2 more folders: images and scripts.</p>
<p>your solution should now look like this:</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-5.jpg"><img class="alignnone size-medium wp-image-210" title="untitled-5" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-5-120x300.jpg" alt="" width="120" height="300" /></a></p>
<p>Now we just need to do a little cleanup and the skeleton of our solution will be ready.</p>
<p>To the &#8220;Common&#8221; Project:</p>
<ol>
<li>Right click on the Common project and select properties.</li>
<li>Under the Application tab, change the Assembly name and the Default Namespace to &#8220;ContentRating.Common&#8221; and save.</li>
<li>Delete Class1.cs</li>
</ol>
<p>To the &#8220;ContentRatingService&#8221; project:</p>
<ol>
<li>Right click on the Common project and select properties.</li>
<li>Under the Application tab, change the Assembly name and the Default Namespace to to ContentRating.Service and save.</li>
<li>Delete Service1.svc and IService1.cs</li>
<li>Add a reference to the Common project</li>
</ol>
<p>To the UI project:</p>
<ol>
<li>Right click on the Common project and select properties.</li>
<li>Under the Application tab, change the Assembly name and the Default Namespace to ContentRating.UI and save &#8211; are you seeing a pattern here?</li>
<li>Delete Default.aspx</li>
</ol>
<p>Your solution should now look like:</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-7.jpg"><img class="alignnone size-medium wp-image-212" title="untitled-7" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-7-106x300.jpg" alt="" width="106" height="300" /></a></p>
<p>Build the solution and make sure that the assembly names generated are ContentRating.UI.dll, ContentRating.Common.dll, and ContentRating.Service.dll</p>
<p>ok, now we can start :-)</p>
<p>The first project we&#8217;re going to modify is the &#8220;Common&#8221; project.  Right click on that bad boy and go &#8220;Add New Item&#8221;.  Select &#8220;Linq to SQL classes&#8221; and name it &#8220;ContentRatingClasses.dbml&#8221;.</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-8.jpg"><img class="alignnone size-medium wp-image-214" title="untitled-8" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-8-300x181.jpg" alt="" width="300" height="181" /></a></p>
<p>open up the server explorer and right click &#8220;Data Connections&#8221; -&gt; &#8220;Add Connection&#8221;.  Select &#8220;Microsoft SQL Sever&#8221; as the Data source and the .NET framework Data Provider for SQL as the Data Provider.   Hit Continue.</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-9.jpg"><img class="alignnone size-medium wp-image-215" title="untitled-9" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-9-300x135.jpg" alt="" width="300" height="135" /></a></p>
<p>select your server name, the ContentRatingExample db, and test the connection to make sure its all good, click ok.</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-10.jpg"><img class="alignnone size-medium wp-image-216" title="untitled-10" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-10-202x300.jpg" alt="" width="202" height="300" /></a></p>
<p>expand and drill down the dataconnections in the server explorer and you should see your tables:</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-13.jpg"><img class="alignnone size-medium wp-image-217" title="untitled-13" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-13-231x300.jpg" alt="" width="231" height="300" /></a></p>
<p>if not, you&#8217;ve done something wrong and need to fix it before continuing.</p>
<p>drag your tables onto the Object Relational Designer, and you&#8217;ll see them drawn out all pretty with the relationships defined.</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-15.jpg"><img class="alignnone size-medium wp-image-219" title="untitled-15" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-15-300x99.jpg" alt="" width="300" height="99" /></a></p>
<p>** note: because I have named some of the columns similar to the table name, visual studio took it upon itself to change the names for a couple of the properties: in the Ratings table, Ratings is now Rating1, and in the Content table, Content is now Content1.  my bad.  I should have conformed to a more robust naming convention.</p>
<p>Build and then have a look at the code behind by opening ContentRatingClasses.designer.cs.  you&#8217;ll see all the tables here have been generated into classes, and you should notice a lot of opportunity in this file &#8211; a lot more than we&#8217;re going to get into today but have a look at the partial classes and the partial methods for OnCreated, OnChanging and OnChanged, etc.  obviously, if you were to create another partial class of this type on the same namespace and implement the partial method, you&#8217;d be able to execute some code on each of these events.  Keep that in mind.</p>
<p>Here is where we stop and contemplate a few things.  In our service we are yet to create, we will need to return deserialized entities to be consumed by the client, in this case an Ajax application.  There is the option of creating a custom object to populate with the result of the linq query to these objects that the dbml generated, and apply the [DataContract] and [DataMember] attributes to those objects and properties respectively, so they can be deserialized and used at the other end.  This seems a little silly though, as it would be redundant, we already have the objects and types defined, why rewrite them?  Instead, lets take the easy way out:</p>
<p>double click the ContentRatingClasses.dbml file and right click anywhere inside the designer pane that has empty space and click properties, or otherwise fine the DataContext properties for the dbml.  Set the serializationMode to Unidirectional, save, and build.</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-17.jpg"><img class="alignnone size-medium wp-image-221" title="untitled-17" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-17-300x242.jpg" alt="" width="300" height="242" /></a></p>
<p>you&#8217;ll see that all of the objects in the ContentRatingClasses.designer.cs file now have the DataContract() attribute, and the properties have the DataMember() attribute, and we&#8217;re golden :-)</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #000000;">&#91;</span>Table<span style="color: #000000;">&#40;</span>Name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;dbo.Content&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #000000;">&#91;</span>DataContract<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> Content <span style="color: #008000;">:</span> INotifyPropertyChanging, INotifyPropertyChanged
	<span style="color: #000000;">&#123;</span>
                .
                .
                .
                <span style="color: #000000;">&#91;</span>Column<span style="color: #000000;">&#40;</span>Storage<span style="color: #008000;">=</span><span style="color: #666666;">&quot;_ID&quot;</span>, DbType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;UniqueIdentifier NOT NULL&quot;</span>, IsPrimaryKey<span style="color: #008000;">=</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #000000;">&#91;</span>DataMember<span style="color: #000000;">&#40;</span>Order<span style="color: #008000;">=</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0600FF;">public</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Guid</span> ID
		<span style="color: #000000;">&#123;</span>
                    .
                    .
                    .</pre></div></div>

<p>Righto &#8211; onto the service.</p>
<p>in the ContentRatingService project, add a new item &#8211; select WCF Service, name it Service.svc.  You&#8217;ll notice that IService.cs and Service.svc were created and added to the project.  IService.cs behaves as any other interface, add your rules here for the services you will expose.  a default DoWork service was created for you, with the attribute OperationContract.   First off, add a reference to System.ServiceModel.Web.  This will provide us with the Attribute we need to define our response format: WebInvoke(). Add some more contracts:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.ServiceModel</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.ServiceModel.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">ContentRating.Common</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> ContentRating.<span style="color: #0000FF;">Service</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#91;</span>ServiceContract<span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IService
    <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebInvoke<span style="color: #000000;">&#40;</span>ResponseFormat <span style="color: #008000;">=</span> WebMessageFormat.<span style="color: #0000FF;">Xml</span>,
            BodyStyle <span style="color: #008000;">=</span> WebMessageBodyStyle.<span style="color: #0000FF;">WrappedRequest</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        List GetUsers<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebInvoke<span style="color: #000000;">&#40;</span>ResponseFormat <span style="color: #008000;">=</span> WebMessageFormat.<span style="color: #0000FF;">Xml</span>,
            BodyStyle <span style="color: #008000;">=</span> WebMessageBodyStyle.<span style="color: #0000FF;">WrappedRequest</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        User GetUser<span style="color: #000000;">&#40;</span>Guid id<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebInvoke<span style="color: #000000;">&#40;</span>ResponseFormat <span style="color: #008000;">=</span> WebMessageFormat.<span style="color: #0000FF;">Xml</span>,
            BodyStyle <span style="color: #008000;">=</span> WebMessageBodyStyle.<span style="color: #0000FF;">WrappedRequest</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">void</span> AddUser<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> username<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebInvoke<span style="color: #000000;">&#40;</span>ResponseFormat <span style="color: #008000;">=</span> WebMessageFormat.<span style="color: #0000FF;">Xml</span>,
            BodyStyle <span style="color: #008000;">=</span> WebMessageBodyStyle.<span style="color: #0000FF;">WrappedRequest</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        List GetMainContent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebInvoke<span style="color: #000000;">&#40;</span>ResponseFormat <span style="color: #008000;">=</span> WebMessageFormat.<span style="color: #0000FF;">Xml</span>,
            BodyStyle <span style="color: #008000;">=</span> WebMessageBodyStyle.<span style="color: #0000FF;">WrappedRequest</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        List GetChildContent<span style="color: #000000;">&#40;</span>Guid ParentID<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebInvoke<span style="color: #000000;">&#40;</span>ResponseFormat <span style="color: #008000;">=</span> WebMessageFormat.<span style="color: #0000FF;">Xml</span>,
            BodyStyle <span style="color: #008000;">=</span> WebMessageBodyStyle.<span style="color: #0000FF;">WrappedRequest</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">void</span> AddContent<span style="color: #000000;">&#40;</span>Guid userID, <span style="color: #FF0000;">string</span> title, <span style="color: #FF0000;">string</span> text<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebInvoke<span style="color: #000000;">&#40;</span>ResponseFormat <span style="color: #008000;">=</span> WebMessageFormat.<span style="color: #0000FF;">Xml</span>,
            BodyStyle <span style="color: #008000;">=</span> WebMessageBodyStyle.<span style="color: #0000FF;">WrappedRequest</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">void</span> AddComment<span style="color: #000000;">&#40;</span>Guid userID, <span style="color: #FF0000;">string</span> title, <span style="color: #FF0000;">string</span> text, Guid contentID<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebInvoke<span style="color: #000000;">&#40;</span>ResponseFormat <span style="color: #008000;">=</span> WebMessageFormat.<span style="color: #0000FF;">Xml</span>,
            BodyStyle <span style="color: #008000;">=</span> WebMessageBodyStyle.<span style="color: #0000FF;">WrappedRequest</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        List GetRatingsForContent<span style="color: #000000;">&#40;</span>Guid ContentID<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebInvoke<span style="color: #000000;">&#40;</span>ResponseFormat <span style="color: #008000;">=</span> WebMessageFormat.<span style="color: #0000FF;">Xml</span>,
            BodyStyle <span style="color: #008000;">=</span> WebMessageBodyStyle.<span style="color: #0000FF;">WrappedRequest</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        List GetRatingsFromUser<span style="color: #000000;">&#40;</span>Guid UserID<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebInvoke<span style="color: #000000;">&#40;</span>ResponseFormat <span style="color: #008000;">=</span> WebMessageFormat.<span style="color: #0000FF;">Xml</span>,
            BodyStyle <span style="color: #008000;">=</span> WebMessageBodyStyle.<span style="color: #0000FF;">WrappedRequest</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">void</span> AddRating<span style="color: #000000;">&#40;</span>Guid contentID, Guid userID, <span style="color: #FF0000;">byte</span> rated<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The next step is to implement these members in the object:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">ContentRating.Common</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> ContentRating.<span style="color: #0000FF;">Service</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Service <span style="color: #008000;">:</span> IService
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> List GetUsers<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ContentRatingClassesDataContext ctx
                <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var users <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>from u <span style="color: #0600FF;">in</span> ctx.<span style="color: #0000FF;">Users</span>
                             select u<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> users<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> User GetUser<span style="color: #000000;">&#40;</span>Guid id<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ContentRatingClassesDataContext ctx
                <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var user <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>from u <span style="color: #0600FF;">in</span> ctx.<span style="color: #0000FF;">Users</span>
                            where u.<span style="color: #0000FF;">ID</span> <span style="color: #008000;">==</span> id
                             select u<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Single</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> user<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> AddUser<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> username<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ContentRatingClassesDataContext ctx
                <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                User user <span style="color: #008000;">=</span><span style="color: #008000;">new</span> User <span style="color: #000000;">&#123;</span>DateCreated <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Now</span>, ID <span style="color: #008000;">=</span> Guid.<span style="color: #0000FF;">NewGuid</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, UserName <span style="color: #008000;">=</span> username<span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
                ctx.<span style="color: #0000FF;">Users</span>.<span style="color: #0000FF;">InsertOnSubmit</span><span style="color: #000000;">&#40;</span>user<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                ctx.<span style="color: #0000FF;">SubmitChanges</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> List GetMainContent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ContentRatingClassesDataContext ctx
                <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var mainContent <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>from content <span style="color: #0600FF;">in</span> ctx.<span style="color: #0000FF;">Contents</span>
                                   where content.<span style="color: #0000FF;">Parent</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span>
                                   select content<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> mainContent<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> List GetChildContent<span style="color: #000000;">&#40;</span>Guid ParentID<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ContentRatingClassesDataContext ctx
                <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var childContent <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>from content <span style="color: #0600FF;">in</span> ctx.<span style="color: #0000FF;">Contents</span>
                                   where content.<span style="color: #0000FF;">Parent</span> <span style="color: #008000;">==</span> ParentID
                                   select content<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> childContent<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> AddContent<span style="color: #000000;">&#40;</span>Guid userID, <span style="color: #FF0000;">string</span> title, <span style="color: #FF0000;">string</span> text<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ContentRatingClassesDataContext ctx
                <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Content content <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Content
                                      <span style="color: #000000;">&#123;</span>
                                          ID <span style="color: #008000;">=</span> Guid.<span style="color: #0000FF;">NewGuid</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,
                                          DateModified <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Now</span>,
                                          DateCreated <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Now</span>,
                                          CreatedBy <span style="color: #008000;">=</span> userID,
                                          Title <span style="color: #008000;">=</span> title,
                                          Content1 <span style="color: #008000;">=</span> text
                                      <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
                ctx.<span style="color: #0000FF;">Contents</span>.<span style="color: #0000FF;">InsertOnSubmit</span><span style="color: #000000;">&#40;</span>content<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                ctx.<span style="color: #0000FF;">SubmitChanges</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> AddComment<span style="color: #000000;">&#40;</span>Guid userID, <span style="color: #FF0000;">string</span> title, <span style="color: #FF0000;">string</span> text, Guid contentID<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ContentRatingClassesDataContext ctx
                <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Content content <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Content
                                      <span style="color: #000000;">&#123;</span>
                                          ID <span style="color: #008000;">=</span> Guid.<span style="color: #0000FF;">NewGuid</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,
                                          DateModified <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Now</span>,
                                          DateCreated <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Now</span>,
                                          CreatedBy <span style="color: #008000;">=</span> userID,
                                          Title <span style="color: #008000;">=</span> title,
                                          Parent <span style="color: #008000;">=</span> contentID,
                                          Content1 <span style="color: #008000;">=</span> text
                                      <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
                ctx.<span style="color: #0000FF;">Contents</span>.<span style="color: #0000FF;">InsertOnSubmit</span><span style="color: #000000;">&#40;</span>content<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                ctx.<span style="color: #0000FF;">SubmitChanges</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> List GetRatingsForContent<span style="color: #000000;">&#40;</span>Guid ContentID<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ContentRatingClassesDataContext ctx
                <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var ratings <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>from rating <span style="color: #0600FF;">in</span> ctx.<span style="color: #0000FF;">Ratings</span>
                                    where rating.<span style="color: #0000FF;">ContentID</span> <span style="color: #008000;">==</span> ContentID
                                    select rating<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> ratings<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> List GetRatingsFromUser<span style="color: #000000;">&#40;</span>Guid UserID<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ContentRatingClassesDataContext ctx
                <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var ratings <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>from rating <span style="color: #0600FF;">in</span> ctx.<span style="color: #0000FF;">Ratings</span>
                               where rating.<span style="color: #0000FF;">UserID</span> <span style="color: #008000;">==</span> UserID
                               select rating<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> ratings<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> AddRating<span style="color: #000000;">&#40;</span>Guid contentID, Guid userID, <span style="color: #FF0000;">byte</span> rated<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>ContentRatingClassesDataContext ctx
                <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Rating rating <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Rating
                                    <span style="color: #000000;">&#123;</span>
                                        ID <span style="color: #008000;">=</span> Guid.<span style="color: #0000FF;">NewGuid</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,
                                        DateCreated <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Now</span>,
                                        ContentID <span style="color: #008000;">=</span> contentID,
                                        UserID <span style="color: #008000;">=</span> userID,
                                        Rating1 <span style="color: #008000;">=</span> rated
                                    <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
                ctx.<span style="color: #0000FF;">Ratings</span>.<span style="color: #0000FF;">InsertOnSubmit</span><span style="color: #000000;">&#40;</span>rating<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                ctx.<span style="color: #0000FF;">SubmitChanges</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>now open up the web.config in the ContentRatingService project.  near the bottom of the file, you&#8217;ll see a service and a behavior.  You&#8217;ll need to modify it to look like this:</p>
<p>&lt;system.serviceModel&gt;<br />
&lt;services&gt;<br />
&lt;service behaviorConfiguration=&#8221;ContentRating.Service.ServiceBehavior&#8221; name=&#8221;ContentRating.Service.Service&#8221;&gt;<br />
&lt;endpoint address=&#8221;" binding=&#8221;wsHttpBinding&#8221; contract=&#8221;ContentRating.Service.IService&#8221;&gt;<br />
&lt;identity&gt;<br />
&lt;dns value=&#8221;localhost&#8221;/&gt;<br />
&lt;/identity&gt;<br />
&lt;/endpoint&gt;<br />
&lt;endpoint address=&#8221;mex&#8221; binding=&#8221;mexHttpBinding&#8221; contract=&#8221;IMetadataExchange&#8221;/&gt;</p>
<p>&lt;!&#8211; the ajax endpoint &#8211;&gt;<br />
&lt;endpoint address=&#8221;ajaxEndpoint&#8221; behaviorConfiguration=&#8221;ajaxBehavior&#8221; binding=&#8221;webHttpBinding&#8221; contract=&#8221;ContentRating.Service.IService&#8221; /&gt;</p>
<p>&lt;/service&gt;<br />
&lt;/services&gt;<br />
&lt;behaviors&gt;<br />
&lt;serviceBehaviors&gt;<br />
&lt;behavior name=&#8221;ContentRating.Service.ServiceBehavior&#8221;&gt;<br />
&lt;serviceMetadata httpGetEnabled=&#8221;true&#8221;/&gt;<br />
&lt;!&#8211; changed to true so you can see anything that goes wrong &#8211;&gt;<br />
&lt;serviceDebug includeExceptionDetailInFaults=&#8221;true&#8221;/&gt;<br />
&lt;/behavior&gt;</p>
<p>&lt;/serviceBehaviors&gt;</p>
<p>&lt;!&#8211; the ajax endpoint behavior &#8211;&gt;<br />
&lt;endpointBehaviors&gt;<br />
&lt;behavior name=&#8221;ajaxBehavior&#8221;&gt;<br />
&lt;enableWebScript /&gt;<br />
&lt;/behavior&gt;<br />
&lt;/endpointBehaviors&gt;</p>
<p>&lt;/behaviors&gt;<br />
&lt;/system.serviceModel&gt;</p>
<p>and that&#8217;s all for the service.</p>
<p>I should have mentioned before,  or maybe i wanted you to get this far before breaking the news,  the Ajax implementation of this application will NOT be using the microsoft ajax dll or anything of that nature.  Ajax is easy and simple and you don&#8217;t need someone to handle it for you, and you should understand how it works from the inside anyway.</p>
<p>Go here and get the best cross browser ajax library you could need:</p>
<p><a href="http://code.google.com/p/xmlhttprequest/" target="_blank">http://code.google.com/p/xmlhttprequest/</a></p>
<p>and extract it to your Includes/scripts folder in the UI project.  This is only javascript, nothing to be scared of.  I will never understand the irrational fear of javascript some people have&#8230; anyway, add a file to your UI project, just a normal html file, call it default.html, or index.html, or whatever you want, it doesnt matter to me.  in the head section of that file, add a script reference the the XMLHttpRequest.js file you just saved.</p>
<p>Ajax is sandboxed, meaning that a request can only be made to the current server, you can&#8217;t cross domains.  to avoid any pain and suffering through running the site in debig mode by pressing F5 or play in visual studio, the next step is to create an site on localhost of the machine youre running this on so we don&#8217;t have any comminuication issues.  Go into IISManager, right click your server instance and select create new website.  go with the defaults for port 80 and set the path to be the root path of your project.  Allow anonymous access, and select Read, Run, and Browse.  Click finish to create it.  Make sure that the site is set to use asp.net 2 and not 1 in the asp.net settings tab under properties.  You should have a site that resembles this (without the resharper files unless you use resharper.. and if you dont, uhm&#8230; wtf?):</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-18.jpg"><img class="alignnone size-medium wp-image-233" title="untitled-18" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-18-300x124.jpg" alt="" width="300" height="124" /></a></p>
<p>now right click on the UI folder, click properties, click create to create it as an application.  do the same for the ContentRatingService folder.  you should have this:</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-19.jpg"><img class="alignnone size-medium wp-image-234" title="untitled-19" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-19-300x202.jpg" alt="" width="300" height="202" /></a></p>
<p>surf over to <a href="http://localhost/ContentRatingService/Service.svc">http://localhost/ContentRatingService/Service.svc</a> and you should see a &#8220;Service Service&#8221; definition &#8211; ahha!  those pesky bad naming conventions habits of mine&#8230; my bad&#8230; then go here <a href="http://localhost/ContentRatingService/Service.svc?wsdl">http://localhost/ContentRatingService/Service.svc?wsdl</a> or just click the link on the svc page.  There&#8217;s a lot of crazy info in there, the blatantly useful stuff is at the bottom.</p>
<p>go back to the default.html page4 in the UI project, and add some javascript in the head (please remove the code tags, they are there so the xml doesnt get parsed out by the browser, the javascript will break if you leave them in.  ) :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> AddUser<span style="color: #009900;">&#40;</span>username<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span>
        <span style="color: #003366; font-weight: bold;">var</span> client <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">+</span> username <span style="color: #339933;">+</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
        client.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'http://localhost/ContentRatingService/Service.svc/ajaxEndpoint/AddUser'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        client.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-length&quot;</span><span style="color: #339933;">,</span> data.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        client.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-type&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        client.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span> <span style="color: #339933;">||</span> client.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> XMLHttpRequest.<span style="color: #660066;">DONE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>client.<span style="color: #660066;">responseText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        client.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> GetUsers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> client <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
        client.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'http://localhost/ContentRatingService/Service.svc/ajaxEndpoint/GetUsers'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        client.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-length&quot;</span><span style="color: #339933;">,</span> data.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        client.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-type&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        client.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span> <span style="color: #339933;">||</span> client.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> XMLHttpRequest.<span style="color: #660066;">DONE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>client.<span style="color: #660066;">responseText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        client.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>code<span style="color: #339933;">&gt;</span></pre></div></div>

<p>and then in the body tags, create a couple controls to interact with this javascript:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;input type=button onclick=&quot;GetUsers()&quot; value=&quot;Get Users&quot; /&gt;
&lt;br /&gt;&lt;br /&gt;&lt;input type=text id='username' /&gt;
&lt;input type=button onclick=&quot;AddUser(document.getElementById('username').value)&quot; value=&quot;Add User&quot; /&gt;</pre></div></div>

<p>When you surf over to <a href="http://localhost/UI/default.html" target="_blank">http://localhost/UI/default.html</a> you should see:</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-20.jpg"><img class="alignnone size-medium wp-image-241" title="untitled-20" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-20-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>when you click the Get Users Button, you will be alerted:</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-21.jpg"><img class="alignnone size-medium wp-image-242" title="untitled-21" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-21-300x44.jpg" alt="" width="300" height="44" /></a></p>
<p>since we have no users, nothing was returned.</p>
<p>add a name to the text box and then click Add User.  you will see a blank alert, or an error.  a blank alert is good.  click Get Users again, and you will see:</p>
<p><a href="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-22.jpg"><img class="alignnone size-medium wp-image-243" title="untitled-22" src="http://inmyshadow.net/wp-content/uploads/2008/11/untitled-22-300x37.jpg" alt="" width="300" height="37" /></a></p>
<p>with the name of the user you just added.  pretty cool huh?</p>
<p>you can compare the data string sent into the ajax call to the properties that the service is expecting, and note that they are exactly the same, these are case sensitive.</p>
<p>Head back over to the ContentRatingClasses.dbml and right click on one of the tables to view code.  the file ContentRatingClasses.cs should come up, and into that file we want to implement an average rating property on the Content class.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Runtime.Serialization</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> ContentRating.<span style="color: #0000FF;">Common</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> Content
    <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#91;</span>DataMember<span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">decimal</span> AverageRating
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">partial</span> <span style="color: #0600FF;">void</span> OnLoaded<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span><span style="color: #000000;">&#40;</span> ContentRatingClassesDataContext ctx <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContentRatingClassesDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var ratings <span style="color: #008000;">=</span> from r <span style="color: #0600FF;">in</span> ctx.<span style="color: #0000FF;">Ratings</span>
                              where r.<span style="color: #0000FF;">ContentID</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ID</span>
                              select r<span style="color: #008000;">;</span>
&nbsp;
                var number <span style="color: #008000;">=</span> ratings.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #FF0000;">int</span> total <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span>var rate <span style="color: #0600FF;">in</span> ratings<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    total <span style="color: #008000;">+=</span> rate.<span style="color: #0000FF;">Rating1</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #FF0000;">decimal</span> average <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">decimal</span>.<span style="color: #0000FF;">TryParse</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>total<span style="color: #008000;">/</span>number<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">out</span> average<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    AverageRating <span style="color: #008000;">=</span> average<span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                AverageRating <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>At this point, all the functionality you will need on the server is complete.  the rest is javascript &#8211; some ajax calls and a little dhtml.</p>
<p>go back to your default.html page, and replace the script between the head tags with this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">        <span style="color: #003366; font-weight: bold;">function</span> SendRequest<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> postUrl<span style="color: #339933;">,</span> callBack<span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> client <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #339933;">;</span>
            client.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> postUrl<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            client.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-length&quot;</span><span style="color: #339933;">,</span> data.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            client.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-type&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            client.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span> <span style="color: #339933;">||</span> client.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> XMLHttpRequest.<span style="color: #660066;">DONE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    callBack<span style="color: #009900;">&#40;</span>client.<span style="color: #660066;">responseXML</span><span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            client.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">function</span> AddComment<span style="color: #009900;">&#40;</span>title<span style="color: #339933;">,</span> comment<span style="color: #339933;">,</span> userID<span style="color: #339933;">,</span> contentID<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;AddComment xmlns=&quot;http://tempuri.org/&quot;&gt;&lt;userID&gt;'</span> <span style="color: #339933;">+</span> userID <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/userID&gt;&lt;title&gt;'</span> <span style="color: #339933;">+</span> title <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/title&gt;&lt;text&gt;'</span> <span style="color: #339933;">+</span> comment <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/text&gt;&lt;contentID&gt;'</span> <span style="color: #339933;">+</span> contentID <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/contentID&gt;&lt;/AddComment&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> postUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://localhost/ContentRatingService/Service.svc/ajaxEndpoint/AddComment'</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> args <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            args<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> contentID<span style="color: #339933;">;</span>
            SendRequest<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> postUrl<span style="color: #339933;">,</span> GetAllMainContent<span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">function</span> GetAllMainContent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'content'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;GetMainContent xmlns=&quot;http://tempuri.org/&quot;&gt;&lt;/GetMainContent&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> postUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://localhost/ContentRatingService/Service.svc/ajaxEndpoint/GetMainContent'</span><span style="color: #339933;">;</span>
            SendRequest<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> postUrl<span style="color: #339933;">,</span> DrawContent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">function</span> GetChildContent<span style="color: #009900;">&#40;</span>parentID<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;GetChildContent xmlns=&quot;http://tempuri.org/&quot;&gt;&lt;ParentID&gt;'</span> <span style="color: #339933;">+</span> parentID <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/ParentID&gt;&lt;/GetChildContent&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> postUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://localhost/ContentRatingService/Service.svc/ajaxEndpoint/GetChildContent'</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> args <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            args<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> parentID<span style="color: #339933;">;</span>
            SendRequest<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> postUrl<span style="color: #339933;">,</span> DrawContent<span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">function</span> SubmitRating<span style="color: #009900;">&#40;</span>contentID<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            RateContent<span style="color: #009900;">&#40;</span>contentID<span style="color: #339933;">,</span>
                document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'users'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'users'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">selectedIndex</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span>
                document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rating_'</span> <span style="color: #339933;">+</span> contentID<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rating_'</span> <span style="color: #339933;">+</span> contentID<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">selectedIndex</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #003366; font-weight: bold;">function</span> RateContent<span style="color: #009900;">&#40;</span> contentID<span style="color: #339933;">,</span> userID<span style="color: #339933;">,</span> rated <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;AddRating xmlns=&quot;http://tempuri.org/&quot;&gt;&lt;contentID&gt;'</span> <span style="color: #339933;">+</span> contentID <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/contentID&gt;&lt;userID&gt;'</span> <span style="color: #339933;">+</span> userID <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/userID&gt;&lt;rated&gt;'</span> <span style="color: #339933;">+</span> rated <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/rated&gt;&lt;/AddRating&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> postUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://localhost/ContentRatingService/Service.svc/ajaxEndpoint/AddRating'</span><span style="color: #339933;">;</span>
            SendRequest<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> postUrl<span style="color: #339933;">,</span> DrawContent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">function</span> AddContent<span style="color: #009900;">&#40;</span>title<span style="color: #339933;">,</span> content<span style="color: #339933;">,</span> userID<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;AddContent xmlns=&quot;http://tempuri.org/&quot;&gt;&lt;userID&gt;'</span> <span style="color: #339933;">+</span> userID.<span style="color: #660066;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/userID&gt;&lt;title&gt;'</span> <span style="color: #339933;">+</span> title <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/title&gt;&lt;text&gt;'</span> <span style="color: #339933;">+</span> content <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/text&gt;&lt;/AddContent&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> postUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://localhost/ContentRatingService/Service.svc/ajaxEndpoint/AddContent'</span><span style="color: #339933;">;</span>
&nbsp;
            SendRequest<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> postUrl<span style="color: #339933;">,</span> GetAllMainContent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">function</span> SubmitComment<span style="color: #009900;">&#40;</span>contentID<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            AddComment<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title_'</span> <span style="color: #339933;">+</span> contentID<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span>
                document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'reply_'</span> <span style="color: #339933;">+</span> contentID<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span>
                document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'users'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'users'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">selectedIndex</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span>
                contentID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> AddUser<span style="color: #009900;">&#40;</span>username<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;AddUser xmlns=&quot;http://tempuri.org/&quot;&gt;&lt;username&gt;'</span> <span style="color: #339933;">+</span> username <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/username&gt;&lt;/AddUser&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> postUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://localhost/ContentRatingService/Service.svc/ajaxEndpoint/AddUser'</span><span style="color: #339933;">;</span>
        SendRequest<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> postUrl<span style="color: #339933;">,</span> GetUsers<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> GetUsers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;GetUsers xmlns=&quot;http://tempuri.org/&quot;&gt;&lt;/GetUsers&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> postUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://localhost/ContentRatingService/Service.svc/ajaxEndpoint/GetUsers'</span><span style="color: #339933;">;</span>
        SendRequest<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> postUrl<span style="color: #339933;">,</span> PopulateUsers<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> DrawContent<span style="color: #009900;">&#40;</span>responseXML<span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> contentNodes <span style="color: #339933;">=</span> responseXML.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Content'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!!</span>contentNodes <span style="color: #339933;">&amp;&amp;</span> contentNodes.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> contentNodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> contentNodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ID'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #003366; font-weight: bold;">var</span> div <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                div.<span style="color: #660066;">style</span>.<span style="color: #660066;">border</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'1px solid #CCCCCC'</span><span style="color: #339933;">;</span>
                div.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                div.<span style="color: #660066;">style</span>.<span style="color: #660066;">margin</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'25px'</span><span style="color: #339933;">;</span>
                div.<span style="color: #660066;">style</span>.<span style="color: #660066;">padding</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'5px'</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #003366; font-weight: bold;">var</span> b <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                b.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> contentNodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Title'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">;</span>
                div.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot; - rating: &quot;</span> <span style="color: #339933;">+</span> contentNodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'AverageRating'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">;</span>
&nbsp;
                div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot; - rate: &quot;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #003366; font-weight: bold;">var</span> select <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'select'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                select.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'rating_'</span> <span style="color: #339933;">+</span> id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">11</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #003366; font-weight: bold;">var</span> option <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Option<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    select.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>select.<span style="color: #660066;">options</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span> option<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
                div.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>select<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
                div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;a href=&quot;javascript:SubmitRating(<span style="color: #000099; font-weight: bold;">\'</span>'</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\'</span>)&quot;&gt;submit&lt;/a&gt;&lt;br /&gt;'</span><span style="color: #339933;">;</span>
                div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;p&gt;&quot;</span> <span style="color: #339933;">+</span> contentNodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Content1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
                div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;br /&gt;&lt;br /&gt;reply to this:&lt;br /&gt;&lt;input type=&quot;text&quot; id=&quot;title_'</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; /&gt;&lt;br /&gt;&lt;textarea id=&quot;reply_'</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;'</span><span style="color: #339933;">;</span>
                div.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;a href=&quot;javascript:SubmitComment(<span style="color: #000099; font-weight: bold;">\'</span>'</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\'</span>)&quot;&gt;submit&lt;/a&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>args <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'content'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    GetChildContent<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #003366; font-weight: bold;">var</span> parentID <span style="color: #339933;">=</span> args<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>parentID<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>div<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    GetChildContent<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> PopulateUsers<span style="color: #009900;">&#40;</span>responseXML<span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> userNodes <span style="color: #339933;">=</span> responseXML.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'User'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!!</span>userNodes <span style="color: #339933;">&amp;&amp;</span> userNodes.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'users'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> userNodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #003366; font-weight: bold;">var</span> option <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Option<span style="color: #009900;">&#40;</span>userNodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'UserName'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">,</span> userNodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ID'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003366; font-weight: bold;">var</span> count <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'users'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
                document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'users'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>count<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> option<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> PrepPage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        GetUsers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        GetAllMainContent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>and then replace the body:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;body onload=&quot;PrepPage()&quot;&gt;
    be user: &lt;select id='users'&gt;&lt;/select&gt;
    &lt;input type=&quot;text&quot; id='username' /&gt;
    &lt;input type=&quot;button&quot; onclick=&quot;AddUser(document.getElementById('username').value)&quot; value=&quot;Add User&quot; /&gt;
&nbsp;
    &lt;div id='content'&gt;
&nbsp;
    &lt;/div&gt;
    &lt;br /&gt;
    &lt;br /&gt;&lt;br /&gt;new content:&lt;br /&gt;
    &lt;input type=&quot;text&quot; id=&quot;title&quot; /&gt;
    &lt;br /&gt;&lt;textarea cols='30' rows='3' id=&quot;reply&quot;&gt;&lt;/textarea&gt;
    &lt;br /&gt;&lt;input type=&quot;button&quot; onclick=&quot;AddContent(document.getElementById('title').value, document.getElementById('reply').value,document.getElementById('users').options[document.getElementById('users').selectedIndex].value)&quot; value=&quot;Add&quot; /&gt;
&nbsp;
&nbsp;
&lt;/body&gt;</pre></div></div>

<p>what you will see will be ugly but functional, and pretty much self explanitory.  </p>
<p>complete solution here, all you&#8217;ll have to do is create the db, run the scripts above, and create the sites and apps in iis:  <a href='http://inmyshadow.net/wp-content/uploads/2008/12/contentratingservice.zip'>contentratingservice</a></p>
<p>Enjoy!  any questions, requests, please comment.</p>
<p>peace,<br />
neb</p>
]]></content:encoded>
			<wfw:commentRss>http://inmyshadow.net/2008/12/06/wcf-and-ajax-and-linq-to-sql-oh-my/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>RPC_E_ATTEMPTED_MULTITHREAD</title>
		<link>http://inmyshadow.net/2008/09/04/rpc_e_attempted_multithread/</link>
		<comments>http://inmyshadow.net/2008/09/04/rpc_e_attempted_multithread/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 16:02:22 +0000</pubDate>
		<dc:creator>Nebulae</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[moss]]></category>
		<category><![CDATA[sharepoint]]></category>

		<guid isPermaLink="false">http://inmyshadow.net/?p=143</guid>
		<description><![CDATA[Exception information:
Exception type: COMException
Exception message: Attempted to make calls on more than one thread in single threaded mode. (Exception from HRESULT: 0&#215;80010102 (RPC_E_ATTEMPTED_MULTITHREAD))
ooh yah baby.  this ones a doozy.
If you&#8217;re running into this in your sharepoint development journey, you have well bypassed the open site / open list / get list item / do [...]]]></description>
			<content:encoded><![CDATA[<p>Exception information:<br />
Exception type: COMException<br />
Exception message: Attempted to make calls on more than one thread in single threaded mode. (Exception from HRESULT: 0&#215;80010102 (RPC_E_ATTEMPTED_MULTITHREAD))</p>
<p>ooh yah baby.  this ones a doozy.</p>
<p>If you&#8217;re running into this in your sharepoint development journey, you have well bypassed the open site / open list / get list item / do stuff with it stage and have moved into the world of creating object representations of your list items, probably databinding that object off the list item to work with it, then populating the listitem columns from the object before saving it.  IMHO, this is a nice, clean and managable way of development, BUT you could run into a couple roadblocks.  this one looks a tad daunting but its an easy one to get around.</p>
<p>My scenario uses 3 lists.  Registrations, Organizations, and Solutions.  An Organization has an owner (registration) and 0-many solutions.  I know, I know, the organization should be a property of the registration, but i digress&#8230;</p>
<p>so i have an organization object.  this object has a bunch of fancy properties &#8211; address, phone number, etc, etc, and also an Owner and a List&lt;Solution&gt; .  During the databind of this object from the listitem, I attempted to set these objects and received the RPC_E_ATTEMPTED_MULTITHREAD error &#8211; if you google this error, which you probably have since you landed here, you&#8217;ll see some answers that will have you believe that you need to implicitly dispose of the SPSite, SPWeb &#8211; you may even be tempted to add a GC.Collect in there.</p>
<p>This didn&#8217;t &#8211; and still doesn&#8217;t &#8211; make a whole lot of sense to me because the access to the list item was wrapped in a using statement which of course only works with types that inherit from IDisposable, and will be disposed of when you exit the using statement, right?  Right? so you would think that after you access that list item and leave the using statement, the SPSite is disposed of and youre good to go&#8230; which is not really the case and I don&#8217;t know the intricacies of it all but I do know how to bypass this problem and the answer is &#8211; Lazy Loading.  yes, serious.</p>
<p>back to my databind&#8230;<br />
as I am binding all the properties from the listitem i just retrieved and I try to set the owner which would have to go access that site and get that list item from the registrations list, create a new owner object from that item, the RPC_E_ATTEMPTED_MULTITHREAD error gets thrown.  the same when I&#8217;m trying to populate the Associated Solutions.  If you move the code to populate these properties into the public accessor ( the getter ) so that the property is loaded when it is accessed instead of when the object is databound &#8211; poof!  problem solved.</p>
<p>If this doesn&#8217;t solve your problem, or you&#8217;re seeing this error in Sharepoint without having the structure i described above or some format of it, drop me a line and we can figure it out.</p>
<p>cheers,<br />
trinity<br />
err, neb</p>
]]></content:encoded>
			<wfw:commentRss>http://inmyshadow.net/2008/09/04/rpc_e_attempted_multithread/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Handy SPFolder / SPList / SPFile / SPWhatever interface, using Generics and Elevated Privs.</title>
		<link>http://inmyshadow.net/2008/08/28/handy-spfolder-splist-spfile-spwhatever-interface-using-generics/</link>
		<comments>http://inmyshadow.net/2008/08/28/handy-spfolder-splist-spfile-spwhatever-interface-using-generics/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 17:01:43 +0000</pubDate>
		<dc:creator>Nebulae</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[moss]]></category>
		<category><![CDATA[sharepoint]]></category>

		<guid isPermaLink="false">http://inmyshadow.net/?p=132</guid>
		<description><![CDATA[This is a handly little lib I wrote for accessing various types of objects using generics.  enjoy :-)

class SPDataAdapter
&#123;
    public static T GetObject&#40;string location&#41;
    &#123;
        object obj = null;
        SPSecurity.RunWithElevatedPrivileges&#40;delegate
     [...]]]></description>
			<content:encoded><![CDATA[<p>This is a handly little lib I wrote for accessing various types of objects using generics.  enjoy :-)</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> SPDataAdapter
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> T GetObject<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> location<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #FF0000;">object</span> obj <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        SPSecurity.<span style="color: #0000FF;">RunWithElevatedPrivileges</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">delegate</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>var site <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPSite<span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                obj <span style="color: #008000;">=</span> site.<span style="color: #0000FF;">OpenWeb</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetObject</span><span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span>obj<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> T GetObject<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> location, <span style="color: #FF0000;">bool</span> useElevatedPrivs<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>useElevatedPrivs<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">return</span> GetObject<span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>var site <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPSite<span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span>site.<span style="color: #0000FF;">OpenWeb</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetObject</span><span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> SPList GetList<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> location, <span style="color: #FF0000;">bool</span> useElevatedPrivs<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>useElevatedPrivs<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">return</span> GetList<span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>var site <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPSite<span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> site.<span style="color: #0000FF;">OpenWeb</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetList</span><span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> SPList GetList<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> location<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        SPList list <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        SPSecurity.<span style="color: #0000FF;">RunWithElevatedPrivileges</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">delegate</span>
       <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>var site <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPSite<span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                list <span style="color: #008000;">=</span> site.<span style="color: #0000FF;">OpenWeb</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetList</span><span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">return</span> list<span style="color: #008000;">;</span>
&nbsp;
   <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>and to test:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">&nbsp;
<span style="color: #000000;">&#91;</span>TestMethod<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> GetObjectTest1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    GetObjectTest1Helper<span style="color: #008000;">&lt;</span>SPFolder<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> GetObjectTest1Helper<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> location <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://spiral/Lists/Tasks&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">bool</span> useElevatedPrivs <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
    var actual <span style="color: #008000;">=</span> SPDataAdapter.<span style="color: #0000FF;">GetObject</span><span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>location, useElevatedPrivs<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    Assert.<span style="color: #0000FF;">IsNotNull</span><span style="color: #000000;">&#40;</span>actual<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>TestMethod<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> GetObjectTest<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    GetObjectTestHelper<span style="color: #008000;">&lt;</span>SPFile<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> GetObjectTestHelper<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> location <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://spiral/Lists/Tasks/Attachments/1/nebulae.jpg&quot;</span><span style="color: #008000;">;</span>
    T actual <span style="color: #008000;">=</span> SPDataAdapter.<span style="color: #0000FF;">GetObject</span><span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>location<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    Assert.<span style="color: #0000FF;">IsNotNull</span><span style="color: #000000;">&#40;</span>actual<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://inmyshadow.net/2008/08/28/handy-spfolder-splist-spfile-spwhatever-interface-using-generics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SPList Factory &#8211; singleton access to your lists.</title>
		<link>http://inmyshadow.net/2008/08/06/splist-factory-singleton-access-to-your-lists/</link>
		<comments>http://inmyshadow.net/2008/08/06/splist-factory-singleton-access-to-your-lists/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 19:17:11 +0000</pubDate>
		<dc:creator>Nebulae</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[moss]]></category>
		<category><![CDATA[sharepoint]]></category>

		<guid isPermaLink="false">http://inmyshadow.net/?p=108</guid>
		<description><![CDATA[A few months ago I was doing a refresher in GOF design patterns.  I have a couple favorites: memento, observer, state, and the factory of course :-)
So I was trying to implement these patterns in a conceptual SPAL ( sp access layer ), and what I&#8217;ve found is that having a SPListWrapper object, and a [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago I was doing a refresher in GOF design patterns.  I have a couple favorites: memento, observer, state, and the factory of course :-)</p>
<p>So I was trying to implement these patterns in a conceptual SPAL ( sp access layer ), and what I&#8217;ve found is that having a SPListWrapper object, and a factory to create them and allow static access is *<a title="please see the bees knees " href="http://farm1.static.flickr.com/31/60685364_cb0d3602ec.jpg" target="_blank">the bees knees</a>*, especially if you want to implement an ajax interface.  Since you only load the list once, its pretty speedy too.</p>
<p>I absolutely love ajax and making the sharepoint interface more robust and seamless.  Any interface for that matter.  there is a library i use exclusively that covers all browsers and addresses the issues found in each of them, even the pesky ie memory leak.</p>
<p>What Im getting at is that I have a bunch of cool stuff to share that probably would become convoluted in a mass array of blog entries, so I think it would be worthwhile to vlog it.  stay tuned, could take a  <span style="text-decoration: line-through;">few days</span> while.</p>
]]></content:encoded>
			<wfw:commentRss>http://inmyshadow.net/2008/08/06/splist-factory-singleton-access-to-your-lists/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Save Conflict in workflow on SPListItem.Update or SystemUpdate</title>
		<link>http://inmyshadow.net/2008/08/01/save-conflict-in-workflow-on-splistitemupdate-or-systemupdate/</link>
		<comments>http://inmyshadow.net/2008/08/01/save-conflict-in-workflow-on-splistitemupdate-or-systemupdate/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 08:16:18 +0000</pubDate>
		<dc:creator>Nebulae</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[moss]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[worklow]]></category>

		<guid isPermaLink="false">http://inmyshadow.net/?p=72</guid>
		<description><![CDATA[in this scenario, I have a really simple workflow that creates a task, does some infopath approval stuff, then copies that list item to another list.  the kicker is when you want to add something about that copied item to the original item, say an id column so you have a reference.  after [...]]]></description>
			<content:encoded><![CDATA[<p>in this scenario, I have a really simple workflow that creates a task, does some infopath approval stuff, then copies that list item to another list.  the kicker is when you want to add something about that copied item to the original item, say an id column so you have a reference.  after saving the copy, you set a column on the original and try to update the listitem, and get a &#8220;save conflict&#8221; error.  </p>
<p>Ive seen a lot of posts on this error, most of them point to not having access to that listitem because its locked by the workflow itself.  I would assume that you can somehow capture the item before the workflow updates it, and set the properties you want.  could someone enlighten me if this is true?  I&#8217;ve seen posts saying to use a delay, to wrap it in a repeating try / catch until the item is unlocked, to try programmatically to check it out, and then save it.  I can&#8217;t see any of this as being best answer.  </p>
<p>What Ive decided is to attach an event handler to the second list to set the id in the first.  this seems to be pretty reliable, plus I already had an event handler on that list.  I&#8217;m really curious to know if there&#8217;s a resolution for this.  </p>
<p>other info on this issue:<br />
<a href="http://forums.msdn.microsoft.com/en-US/sharepointdevelopment/thread/641b40fb-614f-4266-95c0-d61c2f443146/">http://forums.msdn.microsoft.com/en-US/sharepointdevelopment/thread/641b40fb-614f-4266-95c0-d61c2f443146/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://inmyshadow.net/2008/08/01/save-conflict-in-workflow-on-splistitemupdate-or-systemupdate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sharepoint Workflow &#8211; When you just can&#8217;t create a task.</title>
		<link>http://inmyshadow.net/2008/07/27/sharepoint-workflow-when-you-just-cant-create-a-task/</link>
		<comments>http://inmyshadow.net/2008/07/27/sharepoint-workflow-when-you-just-cant-create-a-task/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 20:41:56 +0000</pubDate>
		<dc:creator>Nebulae</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[moss]]></category>
		<category><![CDATA[sharepoint]]></category>

		<guid isPermaLink="false">http://inmyshadow.net/?p=21</guid>
		<description><![CDATA[I&#8217;ve been writing sharepoint applications for quite some time.  In fact, I consider myself pretty damn good at it.  Somehow though, I&#8217;ve been able to avoid writing much workflow all this time.  Event Handlers have been all I needed to this point.
I&#8217;ve never wanted to beat my head into a wall so much as this [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing sharepoint applications for quite some time.  In fact, I consider myself pretty damn good at it.  Somehow though, I&#8217;ve been able to avoid writing much workflow all this time.  Event Handlers have been all I needed to this point.</p>
<p>I&#8217;ve never wanted to beat my head into a wall so much as this last weeks adventure into workflow.  The infamous Julie kremer, who i hold in the highest of esteem as a friend and teacher, wrote a workflow for the OfficeLive app that Ive been working on for the last 5 or so months ( I think we&#8217;re on version 5 at this point, we iterate fast ) that takes a solution submitted by a small business owner and kicks off a workflow to have it approved before it shows up in the small business portal search &#8211; <a title="http://www.officelivepartnerdirectory.com" href="http://www.officelivepartnerdirectory.com/US/Pages/default.aspx" target="_blank">http://www.officelivepartnerdirectory.com</a>.</p>
<p>My task is to create a workflow that the company object will pass through for approval.  The goal is to catch any offensive company names or logos from showing up in the portal.  This seems pretty easy, logistical, shouldn&#8217;t be a problem right?</p>
<p>Well, right off the bat I was getting an exception in mscorlib</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Exception has been thrown by the target of an invocation.
   <span style="color: #0000FF;">at</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">RuntimeMethodHandle</span>._InvokeMethodFast<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> target, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> arguments, SignatureStruct<span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;</span> sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner<span style="color: #000000;">&#41;</span>
   at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">RuntimeMethodHandle</span>.<span style="color: #0000FF;">InvokeMethodFast</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> target, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner<span style="color: #000000;">&#41;</span>
   at <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span>.<span style="color: #0000FF;">RuntimeMethodInfo</span>.<span style="color: #0000FF;">Invoke</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> obj, BindingFlags invokeAttr, Binder binder, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> parameters, CultureInfo culture, Boolean skipVisibilityChecks<span style="color: #000000;">&#41;</span>
   at <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span>.<span style="color: #0000FF;">RuntimeMethodInfo</span>.<span style="color: #0000FF;">Invoke</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> obj, BindingFlags invokeAttr, Binder binder, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> parameters, CultureInfo culture<span style="color: #000000;">&#41;</span>
   at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">RuntimeType</span>.<span style="color: #0000FF;">InvokeMember</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> name, BindingFlags bindingFlags, Binder binder, <span style="color: #FF0000;">Object</span> target, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> providedArgs, ParameterModifier<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> modifiers, CultureInfo culture, <span style="color: #FF0000;">String</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> namedParams<span style="color: #000000;">&#41;</span>
   at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">Activities</span>.<span style="color: #0000FF;">CallExternalMethodActivity</span>.<span style="color: #0000FF;">Execute</span><span style="color: #000000;">&#40;</span>ActivityExecutionContext executionContext<span style="color: #000000;">&#41;</span>
   at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">ComponentModel</span>.<span style="color: #0000FF;">ActivityExecutor</span>`1.<span style="color: #0000FF;">Execute</span><span style="color: #000000;">&#40;</span>T activity, ActivityExecutionContext executionContext<span style="color: #000000;">&#41;</span>
   at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">ComponentModel</span>.<span style="color: #0000FF;">ActivityExecutor</span>`1.<span style="color: #0000FF;">Execute</span><span style="color: #000000;">&#40;</span>Activity activity, ActivityExecutionContext executionContext<span style="color: #000000;">&#41;</span>
   at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">ComponentModel</span>.<span style="color: #0000FF;">ActivityExecutorOperation</span>.<span style="color: #0000FF;">Run</span><span style="color: #000000;">&#40;</span>IWorkflowCoreRuntime workflowCoreRuntime<span style="color: #000000;">&#41;</span>
   at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">Runtime</span>.<span style="color: #0000FF;">Scheduler</span>.<span style="color: #0000FF;">Run</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>I added a fault handler to the workflow and bubbled up the inner exception to see what the deal was:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> code_HandleAllExceptions_ExecuteCode<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    WriteException<span style="color: #000000;">&#40;</span>faultHandlerActivity1_Fault1, <span style="color: #666666;">&quot;An error was handled by fault hander. &quot;</span> <span style="color: #008000;">+</span> faultHandlerActivity1_Fault1.<span style="color: #0000FF;">InnerException</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> WriteException<span style="color: #000000;">&#40;</span>Exception e, <span style="color: #FF0000;">string</span> message<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    WriteTrace<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CompanyWF ERROR: &quot;</span> <span style="color: #008000;">+</span> message <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">+</span> e.<span style="color: #0000FF;">Message</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span> <span style="color: #008000;">+</span> e.<span style="color: #0000FF;">StackTrace</span>, <span style="color: #666666;">&quot;ERROR&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> WriteInfo<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> message<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    WriteTrace<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;CompanyWF: &quot;</span> <span style="color: #008000;">+</span> message, <span style="color: #666666;">&quot;INFO&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> WriteTrace<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">string</span> message, <span style="color: #FF0000;">string</span> level <span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    Trace.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;[&quot;</span><span style="color: #008000;">+</span>DateTime.<span style="color: #0000FF;">Now</span><span style="color: #008000;">+</span><span style="color: #666666;">&quot;] &quot;</span> <span style="color: #008000;">+</span> message, level<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>which then reported a null reference exception:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span> ERROR<span style="color: #008000;">:</span> <span style="color: #000000;">&#91;</span><span style="color: #FF0000;">7</span><span style="color: #008000;">/</span><span style="color: #FF0000;">25</span><span style="color: #008000;">/</span><span style="color: #FF0000;">2008</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">:</span><span style="color: #FF0000;">36</span><span style="color: #008000;">:</span><span style="color: #FF0000;">46</span> AM<span style="color: #000000;">&#93;</span> CompanyWF ERROR<span style="color: #008000;">:</span> An error was handled by fault hander. <span style="color: #000000;">System</span>.<span style="color: #0000FF;">NullReferenceException</span><span style="color: #008000;">:</span> <span style="color: #FF0000;">Object</span> reference not set to an instance of an <span style="color: #FF0000;">object</span>.
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at Microsoft.<span style="color: #0000FF;">SharePoint</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">SPWorkflowTask</span>.<span style="color: #0000FF;">SetWorkflowData</span><span style="color: #000000;">&#40;</span>SPListItem task, Hashtable newValues, Boolean ignoreReadOnly<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at Microsoft.<span style="color: #0000FF;">SharePoint</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">SPWinOETaskService</span>.<span style="color: #0000FF;">UpdateTaskInternal</span><span style="color: #000000;">&#40;</span>Guid taskId, SPWorkflowTaskProperties properties, Boolean fSetWorkflowFinalize, Boolean fCreating, HybridDictionary specialPermissions<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at Microsoft.<span style="color: #0000FF;">SharePoint</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">SPWinOETaskService</span>.<span style="color: #0000FF;">CreateTaskWithContentTypeInternal</span><span style="color: #000000;">&#40;</span>Guid taskId, SPWorkflowTaskProperties properties, Boolean useDefaultContentType, SPContentTypeId ctid, HybridDictionary specialPermissions<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at Microsoft.<span style="color: #0000FF;">SharePoint</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">SPWinOETaskService</span>.<span style="color: #0000FF;">CreateTask</span><span style="color: #000000;">&#40;</span>Guid taskId, SPWorkflowTaskProperties properties, HybridDictionary specialPermissions<span style="color: #000000;">&#41;</span> Exception has been thrown by the target of an invocation.
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">RuntimeMethodHandle</span>._InvokeMethodFast<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> target, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> arguments, SignatureStruct<span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;</span> sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">RuntimeMethodHandle</span>.<span style="color: #0000FF;">InvokeMethodFast</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> target, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span>.<span style="color: #0000FF;">RuntimeMethodInfo</span>.<span style="color: #0000FF;">Invoke</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> obj, BindingFlags invokeAttr, Binder binder, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> parameters, CultureInfo culture, Boolean skipVisibilityChecks<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at <span style="color: #000000;">System.<span style="color: #0000FF;">Reflection</span></span>.<span style="color: #0000FF;">RuntimeMethodInfo</span>.<span style="color: #0000FF;">Invoke</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> obj, BindingFlags invokeAttr, Binder binder, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> parameters, CultureInfo culture<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">RuntimeType</span>.<span style="color: #0000FF;">InvokeMember</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> name, BindingFlags bindingFlags, Binder binder, <span style="color: #FF0000;">Object</span> target, <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> providedArgs, ParameterModifier<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> modifiers, CultureInfo culture, <span style="color: #FF0000;">String</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> namedParams<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">Activities</span>.<span style="color: #0000FF;">CallExternalMethodActivity</span>.<span style="color: #0000FF;">Execute</span><span style="color: #000000;">&#40;</span>ActivityExecutionContext executionContext<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">ComponentModel</span>.<span style="color: #0000FF;">ActivityExecutor</span>`1.<span style="color: #0000FF;">Execute</span><span style="color: #000000;">&#40;</span>T activity, ActivityExecutionContext executionContext<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">ComponentModel</span>.<span style="color: #0000FF;">ActivityExecutor</span>`1.<span style="color: #0000FF;">Execute</span><span style="color: #000000;">&#40;</span>Activity activity, ActivityExecutionContext executionContext<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">ComponentModel</span>.<span style="color: #0000FF;">ActivityExecutorOperation</span>.<span style="color: #0000FF;">Run</span><span style="color: #000000;">&#40;</span>IWorkflowCoreRuntime workflowCoreRuntime<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4120</span><span style="color: #000000;">&#93;</span>    at <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Workflow</span>.<span style="color: #0000FF;">Runtime</span>.<span style="color: #0000FF;">Scheduler</span>.<span style="color: #0000FF;">Run</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>One of the properties I was trying to push into the ExtendedProperties propertybag was null, I changed that and we were past this exception.  The lesson here is to grab the InnerException of your fault handler and hope that it returns something descriptive, i guess :-)</p>
<p>In case you are wondering, the trace viewer i use is called DebugView, brought to my attention by the industrious Eric Jobin.</p>
<p>Another issue I was having with the InfoPath form though, was quite a bit harder to track down, but a stupid mistake in the long run.  I was creating a link to the infopath form with an item id in the query string, but it was the wrong item, wrong list :-)  The error I was getting was something extremely vague and Sharepointy, but what helped me figure it out was enabling (in a google friendly fashion) &#8211; verbose sharepoint  exception reporting &#8211; verbose sharepoint error handling &#8211; full Moss exception handling &#8211; good enough.</p>
<p>This is a lot easier than you might think, and you&#8217;ve probably done this before with other web applications you&#8217;ve needed to debug.  Open the Web.Config for your spsite and find:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SharePoint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SafeMode</span> <span style="color: #000066;">MaxControls</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">CallStack</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">DirectFileDependencies</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">TotalFileDependencies</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">AllowPageLevelTrace</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p>and change it to:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SharePoint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SafeMode</span> <span style="color: #000066;">MaxControls</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">CallStack</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">DirectFileDependencies</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">TotalFileDependencies</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">AllowPageLevelTrace</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p>then find the node:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.web<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;customErrors</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;On&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>and set it to &#8220;Off&#8221;</p>
<p>you may have to recycle your app pool before changes take effect, but you should now see a stack trace when you cause an error &#8211; hopefully more helpful than the generic Unknown Exception that we had all come to love.  </p>
<p>peace, and happy coding&#8230;<br />
trinity</p>
]]></content:encoded>
			<wfw:commentRss>http://inmyshadow.net/2008/07/27/sharepoint-workflow-when-you-just-cant-create-a-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chris O&#8217;Brien&#8217;s blog</title>
		<link>http://inmyshadow.net/2008/07/27/chris-obriens-blog/</link>
		<comments>http://inmyshadow.net/2008/07/27/chris-obriens-blog/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 17:38:44 +0000</pubDate>
		<dc:creator>Nebulae</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[moss]]></category>
		<category><![CDATA[sharepoint]]></category>

		<guid isPermaLink="false">http://inmyshadow.net/?p=31</guid>
		<description><![CDATA[Chris O&#8217;Brien&#8217;s blog. &#8211; Great SharePoint resource.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sharepointnutsandbolts.com/">Chris O&#8217;Brien&#8217;s blog</a>. &#8211; Great SharePoint resource.</p>
]]></content:encoded>
			<wfw:commentRss>http://inmyshadow.net/2008/07/27/chris-obriens-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
