<?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>Annoyed.ca &#187; VB.Net</title>
	<atom:link href="http://annoyed.ca/category/technology/net/vbnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://annoyed.ca</link>
	<description>Life - Technology</description>
	<lastBuildDate>Mon, 30 Jan 2012 20:57:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>My First Extension Method</title>
		<link>http://annoyed.ca/2008/12/27/my-first-extension-method/</link>
		<comments>http://annoyed.ca/2008/12/27/my-first-extension-method/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 05:43:53 +0000</pubDate>
		<dc:creator>Christopher Hyne</dc:creator>
				<category><![CDATA[S#arp Architecture]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://annoyed.ca/2008/12/28/my-first-extension-method/</guid>
		<description><![CDATA[This evening I wrote my first VB.Net extension method while working on my S#arp Architecture based project. I added another overload of the TextBox method (which is itself an extension method, I believe). I wanted to be able to specify &#8230; <a href="http://annoyed.ca/2008/12/27/my-first-extension-method/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This evening I wrote my first VB.Net extension method while working on my S#arp Architecture based project. I added another overload of the TextBox method (which is itself an extension method, I believe). I wanted to be able to specify the size of the text box. One of the existing TextBox methods has the following signature:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">HtmlHelper.TextBox(name <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>, value <span style="color: #0000ff">As</span> <span style="color: #0000ff">Object</span>, htmlAttributes <span style="color: #0000ff">As</span> IDictionary(Of <span style="color: #0000ff">String</span>, <span style="color: #0000ff">Object</span>))</pre>
</div>
<p>I wanted to be able to specify a text box size without having to declare a new IDictionary every time. So I wrote the following extension method:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&lt;Extension()&gt; _
<span style="color: #0000ff">Public</span> <span style="color: #0000ff">Function</span>(html <span style="color: #0000ff">As</span> HtmlHelper, name <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>, value <span style="color: #0000ff">As</span> <span style="color: #0000ff">Object</span>, size <span style="color: #0000ff">As</span> <span style="color: #0000ff">Integer</span>)
    <span style="color: #0000ff">Dim</span> attributes <span style="color: #0000ff">as</span> IDictionary(Of <span style="color: #0000ff">String</span>, <span style="color: #0000ff">Object</span>) = <span style="color: #0000ff">New</span> Dictionary(Of <span style="color: #0000ff">String</span>, <span style="color: #0000ff">Object</span>)

    attributes.Add(<span style="color: #006080">"size"</span>, size)

    <span style="color: #0000ff">Return</span> html.TextBox(name, value, attributes)
<span style="color: #0000ff">End</span> Function</pre>
</div>
<p>Neat stuff.</p>
<p>Now I just have to figure out how to create an extension method that will allow me to pass a lambda expression to RedirectToAction().</p>
]]></content:encoded>
			<wfw:commentRss>http://annoyed.ca/2008/12/27/my-first-extension-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Inner Workings of *.vbproj Files: &lt;ProjectTypeGuids&gt;</title>
		<link>http://annoyed.ca/2008/12/23/the-inner-workings-of-vbproj-files-projecttypeguids/</link>
		<comments>http://annoyed.ca/2008/12/23/the-inner-workings-of-vbproj-files-projecttypeguids/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 02:58:26 +0000</pubDate>
		<dc:creator>Christopher Hyne</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[S#arp Architecture]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://annoyed.ca/2008/12/26/the-inner-workings-of-vbproj-files-projecttypeguids/</guid>
		<description><![CDATA[During the conversion of the S#arp Architecture template project from C# to VB.Net I inadvertently broke (at least) one thing: the ability to add ASP.Net MVC items directly to the SharpArch.Web project directly from the &#8220;Add New Items&#8230;&#8221; dialog. This &#8230; <a href="http://annoyed.ca/2008/12/23/the-inner-workings-of-vbproj-files-projecttypeguids/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>During the conversion of the S#arp Architecture template project from C# to VB.Net I inadvertently broke (at least) one thing: the ability to add ASP.Net MVC items directly to the SharpArch.Web project directly from the &#8220;Add New Items&#8230;&#8221; dialog. This led to <a href="http://stackoverflow.com/questions/386548/how-to-enable-aspnet-mvc-item-templates-for-sarp-architecture-project" target="_blank">my first question asked on StackOverflow.com</a> (which I ended up answering myself, 38 minutes later).</p>
<p>Turns out Visual Studio project files can have an element called &lt;ProjectTypeGuids&gt; which contains one or more guids identifying what type of project the file describes. ASP.Net MVC projects have a particular guid specified: <strong>{603c0e0b-db56-11dc-be95-000d561079b0}</strong>.</p>
<p>So I added this guid to both my SharpArch.Web project file and my SharpArch.Controllers project file, and now I can add new MVC template items directly from the &#8220;Add New Item&#8230;&#8221; dialog. Cool!</p>
]]></content:encoded>
			<wfw:commentRss>http://annoyed.ca/2008/12/23/the-inner-workings-of-vbproj-files-projecttypeguids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>S#arp Architecture</title>
		<link>http://annoyed.ca/2008/12/19/sarp-architecture/</link>
		<comments>http://annoyed.ca/2008/12/19/sarp-architecture/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 03:57:18 +0000</pubDate>
		<dc:creator>Christopher Hyne</dc:creator>
				<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Fluent NHibernate]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[Rhino Mocks]]></category>
		<category><![CDATA[S#arp Architecture]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://annoyed.ca/2008/12/19/sarp-architecture/</guid>
		<description><![CDATA[I&#8217;ve been poking around in the latest release of the S#arp Architecture over the last couple days. I like what I see. Pronounced &#8220;Sharp Architecture,&#8221; this is a solid architectural foundation for rapidly building maintainable web applications leveraging the ASP.NET &#8230; <a href="http://annoyed.ca/2008/12/19/sarp-architecture/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been poking around in the latest release of the <a href="http://code.google.com/p/sharp-architecture/" target="_blank">S#arp Architecture</a> over the last couple days. I like what I see.</p>
<blockquote><p>Pronounced &#8220;Sharp Architecture,&#8221; this is a solid architectural foundation for rapidly building maintainable web applications leveraging the ASP.NET MVC framework with NHibernate.</p>
</blockquote>
<p>This evening I took about an hour and converted the basic starter solution template from C# to VB.Net. Why? Well, for the following reasons:</p>
<ol>
<li>While I can work with C# well enough, I&#8217;m much more familiar with VB.Net, which I am required to use at my 9 to 5 job. I tend to stick with VB.Net even for my personal projects for simplicity. Anything I learn on my own I can easily apply at work.</li>
<li>It gave me an opportunity to confirm that I understand (at least at a high level) what the S#arp Architecture is doing.</li>
</ol>
<p>The conversion was straight forward. Pretty well every line of C# had a corresponding line in VB.Net. The only thing I had to add was an Imports tag in the markup of the Site.Master page in order to get the ActionLink and Image extension methods to resolve. I had already tried adding an imports to the code-behind with no luck. Not sure why that was necessary, but it worked.</p>
<p>The architecture is pretty neat. Here&#8217;s a few things I&#8217;ve noted already:</p>
<ul>
<li>The Models, Views and Controllers (I.e. the M, V and C in MVC) are each in their own projects.</li>
<li>The Repository/IRepository pattern is used, with the Interfaces defined in the same project as the Models, and the Repository implementation(s) in a separate project.</li>
<li>Includes support for NUnit, Castle Windsor, (Fluent) NHibernate, and Rhino Mocks</li>
<li>The ASP.Net MVC routes are defined in the Controllers project, not in the Global.asax of the Web/Views project. Excellent separation of concerns!</li>
</ul>
<p>I&#8217;m going to go ahead and trying putting together an actual application based on S#arp Architecture.</p>
]]></content:encoded>
			<wfw:commentRss>http://annoyed.ca/2008/12/19/sarp-architecture/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A Day Spent Refactoring Code</title>
		<link>http://annoyed.ca/2008/10/28/a-day-spent-refactoring-code/</link>
		<comments>http://annoyed.ca/2008/10/28/a-day-spent-refactoring-code/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 01:09:02 +0000</pubDate>
		<dc:creator>Christopher Hyne</dc:creator>
				<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://annoyed.ca/2008/10/28/a-day-spent-refactoring-code/</guid>
		<description><![CDATA[I spent a good part of today refactoring some code I&#8217;ve inherited. It&#8217;s a VB.Net wrapper around some commercial address verification software. Two examples of the type of functionality the software provides are address correction and address formatting. Here is &#8230; <a href="http://annoyed.ca/2008/10/28/a-day-spent-refactoring-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I spent a good part of today refactoring some code I&#8217;ve inherited. It&#8217;s a VB.Net wrapper around some commercial address verification software. Two examples of the type of functionality the software provides are address correction and address formatting. </p>
<p>Here is a simplified version of three of the classes I was given to work with: Address, CorrectedAddress and FormattedAddress. An Address is what you would provide to the verification software and the other two classes would be returned from either the address correction or address formatting functionality.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">Public</span> <span style="color: #0000ff">Class</span> Address
    <span style="color: #0000ff">Public</span> AddressLine <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
    <span style="color: #0000ff">Public</span> City <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
    <span style="color: #0000ff">Public</span> Province <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
    <span style="color: #0000ff">Public</span> PostalCode <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
    <span style="color: #0000ff">Public</span> Country <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
<span style="color: #0000ff">End</span> Class</pre>
</div>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">Public</span> <span style="color: #0000ff">Class</span> CorrectedAddress : <span style="color: #0000ff">Inherits</span> Address
    <span style="color: #0000ff">Public</span> Status <span style="color: #0000ff">As</span> CorrectedAddress.Status
    <span style="color: #0000ff">Public</span> Message <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>

    <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Enum</span> Status
        Valid
        Invalid
        Corrected
        [<span style="color: #0000ff">Error</span>]
    <span style="color: #0000ff">End</span> <span style="color: #0000ff">Enum</span>
<span style="color: #0000ff">End</span> Class</pre>
</div>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">Public</span> <span style="color: #0000ff">Class</span> FormattedAddress
    <span style="color: #0000ff">Public</span> AddressLineOne <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
    <span style="color: #0000ff">Public</span> AddressLineTwo <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
    <span style="color: #0000ff">Public</span> AddressLineThree <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>

    <span style="color: #0000ff">Public</span> Status <span style="color: #0000ff">As</span> FormattedAddress.Status
    <span style="color: #0000ff">Public</span> Message <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>

    <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Enum</span> Status
        Valid
        Invalid
        [<span style="color: #0000ff">Error</span>]
    <span style="color: #0000ff">End</span> <span style="color: #0000ff">Enum</span>
<span style="color: #0000ff">End</span> Class</pre>
</div>
<p>Note that CorrectedAddress inherits from Address, but FormattedAddress does not. Both CorrectedAddress and FormattedAddress have a Status and Message properties (implemented as public fields above only for brevity). The Status properties both return similar, but not identical enumerations. In the actual code there were six classes like these two, but I am focusing only on these two for simplicity.</p>
<p>The whole thing didn&#8217;t seem quite right to me, and I struggled a bit to put my finger on how this should have been implemented. But then it hit me. CorrectedAddress isn&#8217;t really an Address. It&#8217;s a result of an address correction (that happens to have an address). &#8220;Is A&#8221; versus &#8220;Has A&#8221;. Remember the oft quoted Object-Oriented design principle:</p>
<blockquote>
<p>Favour Composition over Inheritance</p>
</blockquote>
<p>So I pulled the Address class out of the inheritance hierarchy, renamed CorrectedAddress and FormattedAddress to CorrectedResult and FormattedResult respectively and even threw in some Generics stuff to deal with the similar but different Status enumerations.</p>
<p>The result (the Address class was left as-is):</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">Public</span> <span style="color: #0000ff">MustInherit</span> <span style="color: #0000ff">Class</span> Result(Of T <span style="color: #0000ff">As</span> <span style="color: #0000ff">Structure</span>)
    <span style="color: #0000ff">Public</span> Status <span style="color: #0000ff">As</span> T
    <span style="color: #0000ff">Public</span> Message <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
<span style="color: #0000ff">End</span> Class</pre>
</div>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">Public</span> <span style="color: #0000ff">Class</span> CorrectedResult : <span style="color: #0000ff">Inherits</span> Result(Of CorrectedResultStatus)
    <span style="color: #0000ff">Public</span> Address <span style="color: #0000ff">As</span> Address

    <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Enum</span> CorrectedResultStatus
        Valid
        Invalid
        Corrected
        [<span style="color: #0000ff">Error</span>]
    <span style="color: #0000ff">End</span> <span style="color: #0000ff">Enum</span>
<span style="color: #0000ff">End</span> Class</pre>
</div>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">Public</span> <span style="color: #0000ff">Class</span> FormattedResult : <span style="color: #0000ff">Inherits</span> Result(Of FormattedResultStatus
    <span style="color: #0000ff">Public</span> AddressLineOne <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
    <span style="color: #0000ff">Public</span> AddressLineTwo <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>
    <span style="color: #0000ff">Public</span> AddressLineThree <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>

    <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Enum</span> FormattedResultStatus
        Valid
        Invalid
        [<span style="color: #0000ff">Error</span>]
    <span style="color: #0000ff">End</span> <span style="color: #0000ff">Enum</span>
<span style="color: #0000ff">End</span> Class</pre>
</div>
<p>Much better!</p>
]]></content:encoded>
			<wfw:commentRss>http://annoyed.ca/2008/10/28/a-day-spent-refactoring-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing Web Services with SSL Client Certificates</title>
		<link>http://annoyed.ca/2006/01/05/securing-web-services-with-ssl-client-certificates/</link>
		<comments>http://annoyed.ca/2006/01/05/securing-web-services-with-ssl-client-certificates/#comments</comments>
		<pubDate>Fri, 06 Jan 2006 00:06:44 +0000</pubDate>
		<dc:creator>Christopher Hyne</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://annoyed.marge.bluephyre.com/?p=14</guid>
		<description><![CDATA[I am posting this in the hopes that other poor souls writing .Net web service proxies to consume web services that require SSL client certificate authentication won&#8217;t waste days trying to figure out why their code isn&#8217;t working like every &#8230; <a href="http://annoyed.ca/2006/01/05/securing-web-services-with-ssl-client-certificates/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am posting this in the hopes that other poor souls writing .Net web service proxies to consume web services that require SSL client certificate authentication won&#8217;t waste days trying to figure out why their code isn&#8217;t working like every single related article on the web says it should.</p>
<p>According to just about every bit of information I could find on the web about using SSL client certificates with web service proxies, the following code should work:</p>
<blockquote class="code"><p>Dim objCertificate As X509Certificate = X509Certificate.CreateFromCertFile(&#8220;C:\MyClientCert.cer&#8221;)<br />
proxy.ClientCertificates.Add(objCertificate)</p></blockquote>
<p>But that didn&#8217;t work for me, at least not out-of-the-box.</p>
<p>A bit more Googling uncovered <a href="http://blogs.msdn.com/kevinha/archive/2005/02/15/373254.aspx" target="_blank">this blog post by Kevin Hammond</a>. The important points in his post were:</p>
<blockquote><p>First, the certificate with the private key must be imported into your personal store.</p></blockquote>
<blockquote><p>When you import your certificate into the certificate store, you are presented with the option to “Enable strong private key protection. &#8230; Unfortuantely, enabling this option causes the .NET Framework to silently fail when accessing the private key of your certificate.</p></blockquote>
<p>While this did not solve my problem (I had already done both of these things), it lead me to learn a bit more about this &#8220;personal store&#8221;. Among the things I learned is that there is a utility called <a href="http://www.microsoft.com/downloads/details.aspx?familyid=c42e27ac-3409-40e9-8667-c748e422833f&amp;displaylang=en" target="_blank">WinHttpCertCfg.exe</a> that can be used to manage the permissions of the certificate stores on your computer. Since my web service proxy was being called from an ASP.Net web page, the ASPNET user had to be given access to the certificate store containing the SSL client certificate.</p>
<p>But my SSL client certificate authentication was still not working. It had taken me the better part of a day to get to this point. What ended up taking me nearly three days to figure out was that there are a number of was to import SSL certificates into a certificate store. But only one way would work for my web service proxy. The break-through came from Matthew.DelVecchio who wrote in <a href="http://groups.google.com/group/microsoft.public.dotnet.framework.webservices/browse_thread/thread/fbe015e52924e58a" target="_blank">this news group post</a>:</p>
<blockquote><p>&#8230; added the Certifcates snap-in for the MMC windows management utility, and using it to delete my certs, re-add the .PFX into the &#8220;Personal&#8221; store, then exporting it to a .CER all w/ the MMC snap-in (and not using Control Panels -&gt; Internet Settings or IE).</p></blockquote>
<p>Hope this information helps someone out there save some time (and a little bit of sanity)!</p>
]]></content:encoded>
			<wfw:commentRss>http://annoyed.ca/2006/01/05/securing-web-services-with-ssl-client-certificates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

