<?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"
	>

<channel>
	<title>Web Development Guy</title>
	<atom:link href="http://www.webdevguy.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevguy.net</link>
	<description>Personal website of David Brown</description>
	<pubDate>Wed, 24 Sep 2008 23:12:06 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Test, test, test!</title>
		<link>http://www.webdevguy.net/2008/09/24/test-test-test/</link>
		<comments>http://www.webdevguy.net/2008/09/24/test-test-test/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 23:09:18 +0000</pubDate>
		<dc:creator>David Brown</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[activerecord]]></category>

		<category><![CDATA[csharp]]></category>

		<category><![CDATA[nhibernate]]></category>

		<category><![CDATA[quick tip]]></category>

		<guid isPermaLink="false">http://www.webdevguy.net/?p=38</guid>
		<description><![CDATA[Just a quick reminder to the programmers out there: make sure you write unit tests from the beginning!
I&#8217;ve recently been working on a NHibernate/ActiveRecord class library that&#8217;s fairly complex. When finished, it will wrap 125 database tables into C# classes. At the moment, it&#8217;s approximately 20% complete and I only just started writing unit tests [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick reminder to the programmers out there: <strong>make sure you write unit tests from the beginning!</strong></p>
<p>I&#8217;ve recently been working on a NHibernate/ActiveRecord class library that&#8217;s fairly complex. When finished, it will wrap 125 database tables into C# classes. At the moment, it&#8217;s approximately 20% complete and I only just started writing unit tests yesterday. What happened when I ran the tests?</p>
<p>They bombed. It seems there is a class somewhere that has a table name misspelled. Unfortunately, the tables I have wrapped have a ton of BelongsTo relationships, so the SQL statements generated are massive (lazy loading doesn&#8217;t seem to fix this, for some reason). It&#8217;s going to be a huge headache to track down the spelling mistake since the database driver doesn&#8217;t provide any useful error information.</p>
<p>If I had written a unit test every time I added a new table mapping, I would have caught my spelling mistake almost instantly. But, since I waited until the library was 20% finished, I just made my job that much harder.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevguy.net/2008/09/24/test-test-test/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Take a guess&#8230;</title>
		<link>http://www.webdevguy.net/2008/09/18/take-a-guess/</link>
		<comments>http://www.webdevguy.net/2008/09/18/take-a-guess/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 21:04:30 +0000</pubDate>
		<dc:creator>David Brown</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[photos]]></category>

		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.webdevguy.net/?p=35</guid>
		<description><![CDATA[
So, who wants to guess what brand of soda I drink every day? That photo happens to be the contents of my trash can at the office. The whole place is practically paper-less, as you can see.
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.webdevguy.net/wp/wp-content/uploads/guessmyfavdrink.jpg" alt="" title="Guess My Favorite Drink" width="406" height="406" class="alignnone size-full wp-image-36" /><br />
So, who wants to guess what brand of soda I drink every day? That photo happens to be the contents of my trash can at the office. The whole place is practically paper-less, as you can see.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevguy.net/2008/09/18/take-a-guess/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Simple Classic ASP Proxy</title>
		<link>http://www.webdevguy.net/2008/08/23/simple-classic-asp-proxy/</link>
		<comments>http://www.webdevguy.net/2008/08/23/simple-classic-asp-proxy/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 00:25:56 +0000</pubDate>
		<dc:creator>David Brown</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[ajax]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[classic asp]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://www.webdevguy.net/?p=26</guid>
		<description><![CDATA[The web application I&#8217;m working on comes in two parts: the API and the Interface. The API is an ASP.NET application. The interface is written entirely in Javascript (using ExtJS) and one very simple HTML page.
Hosting the Javascript interface in IIS was simple. The ASP.NET application, however, needs to be run in debug mode from [...]]]></description>
			<content:encoded><![CDATA[<p>The web application I&#8217;m working on comes in two parts: the API and the Interface. The API is an ASP.NET application. The interface is written entirely in Javascript (using ExtJS) and one very simple HTML page.</p>
<p>Hosting the Javascript interface in IIS was simple. The ASP.NET application, however, needs to be run in debug mode from Visual Studio 2008. Unfortunately, since I&#8217;m on Vista Home Premium, this just doesn&#8217;t work (the patch released by Microsoft was apparently for a pre-release version of Vista, and is therefore not installable on the retail version). That&#8217;s all fine and good. I can live with using the ASP.NET Development Server for now.</p>
<p>There&#8217;s a problem, however. The interface needs to make AJAX calls to the API application. The application runs on port 8888, rather than 80, so any XMLHttpRequest calls will be denied because a change in port number is classified as a change in domain. How do I make AJAX calls to the API application during development, then?</p>
<p>The answer: a proxy. I wrote a very small Classic ASP script (because who needs an entire ASP.NET application for 5 lines of code?) and placed it in the same directory as the Javascript interface:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="vb vb" style="font-family:monospace;"><span style="color: #b1b100;">Set</span> req = Server.<span style="color: #b1b100;">CreateObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;WinHttp.WinHttpRequest.5.1&quot;</span><span style="color: #66cc66;">&#41;</span>
req.<span style="color: #b1b100;">Open</span> <span style="color: #ff0000;">&quot;GET&quot;</span>, Request.<span style="color: #66cc66;">QueryString</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;url&quot;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #b1b100;">false</span>
req.<span style="color: #66cc66;">Send</span>
&nbsp;
Response.<span style="color: #66cc66;">ContentType</span> = req.<span style="color: #66cc66;">GetResponseHeader</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span><span style="color: #66cc66;">&#41;</span>
Response.<span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>req.<span style="color: #66cc66;">ResponseText</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Now, I make AJAX calls to <strong>/proxy.asp?url=http://localhost:8888/customers/list</strong>. The result is returned as XML which can be gobbled up by ExtJS and used for whatever I want. Of course, there&#8217;s no way I would recommend this for a production instance of the application. Ever.</p>
<p>For development purposes, however, it works pretty well. The only thing it needs is a way to preserve the query string. MonoRail throws a fit when I try to add that feature, however.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevguy.net/2008/08/23/simple-classic-asp-proxy/feed/</wfw:commentRss>
		</item>
		<item>
		<title>XML Serialize an object to a string</title>
		<link>http://www.webdevguy.net/2008/08/17/xml-serialize-object-to-string/</link>
		<comments>http://www.webdevguy.net/2008/08/17/xml-serialize-object-to-string/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 01:31:43 +0000</pubDate>
		<dc:creator>David Brown</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[csharp]]></category>

		<category><![CDATA[quick tip]]></category>

		<guid isPermaLink="false">http://www.webdevguy.net/?p=8</guid>
		<description><![CDATA[While working on a simple web API, I needed a way to serialize an object (using the XML serializer) to a string so I could return it as an API response. Unfortunately, there&#8217;s no Serialize() override for returning a string value. Instead, you&#8217;ll have to use a MemoryStream object and the System.Text.Encoding class.

1
2
3
4
XmlSerializer xs = [...]]]></description>
			<content:encoded><![CDATA[<p>While working on a simple web API, I needed a way to serialize an object (using the XML serializer) to a string so I could return it as an API response. Unfortunately, there&#8217;s no Serialize() override for returning a string value. Instead, you&#8217;ll have to use a MemoryStream object and the System.Text.Encoding class.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="csharp csharp" style="font-family:monospace;">XmlSerializer xs <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlSerializer<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>YourObject<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
MemoryStream ms <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MemoryStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
xs.<span style="color: #0000FF;">Serialize</span><span style="color: #000000;">&#40;</span>ms, instanceOfYourObject<span style="color: #000000;">&#41;</span>;
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>Encoding.<span style="color: #0000FF;">UTF8</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>ms.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<p>Perhaps an extension method would be good in this case.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetXmlString<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> XmlSerializer xs, <span style="color: #FF0000;">object</span> obj<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	MemoryStream ms <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MemoryStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	xs.<span style="color: #0000FF;">Serialize</span><span style="color: #000000;">&#40;</span>ms, obj<span style="color: #000000;">&#41;</span>;
	<span style="color: #0600FF;">return</span> Encoding.<span style="color: #0000FF;">UTF8</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>ms.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp csharp" style="font-family:monospace;">XmlSerializer xs <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlSerializer<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>YourObject<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>xs.<span style="color: #0000FF;">GetXmlString</span><span style="color: #000000;">&#40;</span>instanceOfYourObject<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.webdevguy.net/2008/08/17/xml-serialize-object-to-string/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
