<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Developer's Quest</title>
	<atom:link href="http://developersquest.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://developersquest.wordpress.com</link>
	<description>Sharing Discoveries in Software Development</description>
	<lastBuildDate>Wed, 01 Apr 2009 03:58:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='developersquest.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Developer's Quest</title>
		<link>http://developersquest.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://developersquest.wordpress.com/osd.xml" title="Developer&#039;s Quest" />
	<atom:link rel='hub' href='http://developersquest.wordpress.com/?pushpress=hub'/>
		<item>
		<title>On the Issue of Using Nested Classes in C# for Object-Oriented Design</title>
		<link>http://developersquest.wordpress.com/2009/03/24/on-the-issue-of-using-nested-classes-in-c-for-object-oriented-design/</link>
		<comments>http://developersquest.wordpress.com/2009/03/24/on-the-issue-of-using-nested-classes-in-c-for-object-oriented-design/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 23:19:51 +0000</pubDate>
		<dc:creator>gnhurst</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding Style]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Flyweight]]></category>
		<category><![CDATA[interfaces]]></category>
		<category><![CDATA[Nested Classes]]></category>
		<category><![CDATA[Singleton]]></category>

		<guid isPermaLink="false">http://developersquest.wordpress.com/?p=59</guid>
		<description><![CDATA[...there are definitely valuable use cases for nested classes, but C# programmers are generally not familiar with them yet<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=59&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I first came across the notion of using nested classes back in 2000 when I discovered Ruby. Some years later, I wished for it while writing a forms processing module in PHP. Now that I am using C#, I am glad to be able to use nested classes once again.</p>
<p>However, I have discovered that some developers and architects seriously question the value of such a construct. This actually surprised me, especially after it was noted that one reason to question it is that such a construct is rarely, if ever, seen.</p>
<p>I have not considered this perspective, perhaps because I did see usage of it years ago by others (using Ruby). But now that it has been raised as an issue, I would like to investigate this further.</p>
<p>To begin, I did a search online concerning how many people use it and for what reasons, focusing specifically on its usage in C#.</p>
<p>The first article I came across is at <a title="http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=93" href="http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=93" target="_blank">CSharpFriends</a>. I noted these two points:</p>
<blockquote><p>1. &#8220;<span><span><span class="serif"><span class="txts">At times you need to define a class only to serve [an]other class and there are no other reasons to make it visible.&#8221;</span></span></span></span></p>
<p><span><span><span class="serif"><span class="txts">2. &#8220;Nested classes have the advantage of access to all the members of the outer class. </span></span></span></span><span><span><span class="serif"><span class="txts">&#8220;</span></span></span></span></p></blockquote>
<p>The second article was by <a title="http://staff.develop.com/jasonw/weblog/2003/02/05.html#a151" href="http://staff.develop.com/jasonw/weblog/2003/02/05.html#a151" target="_blank">Jason Whittington</a>, and demonstrated an elegant approach to managing derived classes. He sums up its advantage in this statement:</p>
<blockquote><p>&#8221; The key turns out to be that given a <span style="font-family:Courier,Monospace;">Type</span> object you can enumerate over its <span style="font-family:Courier,Monospace;">NestedTypes</span> collection to see the contained subtypes. You can&#8217;t do this with namespaces, because namespaces can be arbitrarily extended into new assemblies.&#8221;</p></blockquote>
<p>The next article by <a title="http://sjbdeveloper.blogspot.com/2005/07/great-use-for-nested-classes.html" href="http://sjbdeveloper.blogspot.com/2005/07/great-use-for-nested-classes.html" target="_blank">Scott Baldwin</a> describes how he was able to avoid maintaining the same list in two places while working with the Infragistics UltraGrid control.</p>
<blockquote><p>&#8220;This means that I can let the user control maintain the row names and no-one ever needs to know about our RowSelectorDrawFilter class as it&#8217;s happily nested in MyControlClass.&#8221;</p></blockquote>
<p>Yet another article by <a title="http://www.clawbox.com/2006/08/04/c-nested-classes/" href="http://www.clawbox.com/2006/08/04/c-nested-classes/" target="_blank">Christopher Lord</a> provides two reasons for using nested classes.</p>
<blockquote><p>&#8220;Nested classes are usually used for two big reasons. the first is to <strong>hide implementation of interfaces</strong>. &#8230; Additionally, the nested class gains access to private/protected methods and variables in [the outer class, which] leads to the second reason to use nested classes: it allows you to use object-oriented programming to implement your classes, while keeping everything packaged up in a clean interface for your target audience. &#8230; This is keeping with <strong>the principle of “least interface,”</strong> ie, expose as little of your engine as possible. Provide a gas pedal and a steering wheel while keeping details about crankshafts under the hood.&#8221;</p></blockquote>
<p>A more advanced example is given by <a title="http://www.yoda.arachsys.com/csharp/singleton.html" href="http://www.yoda.arachsys.com/csharp/singleton.html" target="_blank">Jon Skeet</a> wherein he compares five implementations of the singleton pattern in C#. The fifth one provided a fully lazy instantiation using nested classes.</p>
<blockquote>
<pre><span class="Modifier">public</span> <span class="Modifier">sealed</span> <span class="ReferenceType">class</span> Singleton
{
    Singleton()
    {
    }

    <span class="Modifier">public</span> <span class="Modifier">static</span> Singleton Instance
    {
        get
        {
            <span class="Statement">return</span> Nested.instance;
        }
    }

    <span class="ReferenceType">class</span> Nested
    {
        <span class="InlineComment">// Explicit static constructor to tell C# compiler</span>
        <span class="InlineComment">// not to mark type as beforefieldinit</span>
        <span class="Modifier">static</span> Nested()
        {
        }

        <span class="Modifier">internal</span> <span class="Modifier">static</span> <span class="Modifier">readonly</span> Singleton instance = <span class="Keyword">new</span> Singleton();
    }
}</pre>
</blockquote>
<blockquote><p>&#8220;This means the implementation is fully       lazy, but has all the performance benefits of the previous ones.&#8221;</p></blockquote>
<p>Interestingly, although he considered it elegant, he also seemed to believe it was a tricky solution.</p>
<blockquote><p>&#8220;Solution 5 is elegant, but trickier than 2 or 4, and as I said above, the benefits it provides       seem to only be rarely useful.&#8221;</p></blockquote>
<p>I also found a pertinent <a title="http://stackoverflow.com/questions/454218/private-inner-classes-in-c-why-arent-they-used-more-often" href="http://stackoverflow.com/questions/454218/private-inner-classes-in-c-why-arent-they-used-more-often" target="_blank">thread on StackOverFlow</a> discussing this same question about using nested classes. Opinions diverged, but it was agreed that it was not commonly used in C# yet. Still, Jon Skeet brought out a nice new pattern he calls the &#8220;better enum&#8221; pattern.</p>
<blockquote>
<pre class="prettyprint"><code><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">MyCleverEnum</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">readonly</span><span class="pln"> </span><span class="typ">MyCleverEnum</span><span class="pln"> </span><span class="typ">First</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">FirstCleverEnum</span><span class="pun">();</span><span class="pln">
    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">readonly</span><span class="pln"> </span><span class="typ">MyCleverEnum</span><span class="pln"> </span><span class="typ">Second</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">SecondCleverEnum</span><span class="pun">();</span><span class="pln">

    </span><span class="com">// Can only be called by this type *and nested types*</span><span class="pln">
    </span><span class="kwd">private</span><span class="pln"> </span><span class="typ">MyCleverEnum</span><span class="pun">()</span><span class="pln">
    </span><span class="pun">{</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">

    </span><span class="kwd">public</span><span class="pln"> abstract </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">SomeMethod</span><span class="pun">();</span><span class="pln">
    </span><span class="kwd">public</span><span class="pln"> abstract </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">AnotherMethod</span><span class="pun">();</span><span class="pln">

    </span><span class="kwd">private</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">FirstCleverEnum</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="typ">MyCleverEnum</span><span class="pln">
    </span><span class="pun">{</span><span class="pln">
        </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">override</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">SomeMethod</span><span class="pun">()</span><span class="pln">
        </span><span class="pun">{</span><span class="pln">
             </span><span class="com">// First-specific behaviour here</span><span class="pln">
        </span><span class="pun">}</span><span class="pln">

        </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">override</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">AnotherMethod</span><span class="pun">()</span><span class="pln">
        </span><span class="pun">{</span><span class="pln">
             </span><span class="com">// First-specific behaviour here</span><span class="pln">
        </span><span class="pun">}</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">

    </span><span class="kwd">private</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">SecondCleverEnum</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="typ">MyCleverEnum</span><span class="pln">
    </span><span class="pun">{</span><span class="pln">
        </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">override</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">SomeMethod</span><span class="pun">()</span><span class="pln">
        </span><span class="pun">{</span><span class="pln">
             </span><span class="com">// Second-specific behaviour here</span><span class="pln">
        </span><span class="pun">}</span><span class="pln">

        </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">override</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">AnotherMethod</span><span class="pun">()</span><span class="pln">
        </span><span class="pun">{</span><span class="pln">
             </span><span class="com">// Second-specific behaviour here</span><span class="pln">
        </span><span class="pun">}</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span></code></pre>
</blockquote>
<p>If you are wondering why I am referencing so many places, it is because some developers have been asking me who uses it; why would anyone use it; what specific, real-life examples demonstrate its use; and, in short, on what basis should it be allowed into the codebase?</p>
<p>But I am not finished.</p>
<p><a title="http://msdn.microsoft.com/en-us/library/s9f3ty7f(VS.71).aspx" href="http://msdn.microsoft.com/en-us/library/s9f3ty7f(VS.71).aspx" target="_blank">Microsoft itself provided some recommendations</a> about nested classes on it MSDN site. This is based on .NET version 1.1, but it probably is still relevant:</p>
<blockquote><p>The use of nested classes in your components is a powerful and convenient way to<strong> supply subordinate objects</strong> that your component might use. Nested classes allow your component to create and use objects <strong>without making them accessible or creatable by external users</strong>. Overuse of nested classes, however, can make your components difficult to work with and maintain. Here are some design recommendations that will help you to use nested classes in your components.</p>
<ul type="disc">
<li>If your class is logically contained by another class, but has <strong>no stand-alone significance</strong>, implement it as a nested class&#8230;</li>
<li>If members of your class <strong>need to access private member variables</strong> of the object containing it, you can implement it as a nested class&#8230;</li>
<li>If a class <strong>needs to implement an interface for interaction</strong> with other components, you can create an implementation of that interface as a nested class and expose an instance of the class as an interface property.</li>
<li>If your component <strong>will need to use one of several different subtypes of a contained object, but the subtype will not be known until run time</strong>, you can implement each subtype as a nested class as opposed to implementing all possible subtypes within a single class. When used with Just-In-Time compilation, nesting classes improves program performance because only the required type is compiled.</li>
<li>If other classes will reasonably need access, or will want to collect or contain your class, do not implement it as a nested class. A class that is accessed by several other classes should stand alone.</li>
<li>In general, do not implement <em>public </em>nested classes. Nested classes <strong>should primarily be for the internal use of the containing class</strong>&#8230;</li>
</ul>
</blockquote>
<p>In addition to the above findings, I came across some books that mention nested classes in particular.</p>
<p>For example, Trey Nash makes some useful comments in his book, <a onclick="return mugicPopWin(this,event);" oncontextmenu="mugicRightClick(this);" href="http://www.amazon.com/gp/product/1590598733?ie=UTF8&amp;tag=devesques-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1590598733">Accelerated C# 2008</a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=devesques-20&amp;l=as2&amp;o=1&amp;a=1590598733" border="0" alt="" width="1" height="1" /> (p.66):</p>
<blockquote><p>&#8220;Nested classes have some special capabilities and lend themselves well to situations where you need a helper class that works on behalf of the containing class.</p>
<p>For example, a container class might maintain a collection of objects. Imagine that you need some facility to iterate over those contained objects and also allow external users who are doing the iteration to maintain a marker, or an iterator of sorts, representing their place during the iteration. This is a common design technique. Preventing the users from holding on to direct references to the contained objects gives you much greater flexibility to change the internal behavior of the container class without breaking code that uses the container class. Nested classes provide a great solution to this problem for several reasons. First, nested classes have access to all the members that are visible to the containing class, even if they&#8217;re private&#8230; &#8220;</p></blockquote>
<p>Here he then gives an example in code, and points out that you can apply the same access modifiers to nested classes as you can to any other member of the class, while non-nested classes can only be declared as either public or internal.</p>
<p>In another book I read, <a onclick="return mugicPopWin(this,event);" oncontextmenu="mugicRightClick(this);" href="http://www.amazon.com/gp/product/0321126971?ie=UTF8&amp;tag=devesques-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321126971">Design Patterns in C# (Software Patterns Series)</a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=devesques-20&amp;l=as2&amp;o=1&amp;a=0321126971" border="0" alt="" width="1" height="1" />, author Steven J. Metsker recommends using nested classes when implementing the Flyweight pattern (pp. 150-153).</p>
<blockquote><p>Extracting the immutable part of an object is half the battle in applying the Flyweight pattern. The remaining work includes creating a flyweight factory&#8230; You also have to ensure that clients will use your factory instead of constructing instances of the flyweight class themselves&#8230;</p>
<p>Access modifiers do not supply the complete control over instantiation that you might want. You might like to ensure that [your factory] is absolutely the only class that can create new instances. To achieve this level of control, you can apply a <em>nested </em>class&#8230;</p></blockquote>
<p>In conclusion, there are definitely valuable use cases for nested classes, but C# programmers are generally not familiar with them yet. Lack of familiarity is no reason to avoid a capability that has been found useful.</p>
<p>I hope this post helps more developers better understand the usefulness and acceptability of C# nested classes.</p>
<br />Posted in C#, Coding Style, Design Patterns Tagged: Flyweight, interfaces, Nested Classes, Singleton <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/developersquest.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/developersquest.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/developersquest.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/developersquest.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/developersquest.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/developersquest.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/developersquest.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/developersquest.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/developersquest.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/developersquest.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/developersquest.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/developersquest.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/developersquest.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/developersquest.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=59&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://developersquest.wordpress.com/2009/03/24/on-the-issue-of-using-nested-classes-in-c-for-object-oriented-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/687b45847768b3b37beb6606103c2a0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gnhurst</media:title>
		</media:content>

		<media:content url="http://www.assoc-amazon.com/e/ir?t=devesques-20&#38;l=as2&#38;o=1&#38;a=1590598733" medium="image" />

		<media:content url="http://www.assoc-amazon.com/e/ir?t=devesques-20&#38;l=as2&#38;o=1&#38;a=0321126971" medium="image" />
	</item>
		<item>
		<title>TidBits about DesignPatterns</title>
		<link>http://developersquest.wordpress.com/2009/03/23/tidbits-about-designpatterns/</link>
		<comments>http://developersquest.wordpress.com/2009/03/23/tidbits-about-designpatterns/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 23:17:09 +0000</pubDate>
		<dc:creator>gnhurst</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Erich Gamma]]></category>
		<category><![CDATA[Gang of Four]]></category>
		<category><![CDATA[GoF]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[object composition]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[reusable code]]></category>

		<guid isPermaLink="false">http://developersquest.wordpress.com/?p=108</guid>
		<description><![CDATA[To add flexibility, you really have to be able to justify it by a requirement.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=108&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been spending some time lately delving into the nature of various design patterns &#8212; in conjunction with a significant refactoring I have been working on. I eventually came across <a title="How to Use Design Patterns" href="http://www.artima.com/lejava/articles/gammadp.html" target="_blank">an article about how to use design patterns</a>, and I decided to share some tidbits I picked up from it.</p>
<p>The article is an interview with Erich Gamma, one of the members of the &#8220;Gang of Four&#8221; (GoF) responsible for the landmark book, <a onclick="return mugicPopWin(this,event);" oncontextmenu="mugicRightClick(this);" href="http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;tag=devesques-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0201633612">Design Patterns: Elements of Reusable Object-Oriented Software</a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=devesques-20&amp;l=as2&amp;o=1&amp;a=0201633612" border="0" alt="" width="1" height="1" /> (Addison-Wesley, 1995).</p>
<p>I would like to summarize some of what Gamma says that I find interesting.</p>
<p>First, regarding what patterns are good for, Gamma says:</p>
<ul>
<li>patterns are good for learning OO and design in general</li>
<li>the GoF patterns help by explaining trade-offs</li>
<li>the fact that patterns are implementable is what makes them so valuable</li>
<li>patterns provide names for design building blocks, which allows you to describe and discuss a particular design</li>
</ul>
<p>Regarding learning patterns, he says:</p>
<ul>
<li>you only appreciate a pattern when it takes away some design pain</li>
<li>just enumerating the patterns is really boring</li>
</ul>
<p>In this regard, Gamma said that <a onclick="return mugicPopWin(this,event);" oncontextmenu="mugicRightClick(this);" href="http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;tag=devesques-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596007124">Head First Design Patterns</a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=devesques-20&amp;l=as2&amp;o=1&amp;a=0596007124" border="0" alt="" width="1" height="1" /> is a great book &#8211; &#8220;not only because it is fun to read but also because they are able to communicate the essence of design patterns in a novel and highly visual way&#8221;.</p>
<p>Regarding the use of patterns, he says:</p>
<ul>
<li>do not start immediately throwing patterns into a design</li>
<li>wait until you understand more of the problem, then refactor to patterns</li>
<li>use patterns after encountering a design pain</li>
</ul>
<p>He then points out that the GoF book describes a <strong>library of patterns</strong> (as building blocks), as opposed to Christopher Alexander&#8217;s landmark book, which describes a <strong>pattern language</strong>.</p>
<p>In <a title="http://www.artima.com/lejava/articles/reuseP.html" href="http://www.artima.com/lejava/articles/reuseP.html" target="_blank">part 2 of the interview</a>, the focus is on reusability.</p>
<ul>
<li>it&#8217;s hard to create highly reusable frameworks</li>
<li>it is crucial to have well-defined APIs</li>
<li>Plug-ins provide reusable code following explicit conventions to separate the API from  internal code</li>
<li>you are not done until you have also thought about the  extension points your plug-in might offer</li>
<li>Patterns  allow you to reuse design ideas and concepts independent of concrete code</li>
</ul>
<p>Interestingly, a point regarding thinking ahead brings Gamma to admit he&#8217;s changed his perspective. The GoF book says, &#8220;The key to maximizing reuse lies in  anticipating new requirements and changes to existing requirements, and in designing your  systems so they can evolve accordingly&#8230;&#8221;  Interviewer Bill Venners noted that this contradicts the XP philosophy. Gamma confides, &#8220;I probably wouldn&#8217;t  write this exactly this way anymore. To add flexibility, you really have to be able to  justify it by a requirement.&#8221;</p>
<p>In <a title="http://www.artima.com/lejava/articles/designprinciplesP.html" href="http://www.artima.com/lejava/articles/designprinciplesP.html" target="_blank">part 3 of the interview</a>, focus was placed on a couple of design principles.</p>
<p>The first was &#8220;program to an interface, not an implementation&#8221;.</p>
<ul>
<li>dependency relationships have to be carefully managed in a large application</li>
<li>depending on an interface is often beneficial because you&#8217;re decoupled from varying implementations</li>
</ul>
<p>Caution is advised here. One should weigh use of interfaces with abstract classes.</p>
<ul>
<li>Since changing interfaces breaks clients you should consider them as immutable once  you&#8217;ve published them</li>
<li>Alternatively, an abstract class gives you the freedom to add new methods later</li>
<li>writing against a type far up in the hierarchy is consistent with the  programming to an interface principle</li>
</ul>
<p>The second was &#8220;favor object composition over class inheritance&#8221;.</p>
<ul>
<li>you should favor composition because plugging in a behavior is  simpler and results in reduced   coupling</li>
<li>increased flexibility comes from ability to use different strategy objects that can change at run-time</li>
<li>inheritance results in tight coupling between the base class and the subclass, due to the implicit context in which the subclass code will be called</li>
<li>composition does use inheritance, but typically in the form of implementing a small interface and not from extending a big class</li>
</ul>
<p>In <a title="http://www.artima.com/lejava/articles/patterns_practiceP.html" href="http://www.artima.com/lejava/articles/patterns_practiceP.html" target="_blank">part 4 of the series</a>, the focus was on patterns and practice.</p>
<ul>
<li>patterns have both a problem <em>and </em>a  solution, and you need to see both</li>
<li>if you just  look at the solution part, it isn&#8217;t that enlightening and all patterns start to look  the same</li>
<li>patterns have both positive effects and associated liabilities</li>
<li>One of the key values of a pattern is that it captures trade-offs so  that you don&#8217;t have to do the analysis again.</li>
</ul>
<p>On the importance of practice:</p>
<ul>
<li>in the book we only tell when to apply a pattern, but removing a pattern can simplify a system</li>
<li>you cannot learn patterns just from reading a book</li>
<li>You become a master by mimicking the  work of excellent developers</li>
</ul>
<p>There was another segment, but it focused on a particular tool, so I will disregard it here.</p>
<p>Overall, I found this series insightful, particularly since it incorporates a self-assessment by an original author of such an influential work as the Gang of Four book. It highlights the points he considers salient, as well as some aspects he considers superceded by lessons learned after ten years of additional experience.</p>
<br />Posted in Design Patterns Tagged: Design Patterns, Erich Gamma, Gang of Four, GoF, interface, object composition, OO, reusable code <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/developersquest.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/developersquest.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/developersquest.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/developersquest.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/developersquest.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/developersquest.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/developersquest.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/developersquest.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/developersquest.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/developersquest.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/developersquest.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/developersquest.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/developersquest.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/developersquest.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=108&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://developersquest.wordpress.com/2009/03/23/tidbits-about-designpatterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/687b45847768b3b37beb6606103c2a0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gnhurst</media:title>
		</media:content>

		<media:content url="http://www.assoc-amazon.com/e/ir?t=devesques-20&#38;l=as2&#38;o=1&#38;a=0201633612" medium="image" />

		<media:content url="http://www.assoc-amazon.com/e/ir?t=devesques-20&#38;l=as2&#38;o=1&#38;a=0596007124" medium="image" />
	</item>
		<item>
		<title>Generating C# classes from DDMS version 2.0 XSD files</title>
		<link>http://developersquest.wordpress.com/2009/02/18/generating-c-classes-from-ddms-version-20-xsd-files/</link>
		<comments>http://developersquest.wordpress.com/2009/02/18/generating-c-classes-from-ddms-version-20-xsd-files/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 19:19:45 +0000</pubDate>
		<dc:creator>gnhurst</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DoD Metadata Registry]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[XSD]]></category>
		<category><![CDATA[DDMS]]></category>
		<category><![CDATA[svcutil.exe]]></category>
		<category><![CDATA[xsd.exe]]></category>

		<guid isPermaLink="false">http://developersquest.wordpress.com/?p=110</guid>
		<description><![CDATA[In spite of experiencing some shortcomings in both the operation and documentation of the svcutil.exe and xsd.exe tools, it is possible to generate WCF data contract classes for DDMS v2.0. <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=110&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We already have a system making use of DDMS version 1.4, but the task at hand is to see what it will take to upgrade it to make use of DDMS version 2.0, which was released in July 2008.</p>
<h4>Attempts with SVCUTIL.EXE</h4>
<p>We are using WCF, so my first thought is to use svcutil.exe to generate just the data contract. This utility gives the option to refer to local files or remote files, but past experience tells me to just download the XML Schema files and run it locally.</p>
<p>The files are available from http://metadata.dod.mil/mdr/irs/DDMS/ and include some different dependencies than the previous version. For example, XLink is now used, and the ICISM has been updated, among other things. I extract the relevant files to a working directory.</p>
<p>The main file is DDMS-v2_0.xsd, so I run svcutil against that one. I need to use the /dconly option to generate just the data contracts. Unfortunately, this results in an error.</p>
<blockquote><p>Error: Type &#8216;ResourceType&#8217; in namespace &#8216;http://metadata.dod.mil/mdr/ns/DDMS/2.0/&#8217; cannot be imported. &#8216;maxOccurs&#8217; on element &#8221; must be 1. Either change the schema so that the types can map to data contract types or use ImportXmlType or use a different serializer.</p>
<p>If you are using the /dataContractOnly option to import data contract types and are getting this error message, consider using xsd.exe instead. Types generated by xsd.exe may be used in the Windows Communication Foundation after applying the XmlSerializerFormatAttribute attribute on your service contract. Alternatively, consider using the /importXmlTypes option to import these types as XML types to use with DataContractFormatAttribute attribute on your service contract.</p></blockquote>
<p>I googled for &#8220;svcutil error type in namespace cannot be imported&#8221; and came across <a title="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c837d0aa-603e-48a9-b3ac-af74b1847ce2/" href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c837d0aa-603e-48a9-b3ac-af74b1847ce2/" target="_blank">someone asking about a similar issue</a>. The moderator, <span class="postedBy">Eugene Osovetsky</span>, pointed out the following:</p>
<blockquote><p>The Data Contract Serializer only supports a very specific subset of XML schema. In particular, as you have discovered, it does not support abstract types or attributes (except for some very special attributes from one special namespace).</p>
<p>You have two options: either fix the schema to follow the Data Contract rules, or use a different serialization engine (the XmlSerializer). As the error message tells you, &#8220;if you are using the /dconly option &#8230; consider using xsd.exe instead&#8221;. The xsd.exe tool (included as part of the .NET Framework 2.0 SDK) will generate valid XmlSerializer-compatible classes that you will be able to use in WCF by applying the [XmlSerializerFormat] attribute to your service contract.</p>
<p>I agree that it would seem intuitive for &#8220;/useXmlSerializer&#8221; to work in your case. Unfortunately, in v1 of WCF, the &#8220;/useXmlSerializer&#8221; option will only work when importing WSDL and will not work when importing XSD. We may add this in a future version (/uxs with /dconly will automatically do what xsd.exe does).</p></blockquote>
<p>Ok, so this means first try /importXmlTypes with svcutil, then try using xsd.exe.</p>
<p>Using &#8220;svcutil /dconly /importXmlTypes DDMS-v2_0.xsd&#8221; resulted in tons of validation errors.</p>
<blockquote><p>Error: There was a validation error in the schemas provided for code generation:<br />
Source:<br />
Line: 88 Column: 5<br />
Validation Error: The &#8216;http://metadata.dod.mil/mdr/ns/DDMS/2.0/:identifier&#8217; element is not declared.</p>
<p>Error: There was a validation error in the schemas provided for code generation:<br />
Source:<br />
Line: 89 Column: 5<br />
Validation Error: The &#8216;http://metadata.dod.mil/mdr/ns/DDMS/2.0/:title&#8217; element is not declared.<br />
:</p>
<p>:</p></blockquote>
<p>I reviewed the help for svcutil, and noticed that it accepts standard wildcards for the file path. It also accepts multiple, separately listed files.</p>
<p>Using &#8220;svcutil /dconly /importXmlTypes *.xsd&#8221; generated the data contract types without errors. However, when I tried using the resulting classes, I discovered that they were quite superficial and made extensive use of XmlNode arrays. I couldn&#8217;t use Intellisense to access nested properties in a meaningful way. I would have to manually iterate and check types, then downcast to make use of them.</p>
<p>Obviously, svcutil is limited in its ability to generate data contracts from XML Schema files. Time to try xsd.exe.</p>
<h4>Attempts with XSD.EXE</h4>
<p>Using the same working directory, I run xsd.exe against the main file, specifying the option to generate classes: &#8220;xsd.exe /c DDMS-v2_0.xsd&#8221;. This resulted in numerous erros regarding undeclared attribute groups.</p>
<blockquote><p>Schema validation warning: Reference to undeclared attribute group &#8216;urn:us:gov:ic:ism:v2:SecurityAttributesOptionGroup&#8217;.<br />
Line 61, position 4.<br />
Schema validation warning: Reference to undeclared attribute group &#8216;urn:us:gov:ic:ism:v2:SecurityAttributesOptionGroup&#8217;.<br />
Line 83, position 4.</p>
<p>:</p></blockquote>
<p>As it turns out, the import tags were not taking effect. I did some googling on this and discovered that others had the same problem. The solution is to include the needed imports on the command line. This required 4 files for DDMS.</p>
<p>The resulting command is:</p>
<blockquote><p>xsd.exe /c DDMS-v2_0.xsd IC-ISM-v2.1.xsd DDMS-GML-Profile.xsd DDMS-XLink-Profile.xsd</p></blockquote>
<p>I checked out the ResourceType, and it had a nice outlay of the various types.</p>
<blockquote><p>public partial class ResourceType {</p>
<p>private CompoundResourceIdentifierType[] identifierField;</p>
<p>private TitleType[] titleField;</p>
<p>private SubtitleType[] subtitleField;</p>
<p>private DescriptionType descriptionField;</p>
<p>private CompoundLanguageIdentifierType[] languageField;<br />
:</p>
<p>:</p></blockquote>
<p>I made some tweaks regarding the output filename and namespace, then incorporated it into the code for testing.</p>
<p>Everything compiled, but I encountered a runtime error: &#8220;There was an error reflecting &#8216;Notify&#8217;.&#8221;</p>
<p>I enabled CLR exception reporting, and caught the problem. The exception contained more than 20 levels of nested inner exceptions! It follows the Notify to NotificationMessage to ResourceType to GeospatialCoverageType all the way down to DirectPositionType and its &#8220;text&#8221; property.</p>
<blockquote><p>Member &#8216;Text&#8217; cannot be encoded using the XmlText attribute. You may use the XmlText attribute to encode primitives, enumerations, arrays of strings, or arrays of XmlNode.</p></blockquote>
<p>The interesting thing is that xsd.exe generated a double[] for this property while also annotating it with an XmlText attribute, thus breaking some rule in the process.</p>
<blockquote><p><span style="text-decoration:line-through;">[System.Xml.Serialization.XmlTextAttribute()]</span><br />
public double[] Text {<br />
get {<br />
return this.textField;<br />
}<br />
set {<br />
this.textField = value;<br />
}<br />
}</p></blockquote>
<p>We decided to just comment out the XmlText attribute, and everything then ran smoothly and passed our tests.</p>
<h4>Conclusion</h4>
<p>In spite of experiencing some shortcomings in both the operation and documentation of the svcutil.exe and xsd.exe tools, it is possible to generate WCF data contract classes for <a title="http://metadata.dod.mil/mdr/ns/DDMS/2.0/" href="http://metadata.dod.mil/mdr/ns/DDMS/2.0/" target="_blank">DDMS v2.0</a>.</p>
<br />Posted in .NET Framework, C#, DoD Metadata Registry, WCF, XSD Tagged: C#, DDMS, svcutil.exe, WCF, XSD, xsd.exe <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/developersquest.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/developersquest.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/developersquest.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/developersquest.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/developersquest.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/developersquest.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/developersquest.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/developersquest.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/developersquest.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/developersquest.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/developersquest.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/developersquest.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/developersquest.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/developersquest.wordpress.com/110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=110&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://developersquest.wordpress.com/2009/02/18/generating-c-classes-from-ddms-version-20-xsd-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/687b45847768b3b37beb6606103c2a0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gnhurst</media:title>
		</media:content>
	</item>
		<item>
		<title>Stop Visual Studio from Applying Ctrl-C to Blank Lines</title>
		<link>http://developersquest.wordpress.com/2009/01/27/stop-visual-studio-from-applying-ctrl-c-to-blank-lines/</link>
		<comments>http://developersquest.wordpress.com/2009/01/27/stop-visual-studio-from-applying-ctrl-c-to-blank-lines/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 21:37:15 +0000</pubDate>
		<dc:creator>gnhurst</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://developersquest.wordpress.com/?p=73</guid>
		<description><![CDATA[I currently subscribe to the Safari Online Library, and today I decided to check out an interesting new book, Microsoft® Visual Studio® Tips. I just checked out the very first tip, and was amazed because it resolved an annoyance that I have had only too often. I asked a fellow developer whether he ever runs [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=73&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I currently subscribe to the Safari Online Library, and today I decided to check out an interesting new book, <span class="b"><strong>Microsoft® Visual Studio® Tips</strong>.</span><a onclick="return mugicPopWin(this,event);" oncontextmenu="mugicRightClick(this);" href="http://www.amazon.com/gp/product/0735626405?ie=UTF8&amp;tag=devesques-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0735626405"></a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=devesques-20&amp;l=as2&amp;o=1&amp;a=0735626405" border="0" alt="" width="1" height="1" /></p>
<p>I just checked out the very first tip, and was amazed because it resolved an annoyance that I have had only too often. I asked a fellow developer whether he ever runs into such a problem, and he said it just happened to him yesterday. When I told him this tip, he thought it was awesome, and suggested that every developer in the company be notified. He also questioned why such a setting was the default in Visual Studio to begin. I asked another developer who sits next to me the same thing, and he responded with the same disbelief. I myself wonder the same thing.</p>
<p>So what is this annoyance and its resolution?</p>
<p>I often use the keyboard shortcuts to cut or copy some lines of code using [Ctrl]-[X] or [Ctrl]-[C], and then [Ctrl-V] to paste them elsewhere. But somehow, it occasionally happens that when I put the cursor on the blank line where they should be pasted, instead of pasting with [Ctrl]-[V], I accidentally hit [Ctrl]-[C] again. This can easily happen since the [C] and [V] are right next to each other on the keyboard. Anyway, once I realize nothing was pasted, I realized my mistake, and then correct my action by following up with the correct [Ctrl]-[V] combination. However, my lines of code are not pasted even then, because the previous [Ctrl]-[C] <strong>copied the blank line</strong>. This results in the annoyance that the buffered lines I meant to paste have been lost and replaced with the blank line I did not mean to copy.</p>
<p>The cause of this turns out to be that Visual Studio by default copies a blank line if nothing is selected. If Microsoft is reading this, then please note that this is an annoyance. I would like the default to be the opposite. And I am not the only one. My fellow developer expects it that way also. Finally, the very fact it has to be in a book  is an indication that a lot of others are annoyed by the current default as well. So please change it.</p>
<p>Here is the fix.</p>
<p>In Visual Studio 2008, go to Tools &gt; Options as shown.</p>
<div id="attachment_74" class="wp-caption aligncenter" style="width: 285px"><img class="size-full wp-image-74" title="tools-menu_vs2008_select-options" src="http://developersquest.files.wordpress.com/2009/01/tools-menu_vs2008_select-options.png?w=275&#038;h=574" alt="Visual Studio Tools Menu - Select Options" width="275" height="574" /><p class="wp-caption-text">Visual Studio Tools Menu - Select Options</p></div>
<p>This will bring up the Options Dialog. Go to the Text Editor &gt; All Languages &gt; General pane. There will be an option with a check box titled &#8220;Apply Cut or Copy commands to blank lines when there is no selection&#8221;. It is checked by default.</p>
<div id="attachment_75" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-75" title="options_vs2008_copy-blank-lines" src="http://developersquest.files.wordpress.com/2009/01/options_vs2008_copy-blank-lines.png?w=450&#038;h=262" alt="Copy Blank Lines" width="450" height="262" /><p class="wp-caption-text">Visual Studio Options Dialog - Text Editor: Copy Blank Lines</p></div>
<p>Uncheck this checkbox.</p>
<div id="attachment_103" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-103" title="vs2008-options_dialog-checkbox_apply-cut-or-copy-to-blank-lines" src="http://developersquest.files.wordpress.com/2009/01/vs2008-options_dialog-checkbox_apply-cut-or-copy-to-blank-lines.png?w=450&#038;h=154" alt="Apply Cut or Copy commands to Blank Lines" width="450" height="154" /><p class="wp-caption-text">Visual Studio 2008 Options Dialog Checkbox: Apply Cut or Copy commands to Blank Lines</p></div>
<p>Now when you accidentally use [Ctrl-C] instead of [Ctrl-V], you won&#8217;t lose your buffered lines, and can correct your mistake without having to go find and re-copy (or restore and re-cut) those lines again.</p>
<p>Again, thanks to the author Sara Ford and her book <a onclick="return mugicPopWin(this,event);" oncontextmenu="mugicRightClick(this);" href="http://www.amazon.com/gp/product/0735626405?ie=UTF8&amp;tag=devesques-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0735626405">Microsoft Visual Studio Tips</a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=devesques-20&amp;l=as2&amp;o=1&amp;a=0735626405" border="0" alt="" width="1" height="1" />. I look forward to learning more tips from the rest of her book.</p>
<p><em>Disclosure</em>: Purchasing this book through the link in this post will provide a commission to the owner of <strong>Developer&#8217;s Quest</strong>. Thank you for your support.</p>
<br />Posted in Tips and Tricks, Visual Studio 2008 Tagged: Tips, Visual Studio <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/developersquest.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/developersquest.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/developersquest.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/developersquest.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/developersquest.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/developersquest.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/developersquest.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/developersquest.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/developersquest.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/developersquest.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/developersquest.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/developersquest.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/developersquest.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/developersquest.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=73&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://developersquest.wordpress.com/2009/01/27/stop-visual-studio-from-applying-ctrl-c-to-blank-lines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/687b45847768b3b37beb6606103c2a0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gnhurst</media:title>
		</media:content>

		<media:content url="http://www.assoc-amazon.com/e/ir?t=devesques-20&#38;l=as2&#38;o=1&#38;a=0735626405" medium="image" />

		<media:content url="http://developersquest.files.wordpress.com/2009/01/tools-menu_vs2008_select-options.png" medium="image">
			<media:title type="html">tools-menu_vs2008_select-options</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/options_vs2008_copy-blank-lines.png" medium="image">
			<media:title type="html">options_vs2008_copy-blank-lines</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/vs2008-options_dialog-checkbox_apply-cut-or-copy-to-blank-lines.png" medium="image">
			<media:title type="html">vs2008-options_dialog-checkbox_apply-cut-or-copy-to-blank-lines</media:title>
		</media:content>

		<media:content url="http://www.assoc-amazon.com/e/ir?t=devesques-20&#38;l=as2&#38;o=1&#38;a=0735626405" medium="image" />
	</item>
		<item>
		<title>My Endeavor to Create a Test Client to a Secure Remote Web Service. (Part 1)</title>
		<link>http://developersquest.wordpress.com/2009/01/23/my-endeavor-to-create-a-test-client-to-a-secure-remote-web-service-part-1/</link>
		<comments>http://developersquest.wordpress.com/2009/01/23/my-endeavor-to-create-a-test-client-to-a-secure-remote-web-service-part-1/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 23:19:36 +0000</pubDate>
		<dc:creator>gnhurst</dc:creator>
				<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[Add Service Reference]]></category>
		<category><![CDATA[Add Web Reference]]></category>
		<category><![CDATA[Apache Axis]]></category>
		<category><![CDATA[secure channel]]></category>
		<category><![CDATA[Smart Card Reader]]></category>
		<category><![CDATA[SOAP 1.1]]></category>
		<category><![CDATA[SOAP 1.2]]></category>
		<category><![CDATA[SOAPAction header]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[SSL/TLS]]></category>
		<category><![CDATA[trust relationship]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[WSDL]]></category>

		<guid isPermaLink="false">http://developersquest.wordpress.com/?p=11</guid>
		<description><![CDATA[We have a situation where we need to somehow integrate our existing messaging system with another vendor&#8217;s messaging system. They have implemented some web services intended for their own users, and we are thinking of setting up some proxy services so our users can transparently benefit from both messaging services. There is very little documentation [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=11&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We have a situation where we need to somehow integrate our existing messaging system with another vendor&#8217;s messaging system. They have implemented some web services intended for their own users, and we are thinking of setting up some proxy services so our users can transparently benefit from both messaging services.</p>
<p>There is very little documentation or experience with the other vendor&#8217;s system, so the first task was to see if we could even connect to their service. We obtained some URL&#8217;s to their services, and I set out to create a client to make the connection.</p>
<h3>Attempting to Add a Service Reference from Visual Studio 2008</h3>
<p>My development environment is Visual Studio 2008 SP1 on Windows XP. Since this is just a test application, I decided to make it simple and create a console application project to serve as the client.</p>
<p>The typical approach to connecting to a remote service is to start by adding a reference to it from within Visual Studio. This option is in the right-click menu of the project:</p>
<div id="attachment_22" class="wp-caption aligncenter" style="width: 312px"><img class="size-full wp-image-22" title="add-service-reference_menu-selection" src="http://developersquest.files.wordpress.com/2009/01/add-service-reference_menu-selection.png?w=302&#038;h=283" alt="Menu Selection for Add Service Reference" width="302" height="283" /><p class="wp-caption-text">Menu Selection for Add Service Reference</p></div>
<p>Note that we would not use the &#8220;Add Reference&#8221; option in this case, since we need to reference a URL. Now, I didn&#8217;t think of it before, but notice that there is no menu item for &#8220;Add Web Reference&#8221;. Why is that? Perhaps because we are not working in a web site project? I will have to investigate this some other time. Either way, adding a URL-based reference has the effect of enabling you to use objects and methods in your code that map to the services and operations available via the URL. Meanwhile, we will have to use the &#8220;Add Service Reference&#8221; option.</p>
<p>Selecting this menu item brings up the Add Service Reference dialog.</p>
<p><img class="aligncenter size-full wp-image-19" title="add-service-reference_dialog" src="http://developersquest.files.wordpress.com/2009/01/add-service-reference_dialog.png?w=450&#038;h=366" alt="add-service-reference_dialog" width="450" height="366" /></p>
<p>I entered the URL, which uses the SSL-based <strong>https </strong>scheme. Note that, for this post, I will be blocking any identifying information pertaining to the remote site.</p>
<div id="attachment_86" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-86" title="add-service-reference_dialog_https-address" src="http://developersquest.files.wordpress.com/2009/01/add-service-reference_dialog_https-address.png?w=450&#038;h=128" alt="Add Service Reference Dialog - HTTPS Address" width="450" height="128" /><p class="wp-caption-text">Add Service Reference Dialog - HTTPS Address</p></div>
<p>When I clicked Go, the remote server triggered an authentication dialog on my end. I was not expecting this&#8230;</p>
<h4>Trying to Get By on Minimal Security</h4>
<p>I have a smart-card reader, and it seemed this would only be triggered if the remote site was doing mutual authentication and wanted my certificate.</p>
<div id="attachment_36" class="wp-caption aligncenter" style="width: 382px"><img class="size-full wp-image-36" title="insert-smart-card_dialog" src="http://developersquest.files.wordpress.com/2009/01/insert-smart-card_dialog.png?w=372&#038;h=139" alt="Dialog to Insert Smart Card" width="372" height="139" /><p class="wp-caption-text">Dialog to Insert Smart Card</p></div>
<p>I canceled, but it kept popping up. Finally, after clicking Cancel four times, it stopped popping up.</p>
<p>Then I faced a new dialog. This was a Security Alert indicating that the remote site was using a self-signed certificate that was not trusted on my side.</p>
<div id="attachment_26" class="wp-caption aligncenter" style="width: 450px"><img class="size-full wp-image-26" title="security-alert_dialog" src="http://developersquest.files.wordpress.com/2009/01/security-alert_dialog.png?w=440&#038;h=346" alt="Security Alert Dialog" width="440" height="346" /><p class="wp-caption-text">Security Alert Dialog</p></div>
<p>I decided not to trust the remote site at first. I was returned to the Add Service Reference dialog, and it now reported an error:</p>
<blockquote><p>&#8220;An error (Details) occurred while attempting to find services&#8221;</p></blockquote>
<div id="attachment_21" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-21" title="add-service-reference_dialog_error-declining-cert" src="http://developersquest.files.wordpress.com/2009/01/add-service-reference_dialog_error-declining-cert.png?w=450&#038;h=366" alt="Add Service Reference Dialog - Error after declining to trust remote certificate" width="450" height="366" /><p class="wp-caption-text">Add Service Reference Dialog - Error after declining to trust remote certificate</p></div>
<p>I clicked on the (Details) link, and it brought up a dialog explaining that it</p>
<blockquote><p>&#8220;Could not create SSL/TLS secure channel&#8221;</p></blockquote>
<p>because it</p>
<blockquote><p>&#8220;Could not establish trust relationship for the SSL/TLS secure channel.<br />
The remote certificate is invalid according to the validation procedure.&#8221;</p></blockquote>
<div id="attachment_24" class="wp-caption aligncenter" style="width: 397px"><img class="size-full wp-image-24" title="add-service-reference-error_dialog_invalid-cert" src="http://developersquest.files.wordpress.com/2009/01/add-service-reference-error_dialog_invalid-cert.png?w=387&#038;h=298" alt="Add Service Reference Error Dialog - Invalid Certificate" width="387" height="298" /><p class="wp-caption-text">Add Service Reference Error Dialog - Invalid Certificate</p></div>
<p>Ok, so I decided to retry and accept their certificate. I clicked Go again, bypassed the smart card prompts, and clicked Yes in the Security Alert dialog to accept it. But I still found an error reported in the Add Service Reference dialog as before:</p>
<blockquote><p>&#8220;An error (Details) occurred while attempting to find services&#8221;.</p></blockquote>
<p>I clicked on the (Details) link again, to see if it was any different. It was longer this time.</p>
<div id="attachment_28" class="wp-caption aligncenter" style="width: 397px"><img class="size-full wp-image-28" title="add-service-reference-error_dialog_accepting-cert" src="http://developersquest.files.wordpress.com/2009/01/add-service-reference-error_dialog_accepting-cert1.png?w=387&#038;h=533" alt="Add Service Reference Error Dialog" width="387" height="533" /><p class="wp-caption-text">Add Service Reference Error Dialog</p></div>
<p>As you can see in the screenshot, it was still complaining that it &#8220;Could not create SSL/TLS secure channel&#8221;. However, now that I accepted the untrusted cert, different reasons for that failure are given. Note that none of them are for not providing a certificate via the smartcard reader, so I am not yet convinced that mutual authentication is required. Meanwhile, what are these errors?</p>
<h4>Discovering that the Remote Service Requires SOAP 1.1</h4>
<p>First, the content type of the response does not match that of the binding. But why are they different? Why didn&#8217;t the built-in feature provided by VS2008 figure out the correct binding?</p>
<p>I&#8217;m not sure what my options are now, but I noted that there was an &#8220;Advanced&#8221; button on the Add Service Reference Dialog. might let me do. But first I wanted to find out the possible cause of the errors in the rest of the response&#8230;</p>
<p>Along with the complaint of the mismatch, the error dialog displayed what it received from the remote host. (It is interesting that in spite of not being able to establish a secure channel, the server still returned a legible response). Inside this content, the remote host itself reported an error in what it received:</p>
<blockquote><p>&#8220;no SOAPAction header!&#8221;.</p></blockquote>
<p>That struck me as odd, since I seemed to recall that the SOAPAction header is only required for SOAP 1.1. In fact, looking at the XML, I can tell it is the older version of SOAP, because the new version (SOAP 1.2) no longer uses &#8220;<strong>faultcode</strong>&#8221; and &#8220;<strong>faultstring</strong>&#8220;. Plus, the namespace for this SOAP envelope is &#8220;<strong>http://schemas.xmlsoap.org/soap/envelope/</strong>&#8220;. I pulled that URL up in a browser to see if it actually resolved to anything, and it pulled up an XSD file. The first thing it says in the comments is:</p>
<blockquote><p>&#8220;Schema for the SOAP/1.1 envelope&#8221;.</p></blockquote>
<p>This is clearly a SOAP 1.1 response, and it contains an error complaining that it did not receive a SOAP 1.1 request. (By the way, here is an excellent article discussing SOAP 1.2 and how it differs from SOAP 1.1: <a title="SOAP 1.2 by Rich Salz" href="http://www.xml.com/pub/a/ws/2003/06/10/salz.html" target="_blank">http://www.xml.com/pub/a/ws/2003/06/10/salz.html</a> &#8211; and an authoritative list of changes is here: <a title="Changes between SOAP 1.1 and SOAP 1.2" href="http://www.w3.org/TR/2007/REC-soap12-part0-20070427/#L4697" target="_blank">http://www.w3.org/TR/2007/REC-soap12-part0-20070427/#L4697</a>)</p>
<p>Interestingly, its faultcode uses a namespace of &#8220;http://xml.apache.org/axis&#8221;. I pulled that up in a browser and it redirected to &#8220;http://ws.apache.org/axis/&#8221;. It seems outdated, because the most recent news item at the top of the page is</p>
<blockquote><p>&#8220;NEWS (April 22, 2006): Axis 1.4 Final is now available!&#8221;.</p></blockquote>
<p>Hmm. Ok, so <em>Axis is only accepting requests using SOAP 1.1 and sending me responses using SOAP 1.1</em>. I wonder if it is even capable of using SOAP 1.2? Well, I don&#8217;t know Axis, but after scouring the Axis site, I came across <a title="Apache Axis Requirements" href="http://ws.apache.org/axis/java/requirements.html" target="_blank">http://ws.apache.org/axis/java/requirements.html</a>, and found the following part way down:</p>
<blockquote><p>100      SOAP 1.1           done<br />
101      SOAP 1.2           Partial &#8211; doesn&#8217;t yet do envelope versioning or namespaces</p></blockquote>
<p>In other words, <em>I probably can&#8217;t expect this vendor to support SOAP 1.2 fully with Axis 1.4</em>. But I also discovered that there is a rewrite of Axis called Axis2, and that it does in fact support both SOAP 1.1 and 1.2. One option is to see if they will upgrade. After all, it looks like Axis is no longer being updated, and Axis2 has taken its place. (Interestingly, the current version is Axis2 v1.4! This could be a source of confusion&#8230;).</p>
<p>Ok, so I am now facing the prospect of having to use SOAP 1.1 to connect with the remote service. However, I was merely using some built-in feature of VS2008. Why did it not detect the remote service using SOAP 1.1 and comply?</p>
<p>Now a new question on my mind is whether &#8220;Add Service Reference&#8221; is even capable of SOAP 1.1? If not, I will have to generate proxy classes via the commandline.</p>
<h4>Discovering that Add Service Reference is only for WCF</h4>
<p>After some searching, I have come to a tentative answer. According to <a title="Add Service Reference Dialog" href="http://msdn.microsoft.com/en-us/library/bb386382.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/bb386382.aspx</a>,</p>
<blockquote><p>&#8220;The Add Service Reference dialog box enables you to add references to Windows Communication Foundation (WCF) services and ADO.NET Data Services.&#8221;</p></blockquote>
<p>Notice no mention is made of other technologies. But then, no exclusive claim is made regarding WCF, either. So for all I know, it might be some form of marketing spin where they just aren&#8217;t mentioning the competition.</p>
<p>Looking further, there is a link near the bottom for &#8220;How to: Add, Update, or Remove a Service Reference&#8221; linked to <a title="Add, Update, or Remove a Service Reference" href="http://msdn.microsoft.com/en-us/library/bb628652.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/bb628652.aspx</a>, and it states clearly on that page:</p>
<blockquote><p>&#8220;A service reference enables a project to access one or more Windows Communication Foundation (WCF) services. <em>Use the <strong>Add Service Reference</strong> dialog box to search for </em><em><strong>WCF services</strong> in the current solution, locally, on a local area network, or on the Internet.</em>&#8220;</p></blockquote>
<p>Could it really be that it is for Microsoft-specific technologies? Why? For some reason, I had been thinking it was for any web services accessible by additional protocol schemes other than ones such as HTTP. After all, services can serve SOAP over other transport protocols.</p>
<p>I pretty much exhausted my options here. But wait, that web page also indicates that the Advanced button &#8220;Displays the Configure Service Reference Dialog Box&#8221;.</p>
<p>Seems like now is a good time to revisit this button to see what it lets me do. Here is a screenshot showing where this button is, exactly.</p>
<div id="attachment_20" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-20" title="add-service-reference_dialog_advanced" src="http://developersquest.files.wordpress.com/2009/01/add-service-reference_dialog_advanced.png?w=450&#038;h=366" alt="Add Service Reference Dialog - Advanced Button" width="450" height="366" /><p class="wp-caption-text">Add Service Reference Dialog - Advanced Button</p></div>
<p>I clicked on the Advanced button and discovered the &#8220;Service Reference Settings&#8221; dialog. Note that the dialog title doesn&#8217;t quite match &#8220;Configure Service Reference&#8221; that was mentioned in the documentation.</p>
<div id="attachment_40" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-40" title="service-reference-settings_dialog" src="http://developersquest.files.wordpress.com/2009/01/service-reference-settings_dialog.png?w=450&#038;h=422" alt="Service Reference Settings dialog" width="450" height="422" /><p class="wp-caption-text">Service Reference Settings dialog</p></div>
<p>Anyway, according to <a title="Configure Service Reference Dialog" href="http://msdn.microsoft.com/en-us/library/bb514724.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/bb514724.aspx</a>,</p>
<blockquote><p>&#8220;The Configure Service Reference dialog box enables you to configure the behavior of Windows Communication Foundation (WCF) services.&#8221;</p></blockquote>
<p>Ok, so this is obviously a WCF-only feature. So I can&#8217;t use this with the Axis 1.4 remote service.</p>
<h4>Trying to Use the &#8220;Add Web Reference&#8221; Option</h4>
<p>But wait a minute &#8211; there is another button at the bottom of this new dialog&#8230;</p>
<div id="attachment_27" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-27" title="service-reference-settings_dialog_add-web-ref" src="http://developersquest.files.wordpress.com/2009/01/service-reference-settings_dialog_add-web-ref.png?w=450&#038;h=422" alt="Service Reference Settings Dialog - Add Web Reference Button" width="450" height="422" /><p class="wp-caption-text">Service Reference Settings Dialog - Add Web Reference Button</p></div>
<p>It is interesting that it says &#8220;Add a Web Reference instead of a Service Reference&#8221;. What exactly is the difference?</p>
<p>Ok, so I tried this Add Web Reference button to see if the compatibility option would be useful.</p>
<div id="attachment_41" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-41" title="add-web-reference_dialog" src="http://developersquest.files.wordpress.com/2009/01/add-web-reference_dialog.png?w=450&#038;h=315" alt="Add Web Reference Dialog" width="450" height="315" /><p class="wp-caption-text">Add Web Reference Dialog</p></div>
<p>I entered the <strong>https </strong>URL into the new dialog and clicked Go. Once again, as with the Add Service Reference dialog, the remote server triggered an authentication dialog on my end seeking a certificate.</p>
<div id="attachment_25" class="wp-caption aligncenter" style="width: 390px"><img class="size-full wp-image-25" title="choose-a-digital-certificate_dialog" src="http://developersquest.files.wordpress.com/2009/01/choose-a-digital-certificate_dialog.png?w=380&#038;h=327" alt="Choose A Digital Certificate Dialog" width="380" height="327" /><p class="wp-caption-text">Choose A Digital Certificate Dialog</p></div>
<p>I decided not to provide one at this time, and clicked Cancel. (I didn&#8217;t have a smartcard in the reader, so I believe it pulled these up from the local store).</p>
<p>I was then alerted that the remote site was using a self-signed certificate that was not trusted on my side, just as before when I tried adding a Service Reference. But this time the dialog was slightly different.</p>
<div id="attachment_42" class="wp-caption aligncenter" style="width: 394px"><img class="size-full wp-image-42" title="security-alert_dialog_problem-cert" src="http://developersquest.files.wordpress.com/2009/01/security-alert_dialog_problem-cert.png?w=384&#038;h=301" alt="Security Alert Dialog - from Add Web Reference" width="384" height="301" /><p class="wp-caption-text">Security Alert Dialog - from Add Web Reference</p></div>
<p>When I clicked No, it merely returned me to the Add Web Reference dialog. I decided to click Yes, and it proceeded to ask me again for a certificate. This time it wanted me to insert a smart card. (Perhaps it remembered I rejected all the ones listed in my local store earlier, and is therefore asking for alternatives).</p>
<div id="attachment_36" class="wp-caption aligncenter" style="width: 382px"><img class="size-full wp-image-36" title="insert-smart-card_dialog" src="http://developersquest.files.wordpress.com/2009/01/insert-smart-card_dialog.png?w=372&#038;h=139" alt="Dialog to Insert Smart Card" width="372" height="139" /><p class="wp-caption-text">Dialog to Insert Smart Card</p></div>
<p>I clicked cancel four times again, and it then returned to the Add Web Reference dialog with some feedback.</p>
<div id="attachment_43" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-43" title="add-web-reference_dialog_error-downloading" src="http://developersquest.files.wordpress.com/2009/01/add-web-reference_dialog_error-downloading.png?w=450&#038;h=315" alt="Add Web Reference Dialog - Error Downloading metadata" width="450" height="315" /><p class="wp-caption-text">Add Web Reference Dialog - Error Downloading metadata</p></div>
<p>This result seems strange. It displays content from the URL while simultaneously reporting an error that it could not create the SSL/TLS secure channel. Since I accepted their cert, then perhaps it failed because I did not provide one back. So, I clicked Go again and provided my smart card with the cert, and it responded with this dialog:</p>
<div id="attachment_44" class="wp-caption aligncenter" style="width: 382px"><img class="size-full wp-image-44" title="insert-smart-car_dialog_selected" src="http://developersquest.files.wordpress.com/2009/01/insert-smart-car_dialog_selected.png?w=372&#038;h=139" alt="Insert Smart Card Dialog - Card Selected" width="372" height="139" /><p class="wp-caption-text">Insert Smart Card Dialog - Card Selected</p></div>
<p>I clicked OK to continue, expecting new feedback. Unfortunately, even after providing my cert to the remote service, I still get the same failure feedback as before:</p>
<blockquote><p>&#8220;Could not create the SSL/TLS secure channel&#8221;.</p></blockquote>
<p>It might be that I am simply not authorized, or that my private key is not exportable, or that the VS2008 feature is running under a user that does not have access to the store where the cert is kept. It might also be that I need to install the remote cert and make it trusted rather than just accepting an untrusted cert.</p>
<p>At this point, though, I would like to see how things pan out if I go directly to a browser. I am just trying to create a proxy to this service, and am expecting to require minimal security to obtain the necessary information.</p>
<h4>Trying to Access the Service with the Browser</h4>
<p>I entered the URL into the browser and got the invalid certificate error.</p>
<div id="attachment_46" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-46" title="page-load-error_firefox_invalid-cert" src="http://developersquest.files.wordpress.com/2009/01/page-load-error_firefox_invalid-cert.png?w=450&#038;h=356" alt="Secure Connection Failed - Firefox" width="450" height="356" /><p class="wp-caption-text">Secure Connection Failed - Firefox</p></div>
<p>I decided to add a temporary exception.</p>
<div id="attachment_47" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-47" title="add-security-exception_firefox-dialog" src="http://developersquest.files.wordpress.com/2009/01/add-security-exception_firefox-dialog.png?w=450&#038;h=448" alt="Add Security Exception Dialog - Firefox" width="450" height="448" /><p class="wp-caption-text">Add Security Exception Dialog - Firefox</p></div>
<p>I noticed that this dialog has a button to [Get Certificate]. That struck me as relevant to the issues I mentioned before about how and where the server and/or client certificate is stored locally. It also reminds me of some google results I came across where mention is made of how IIS and IE and VS handle certificates differently, among other things. (For example, <a title="http://zybermark.blogspot.com/2008/03/clientcertificates-and-webexception.html" href="http://zybermark.blogspot.com/2008/03/clientcertificates-and-webexception.html" target="_blank">zybermark</a> and <a title="http://www.kerrywong.com/2006/12/01/using-x509-certificate-with-web-service-in-aspnet/" href="http://www.kerrywong.com/2006/12/01/using-x509-certificate-with-web-service-in-aspnet/" target="_blank">kerrywong</a> and <a title="http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/43fe9467-a2c2-4ce9-9d77-865e8fee456f" href="http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/43fe9467-a2c2-4ce9-9d77-865e8fee456f" target="_blank">an MSDN forum thread</a> discuss this)</p>
<p>Anyway, I retrieved it and unchecked the &#8220;Permanently store this exception&#8221; option.</p>
<div id="attachment_48" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-48" title="add-security-exception_firefox-dialog_get-cert" src="http://developersquest.files.wordpress.com/2009/01/add-security-exception_firefox-dialog_get-cert.png?w=450&#038;h=448" alt="Confirm Exception" width="450" height="448" /><p class="wp-caption-text">Add Security Exception Dialog - Firefox: Confirm Exception</p></div>
<p>After confirming this exception, the browser loaded up the service page, which was not much different than before:</p>
<div id="attachment_51" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-51" title="webservice-url_firefox_axis-service2" src="http://developersquest.files.wordpress.com/2009/01/webservice-url_firefox_axis-service2.png?w=450&#038;h=302" alt="Axis Web Service in Browser - Firefox" width="450" height="302" /><p class="wp-caption-text">Axis Web Service in Browser - Firefox</p></div>
<p>What is interesting here is that no security error seems apparent, yet no services seem to be available. Also, I was not asked for a certificate via the smartcard reader. Hmm.</p>
<h4>Trying to Access the WSDL with the Browser</h4>
<p>I have something else I want to try, so I will move on for now. I will try appending ?wsdl to the url to see if I can get what I actually need to generate a proxy from the commandline. As you can see below, I did in fact get a WSDL.</p>
<div id="attachment_52" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-52" title="webservice-url_firefox_axis-wsdl" src="http://developersquest.files.wordpress.com/2009/01/webservice-url_firefox_axis-wsdl.png?w=450&#038;h=358" alt="Axis Web Service WSDL - Firefox" width="450" height="358" /><p class="wp-caption-text">Axis Web Service WSDL - Firefox</p></div>
<p>However, notice that the lower right-hand corner displays an icon with an alert symbol with a tooltip indicating unauthenticated content:</p>
<div id="attachment_53" class="wp-caption aligncenter" style="width: 280px"><img class="size-full wp-image-53" title="webservice-url_firefox-error-icon_axis-wsdl" src="http://developersquest.files.wordpress.com/2009/01/webservice-url_firefox-error-icon_axis-wsdl.png?w=270&#038;h=89" alt="Firefox Error Icon - Unauthenticated Content Tooltip" width="270" height="89" /><p class="wp-caption-text">Firefox Error Icon - Unauthenticated Content Tooltip</p></div>
<p>When I click on this error icon, I get another dialog with more information:</p>
<div id="attachment_54" class="wp-caption aligncenter" style="width: 455px"><img class="size-full wp-image-54" title="page-info_firefox_security" src="http://developersquest.files.wordpress.com/2009/01/page-info_firefox_security.png?w=445&#038;h=500" alt="Page Info Security Tab - Firefox" width="445" height="500" /><p class="wp-caption-text">Page Info Security Tab - Firefox</p></div>
<p>I looked into this security error, because I am wondering why the remote service sent the WSDL information without having a fully secure connection. I am still not clear on this yet. It might be a configuration error, or it might be that they really do want anyone to be able to get the WSDL.</p>
<p>Likewise, if the remote site sent a WSDL file to my browser in spite of being unauthenticated, would it send it to Visual Studio?</p>
<h4>Trying to Access the WSDL from the &#8220;Add Web Reference&#8221; Dialog</h4>
<p>I quickly tried it, and it did fetch something:</p>
<div id="attachment_55" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-55" title="add-web-reference_dialog_wsdl" src="http://developersquest.files.wordpress.com/2009/01/add-web-reference_dialog_wsdl.png?w=450&#038;h=315" alt="Add Web Reference Dialog - Using URL for WSDL" width="450" height="315" /><p class="wp-caption-text">Add Web Reference Dialog - Using URL for WSDL</p></div>
<p>It does list the service and its operations. But it does not allow me to select anything. At this point, I am thinking that I should become more familiar with how this dialog is intended to work.</p>
<p>According to <a title="http://msdn.microsoft.com/en-us/library/8dcbc50t.aspx#" href="http://msdn.microsoft.com/en-us/library/8dcbc50t.aspx#" target="_blank">this MSDN article</a>:</p>
<blockquote><p>&#8220;The <span class="ui">Add Web Reference</span> dialog box enables you to browse for Web services and add Web references to a Web site. A Web reference enables you to use objects and methods provided by a Web service in your code. You can search for Web services on a local computer or on servers in your company&#8217;s local area network, or you can search the Internet for commercial Web services.&#8221;</p></blockquote>
<p>It also notes this:</p>
<blockquote><p>&#8220;When you open a project for editing that includes a Web reference, a local proxy file for the Web service runs in an instance of the Devenv.exe process that has been started by a trusted user — yourself.&#8221;</p></blockquote>
<p>That point might have something to do with the SSL certificate problems. Maybe not.</p>
<p>At this point, I am inclined to stop bothering with the security problems and just run with the fact that I can fetch the WSDL via the browser. Using the WSDL, I can generate a proxy from the commandline and use the resulting generated code in my client console application to access the remote service. But it still bothers me, because the previous SSL failures might be an indication that even after I have the proxy code for connecting, I won&#8217;t be able to complete the secure connection to make use of the operations on the service.</p>
<p>This article has gotten long, so I will resume this adventure in a later post.</p>
<p>(to be continued&#8230;)</p>
<br />Posted in Visual Studio 2008, Web Services Tagged: Add Service Reference, Add Web Reference, Apache Axis, secure channel, Smart Card Reader, SOAP 1.1, SOAP 1.2, SOAPAction header, SSL, SSL/TLS, trust relationship, Visual Studio, Visual Studio 2008, WCF, Web Service, WSDL <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/developersquest.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/developersquest.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/developersquest.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/developersquest.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/developersquest.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/developersquest.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/developersquest.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/developersquest.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/developersquest.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/developersquest.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/developersquest.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/developersquest.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/developersquest.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/developersquest.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=11&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://developersquest.wordpress.com/2009/01/23/my-endeavor-to-create-a-test-client-to-a-secure-remote-web-service-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/687b45847768b3b37beb6606103c2a0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gnhurst</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-service-reference_menu-selection.png" medium="image">
			<media:title type="html">add-service-reference_menu-selection</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-service-reference_dialog.png" medium="image">
			<media:title type="html">add-service-reference_dialog</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-service-reference_dialog_https-address.png" medium="image">
			<media:title type="html">add-service-reference_dialog_https-address</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/insert-smart-card_dialog.png" medium="image">
			<media:title type="html">insert-smart-card_dialog</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/security-alert_dialog.png" medium="image">
			<media:title type="html">security-alert_dialog</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-service-reference_dialog_error-declining-cert.png" medium="image">
			<media:title type="html">add-service-reference_dialog_error-declining-cert</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-service-reference-error_dialog_invalid-cert.png" medium="image">
			<media:title type="html">add-service-reference-error_dialog_invalid-cert</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-service-reference-error_dialog_accepting-cert1.png" medium="image">
			<media:title type="html">add-service-reference-error_dialog_accepting-cert</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-service-reference_dialog_advanced.png" medium="image">
			<media:title type="html">add-service-reference_dialog_advanced</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/service-reference-settings_dialog.png" medium="image">
			<media:title type="html">service-reference-settings_dialog</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/service-reference-settings_dialog_add-web-ref.png" medium="image">
			<media:title type="html">service-reference-settings_dialog_add-web-ref</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-web-reference_dialog.png" medium="image">
			<media:title type="html">add-web-reference_dialog</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/choose-a-digital-certificate_dialog.png" medium="image">
			<media:title type="html">choose-a-digital-certificate_dialog</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/security-alert_dialog_problem-cert.png" medium="image">
			<media:title type="html">security-alert_dialog_problem-cert</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/insert-smart-card_dialog.png" medium="image">
			<media:title type="html">insert-smart-card_dialog</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-web-reference_dialog_error-downloading.png" medium="image">
			<media:title type="html">add-web-reference_dialog_error-downloading</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/insert-smart-car_dialog_selected.png" medium="image">
			<media:title type="html">insert-smart-car_dialog_selected</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/page-load-error_firefox_invalid-cert.png" medium="image">
			<media:title type="html">page-load-error_firefox_invalid-cert</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-security-exception_firefox-dialog.png" medium="image">
			<media:title type="html">add-security-exception_firefox-dialog</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-security-exception_firefox-dialog_get-cert.png" medium="image">
			<media:title type="html">add-security-exception_firefox-dialog_get-cert</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/webservice-url_firefox_axis-service2.png" medium="image">
			<media:title type="html">webservice-url_firefox_axis-service2</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/webservice-url_firefox_axis-wsdl.png" medium="image">
			<media:title type="html">webservice-url_firefox_axis-wsdl</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/webservice-url_firefox-error-icon_axis-wsdl.png" medium="image">
			<media:title type="html">webservice-url_firefox-error-icon_axis-wsdl</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/page-info_firefox_security.png" medium="image">
			<media:title type="html">page-info_firefox_security</media:title>
		</media:content>

		<media:content url="http://developersquest.files.wordpress.com/2009/01/add-web-reference_dialog_wsdl.png" medium="image">
			<media:title type="html">add-web-reference_dialog_wsdl</media:title>
		</media:content>
	</item>
		<item>
		<title>Welcome to Developer&#8217;s Quest</title>
		<link>http://developersquest.wordpress.com/2009/01/15/welcome-to-developers-quest/</link>
		<comments>http://developersquest.wordpress.com/2009/01/15/welcome-to-developers-quest/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 22:04:26 +0000</pubDate>
		<dc:creator>gnhurst</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[introduction]]></category>
		<category><![CDATA[purpose]]></category>

		<guid isPermaLink="false">http://developersquest.wordpress.com/?p=3</guid>
		<description><![CDATA[The purpose of this blog is to be a destination to record what I learn in the realm of web development and architecture.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=3&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The purpose for this blog is to be a destination to record and share what I learn.</p>
<p>As a developer, I am typically engaged in doing software engineering, web development, and architectural analysis, among other things. And in that capacity, I often find myself engaging in a <strong>quest </strong>to gain competence or expertise in a new or existing technology, technique, language, framework, platform, tool, standard, or product that might or must be used in a project I am or might become involved in. I then take some time to read up on pertinent topics, study the relevant standards, read about lessons learned in the blog postings of others, and think about the implications of all this as it applies to the task at hand. As a result, I gain understanding and confidence. But I haven&#8217;t been recording much of what I have learned. Other developers I interact with occasionally express an interest in benefitting from what I have learned, without having to find all the resources all over again on their own. They could use a map to save them time.</p>
<p>I hope the record of my discoveries here provides just such a map to aid others who are on a similar quest.</p>
<br />Posted in Announcements Tagged: introduction, purpose <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/developersquest.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/developersquest.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/developersquest.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/developersquest.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/developersquest.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/developersquest.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/developersquest.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/developersquest.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/developersquest.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/developersquest.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/developersquest.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/developersquest.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/developersquest.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/developersquest.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=developersquest.wordpress.com&amp;blog=6189690&amp;post=3&amp;subd=developersquest&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://developersquest.wordpress.com/2009/01/15/welcome-to-developers-quest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/687b45847768b3b37beb6606103c2a0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gnhurst</media:title>
		</media:content>
	</item>
	</channel>
</rss>
