<?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>Alex Sarafian as Developer &#187; WCF</title>
	<atom:link href="http://sarafianalex.wordpress.com/category/net-c/wcf/feed/" rel="self" type="application/rss+xml" />
	<link>http://sarafianalex.wordpress.com</link>
	<description>Adventures in C# Land and some SQL</description>
	<lastBuildDate>Fri, 04 Sep 2009 11:27:50 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='sarafianalex.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/ea38bb69738d229a89ab00b82aad64b7?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Alex Sarafian as Developer &#187; WCF</title>
		<link>http://sarafianalex.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sarafianalex.wordpress.com/osd.xml" title="Alex Sarafian as Developer" />
		<item>
		<title>Self Issued X509 Certification Token</title>
		<link>http://sarafianalex.wordpress.com/2009/01/08/self-issued-x509-certification-token/</link>
		<comments>http://sarafianalex.wordpress.com/2009/01/08/self-issued-x509-certification-token/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 16:27:03 +0000</pubDate>
		<dc:creator>Sarafian Alex</dc:creator>
				<category><![CDATA[Certificate]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://sarafianalex.wordpress.com/2009/01/08/self-issued-x509-certification-token/</guid>
		<description><![CDATA[At the company I work for, there was a need to create a n-tier application with username authentication.
For some reason WCF requires a certificate which is understandable, but shouldn&#8217;t this be a choice of my company?I will not get deep with WCF about this part. Maybe in another section.
So what is the problem. The problem [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sarafianalex.wordpress.com&blog=2367780&post=53&subd=sarafianalex&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p align="justify">At the company I work for, there was a need to create a n-tier application with username authentication.</p>
<p align="justify">For some reason WCF requires a certificate which is understandable, but shouldn&#8217;t this be a choice of my company?I will not get deep with WCF about this part. Maybe in another section.</p>
<p align="justify">So what is the problem. The problem is that everyone talks about making a self issued certification token and using it to run in development, but few talk about deploying the application. And most of those few have posted questions that remain unanswered or have posted some guidelines that do not work entirely.</p>
<p align="justify">My development machine is Vista 32 based and target deployment was for both Vista 32 and Windows Server 2003 both environments under their respective IIS.</p>
<p align="justify">First of all, the token must be created. At start as many of you, I knew little about certificates. I really believe this not to be a common interest for developers, so it has been really annoying not to really understand what has been happening or why that command was user. It is fair to say that at the moment, I haven&#8217;t really understood why the solution works, probably because after not being able to find solutions for my problems I had to resort to trial and error. Additionally Microsoft does not make public a lot of information about the subject or relevant APIS and their errors. There are some tools for example that generate a very common error message that one can not track the reason causing it.</p>
<p align="justify">Certificates manager console will be required with knowledge of it for importing and exporting.</p>
<p align="justify">Anyway, lets start.</p>
<p align="justify">First I will discuss how to create a self issued token through the development token. To token is created for a WCF service and its store location will be LocalMachine and store name My. My post is not for WCF so I assume that one knows what the above means for WCF.</p>
<p align="justify">Then I will discuss how to setup IIS in the development machine.</p>
<p align="justify">Last in this post I will tell you how to reuse the above token in other machines.</p>
<h2 align="justify"></h2>
<h2 align="justify">Token Creation</h2>
<p align="justify">
<p align="justify">In order to create a self issued token, you must have installed in the machine Windows SDK. Because the machine is a development the above should be found in :\Program Files\Microsoft SDKs\Windows\v6.0A\Bin for Vista and XP and C:\Program Files\Microsoft Platform SDK\Bin for Windows 2003.If not found for windows 2003 you can download it from <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&amp;displaylang=en#filelist">here</a>. In any case WSDK will refer from now on to the appropriate path.</p>
<p align="justify">In order to create the token a certification authority token must be created first and then the token itself issued by the above. In order to keep it simple we assume that TokenCA is the certificate authority token and TokenCert is the certification token based on TokenCA.</p>
<p align="justify">In order for the above to work for wcf, the key must be exportable so in each command that it is required the appropriate flag is used. I will not analyze the commands, you can do it from the help or Internet.</p>
<p align="justify">The goal of the next steps is to create a zip file with the reusable token.All files will be saved in C:\ . Password will be required. I chose one and used it everywhere.</p>
<h3 align="justify">Create Certification Authority</h3>
<p align="justify">Open a command prompt for the WSDK path.</p>
<p align="justify">Execute makecert -n &#8220;CN=TokenCA&#8221; -r -sky exchange -pe -sv C:\TokenCA.pvk C:\TokenCA.cer</p>
<h3 align="justify">Create Certification Token</h3>
<p align="justify">Execute makecert -sk =TokenCert -iv C:\TokenCA.pvk -n &#8220;CN=TokenCert&#8221; -ic C:\TokenCA.cer -sky exchange -pe C:\TokenCert.cer -sr LocalMachine -ss My</p>
<h3 align="justify">Import Token</h3>
<p align="justify">In order to Import Token you must open the Certificates manager from the mmc.</p>
<p align="justify">In the Trusted Root Certification Authorities under certificated select import and choose the TokenCA.cer we created.</p>
<p align="justify">Then in the Personal under Certificated select import and choose TokenCert.cer.</p>
<p align="justify">At this stage the token is ready to be used by the development WCF Service.</p>
<h3 align="justify">Export Token</h3>
<p align="justify">In the Personal under Certificated select import and choose the token we created and select export. On the question if you want the export the private key, choose YES.</p>
<p align="justify"><a href="http://sarafianalex.files.wordpress.com/2009/01/image1.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="221" alt="image" src="http://sarafianalex.files.wordpress.com/2009/01/image-thumb.png?w=244&#038;h=221" width="244" border="0"></a> </p>
<p align="justify">Then select like the next picture </p>
<p align="justify"><a href="http://sarafianalex.files.wordpress.com/2009/01/image2.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="221" alt="image" src="http://sarafianalex.files.wordpress.com/2009/01/image-thumb1.png?w=244&#038;h=221" width="244" border="0"></a> </p>
<p align="justify">Then enter password, and select where it should be stored. I entered c:\Token.pfx.</p>
<p align="justify">At this stage in c:\ there should be 4 files starting with token which you can pack but the reusable part is the Token.pfx.</p>
<h2 align="justify">Deploying in another machine</h2>
<p align="justify">
<p align="justify">Now we want to use the above certificate. In the certificates manager in Certificates node under Personal you import the TokenCert.pfx enter the password and mark the key as exportable like this</p>
<p align="justify"><a href="http://sarafianalex.files.wordpress.com/2009/01/image.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="221" alt="image" src="http://sarafianalex.files.wordpress.com/2009/01/image-thumb2.png?w=244&#038;h=221" width="244" border="0"></a> </p>
<h2 align="justify">IIS Setup </h2>
<p align="justify">
<p align="justify">In order for any process to use the token we created or imported, that process must have read rights under the user it is running over the actual file windows created for the certificate token (TokenCert).</p>
<p align="justify">So for IIS NETWORK_SERVICE must have read access over the file.</p>
<p align="justify">If the OS is Windows 2003 you can use <a href="http://www.microsoft.com/downloads/thankyou.aspx?familyId=c42e27ac-3409-40e9-8667-c748e422833f&amp;displayLang=en">WinHttpCertCfg.exe</a> which has two problems. First it is deprecated for Vista and second most important it gives the user Full Control access. So I do not recommend it. In any case use it like this winhttpcertcfg -g -c LOCAL_MACHINE\My -s &#8220;TokenCert&#8221; -a &#8220;NETWORK SERVICE&#8221;</p>
<p align="justify">Windows itself want tell you the file itself. In order to locate it you must follow <a href="http://msdn.microsoft.com/en-us/library/aa717039.aspx">these</a> instructions.After you have located is just give the right like every other folder/file sharing.</p>
<p align="justify">Now the IIS can access the certificate. If you don&#8217;t do this the service will fail in every attempt including just hitting the svc which I used as a test.</p>
<p align="justify">In Vista there is another way through the certificates manager. You can select the certificate token (TokenCert) and right click -&gt; All Tasks -&gt; Manage Private Keys will display the access rights dialog for the actual file.</p>
<h2>Questions</h2>
<p align="justify">I can&#8217;t understand why in other machines the TokenCA is not needed. When I had also imported that, there were errors both from the finding tool and the winhttpcertcfg. This problem was resolved based truly on trial and error, but I still can&#8217;t understand why when creating the TokenCert, TokenCA is needed and then not. I know that the key is contained in the pfx, but as a mentioned my knowledge of certificates is superficial so the question still remains.</p>
<p align="justify">If I use the TokenCert outside the intranet will it still work?</p>
<h2>Future Stuff</h2>
<p>Because I want/ need automate the procedure, tools will be written to do the above in sequence. When I do, I surely post here or on codeproject.</p>
<h2>Conclusions</h2>
<p>Any questions you might have, please just ask and if I can help I will. The above process has taken me 2 days to find and I personally find it unacceptable especially when there is a WCF authorization system that requires the use of a token.</p>
<p>This article is based again on a specific WCF deployment that was required of me, but I think it is irrelevant.</p>
<p>Hope I didn&#8217;t forget anything.</p>
<p align="justify">Finally let me just say that the simplest and oldest authorization has been turned into a deployment nightmare. Hope this article helps the community. As always everything is great when Microsoft evangelist advertise. You guys, we are not making an assignment for IT bachelors.</p>
<p align="justify">
Posted in Certificate, IIS, WCF, Windows  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sarafianalex.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sarafianalex.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sarafianalex.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sarafianalex.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sarafianalex.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sarafianalex.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sarafianalex.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sarafianalex.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sarafianalex.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sarafianalex.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sarafianalex.wordpress.com&blog=2367780&post=53&subd=sarafianalex&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sarafianalex.wordpress.com/2009/01/08/self-issued-x509-certification-token/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/64f00567ef7dda3ec36dcf0e01043d11?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sarafian</media:title>
		</media:content>

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

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

		<media:content url="http://sarafianalex.files.wordpress.com/2009/01/image-thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>How to debug a WCF service</title>
		<link>http://sarafianalex.wordpress.com/2008/06/28/how-to-debug-a-wcf-service/</link>
		<comments>http://sarafianalex.wordpress.com/2008/06/28/how-to-debug-a-wcf-service/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 20:07:12 +0000</pubDate>
		<dc:creator>Sarafian Alex</dc:creator>
				<category><![CDATA[.NET C#]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://sarafianalex.wordpress.com/2008/06/28/how-to-debug-a-wcf-service/</guid>
		<description><![CDATA[Introduction
WCF default debugging does not support edit and continue features, as I have said in my blog post 
Background
In that post I said that there is an easy way to do it, but I didn&#8217;t give any code. So this article is about how to it. The reason I wrote this article, is because a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sarafianalex.wordpress.com&blog=2367780&post=29&subd=sarafianalex&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h4>Introduction</h4>
<p>WCF default debugging does not support edit and continue features, as I have said in my blog <a href="http://sarafianalex.wordpress.com/2008/06/17/wcf-debuging/">post </a></p>
<h4>Background</h4>
<p>In that post I said that there is an easy way to do it, but I didn&#8217;t give any code. So this article is about how to it. The reason I wrote this article, is because a fellow member wrote a useful article about wcf, and in tip1 he suggested using a console application.</p>
<p>My scenario for wcf service consuming and debugging is a Client Server application. I believe my solution can apply and for other scenarios.</p>
<h4>How to do it</h4>
<p>You need this class <code>DebugServiceHost</code></p>
<pre><span style="color:blue;">internal class </span><span style="color:#2b91af;">DebugServiceHost</span>:<span style="color:#2b91af;">IDisposable
</span>{
    <span style="color:blue;">private static string </span>serviceExecuteTypeName = <span style="color:#a31515;">"ExecutionService.ServiceExecute, ServiceSide.ExecutionService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"</span>;
    <span style="color:blue;">private static string </span>iServiceExecuteTypeName = <span style="color:#a31515;">"ExecutionService.IServiceExecute, ServiceSide.ExecutionService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"</span>;
<span style="color:blue;">public static string </span>Address = <span style="color:#a31515;">@"http://localhost:9999/ExecutionService/ServiceExecute/"</span>;
    <span style="color:blue;">public static </span>Binding Binding = <span style="color:blue;">new </span>WSHttpBinding();

    <span style="color:blue;">static </span>DebugServiceHost()
    {
        isEnabled = <span style="color:#2b91af;">Type</span>.GetType(serviceExecuteTypeName) != <span style="color:blue;">null</span>;
    }
    <span style="color:blue;">public </span>DebugServiceHost()
    {
        <span style="color:#2b91af;">Type </span>serviceType = <span style="color:#2b91af;">Type</span>.GetType(serviceExecuteTypeName);
        <span style="color:#2b91af;">Type </span>iServiceType = <span style="color:#2b91af;">Type</span>.GetType(iServiceExecuteTypeName);
        <span style="color:blue;">this</span>.debugHost = <span style="color:blue;">new </span>ServiceHost(serviceType);

        <span style="color:blue;">this</span>.debugHost.AddServiceEndpoint(iServiceType, Binding, Address);
        <span style="color:blue;">this</span>.debugHost.Open();
    }

    <span style="color:blue;">private </span>System.ServiceModel.ServiceHost debugHost;

    <span style="color:blue;">private static bool </span>isEnabled = <span style="color:blue;">false</span>;
    <span style="color:blue;">public static bool </span>IsEnabled
    {
        <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>isEnabled; }
    }

    <span style="color:blue;">#region </span>IDisposable Members
    <span style="color:blue;">private bool </span>disposed = <span style="color:blue;">false</span>;
    <span style="color:blue;">public void </span>Dispose()
    {
        <span style="color:blue;">if </span>(<span style="color:blue;">this</span>.disposed)
        {
            <span style="color:blue;">return</span>;
        }
        <span style="color:blue;">this</span>.debugHost.Close();
        <span style="color:#2b91af;">GC</span>.SuppressFinalize(<span style="color:blue;">this</span>);
    }

    <span style="color:blue;">#endregion
</span>}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>where <code>ServiceSide.ExecutionService.ServiceExecute </code>is the namespace of the wcf service and <code>ServiceSide.ExecutionService </code>the assembly containing it.</p>
<h4>Using the code</h4>
<p>I use a provider class, but its up to you how to implement the above feature.</p>
<p><code>DebugServiceHost </code>has a static property <code>IsEnabled</code>, which basically checks whether the service is locally located to the running client execution folder. If that is true then using an instance of the class, host the service as well, which is automatically disposed.</p>
<p>This a sample code from my project that consumed the true or debug hosted service.</p>
<p><img height="9" src="http://www.codeproject.com/images/minus.gif" width="9"> Collapse</p>
<pre><span style="color:blue;">public static class </span><span style="color:#2b91af;">Provider
</span>{
    <span style="color:blue;">private static </span>DebugServiceHost dbh;
    <span style="color:blue;">public static void </span>CheckAndRunDebugService()
    {
        <span style="color:blue;">if </span>(DebugServiceHost.IsEnabled)
        {
            dbh = <span style="color:blue;">new </span>DebugServiceHost();
        }
    }
    <span style="color:blue;">public static string </span>RemoteURL { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
    <span style="color:blue;">private static </span>IServiceExecute iServiceExecute = <span style="color:blue;">null</span>;
    <span style="color:blue;">private static </span>IServiceExecute GetInterface()
    {
        <span style="color:blue;">if </span>(iServiceExecute != <span style="color:blue;">null</span>)
            <span style="color:blue;">return </span>iServiceExecute;
        iServiceExecute = CreateClient();
        <span style="color:blue;">return </span>iServiceExecute;
    }
    <span style="color:blue;">private static </span>ServiceExecuteClient CreateClient()
    {
        <span style="color:blue;">string </span>address = <span style="color:#a31515;">""</span>;
        <span style="color:blue;">if </span>(DebugServiceHost.IsEnabled)
        {
            address = DebugServiceHost.Address;
        }
        <span style="color:blue;">else
        </span>{
            address = <span style="color:#2b91af;">String</span>.Format(<span style="color:#a31515;">"{0}/Service.svc"</span>, Provider.RemoteURL);
        }
        <span style="color:blue;">return new </span>ServiceExecuteReference.ServiceExecuteClient(<span style="color:#a31515;">"DefaultEndPoint"</span>, address);
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>where </p>
<ul>
<li><code>IServiceExecute </code>is the Interface created when you add the service Reference.
<li><code>ServiceExecuteReference.ServiceExecuteClient </code>is the client created when you add the service reference
<li>DefaultEndPoint is the endpoint in my config file. </li>
</ul>
<h4>Points of Interest</h4>
<p>At first I at the first call to the service, I create the host. But as I mentioned in my <a href="http://sarafianalex.wordpress.com/2008/06/17/wcf-debuging/">post</a> there was problem with that implementation.</p>
<blockquote>
<p><strong><em>Last problem hopefully</em></strong></p>
<p><em>Finally a point of interest which was my last obstacle that took me a half day to find. I had implemented a provider class for the remoting part, which if needed, fired up the service host. Everything worked just great in the test projects, but at some point I tried to extend the framework with WPF.</em></p>
<p><em>The trick was that at first request, through static constructor I checked if the service was required to be hosted, and did that. But this did not work when I made the call from WPF. The only error was a timeout exception. I was going crazy, and then it kicked in. Never trust completely a 3 party library.</em></p>
<p><strong><em>Solution</em></strong></p>
<p><em>I made three clients, one Console, one Windows one WPF and stripped down the functionality of my framework to test. On each UI Client I made the call (and raised subsequently the host) after a UI reaction. I turns out that neither Windows Forms played correctly, when for example the call is made through a button click event. When I saw that, I made the host come up before the UI part was ever initialized and guess what? It all played just fine.</em></p>
<p><em>I really can&#8217;t understand how this has not been mentioned.</em></p>
</blockquote>
<p>So I refactored the code, and at the program main entry method I call <code>Provider.CheckAndRunDebugService()</code></p>
<p>Final thing is that, you must implement a trick in order for all serverside assemblies to be found in the client execution folder when you are debugging. There are a number of ways to do achieve this mainly by using post build event or by just adding the references and deleting them when in deployment face. I use the first.</p>
<h4>Apologies</h4>
<p>There is not project code, because the above resides in a framework project, I have written for the company I work for.</p>
<p><a href="http://www.codeproject.com/KB/WCF/WCFRDebug.aspx" target="_blank">CodeProject Article</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sarafianalex.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sarafianalex.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sarafianalex.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sarafianalex.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sarafianalex.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sarafianalex.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sarafianalex.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sarafianalex.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sarafianalex.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sarafianalex.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sarafianalex.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sarafianalex.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sarafianalex.wordpress.com&blog=2367780&post=29&subd=sarafianalex&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sarafianalex.wordpress.com/2008/06/28/how-to-debug-a-wcf-service/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/64f00567ef7dda3ec36dcf0e01043d11?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sarafian</media:title>
		</media:content>

		<media:content url="http://www.codeproject.com/images/minus.gif" medium="image" />
	</item>
		<item>
		<title>WCF Debugging and a WCF review</title>
		<link>http://sarafianalex.wordpress.com/2008/06/17/wcf-debuging/</link>
		<comments>http://sarafianalex.wordpress.com/2008/06/17/wcf-debuging/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 19:52:11 +0000</pubDate>
		<dc:creator>Sarafian Alex</dc:creator>
				<category><![CDATA[.NET C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Review]]></category>

		<guid isPermaLink="false">http://sarafianalex.wordpress.com/2008/06/17/wcf-debuging/</guid>
		<description><![CDATA[A comment
At some point, people need to understand that, business applications are not like console applications. So all these comments on the net, in blogs and forums, should be a little more double checked for real life development process because they mislead other people. Especially for LINQ to SQL and WCF, I am really bored [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sarafianalex.wordpress.com&blog=2367780&post=24&subd=sarafianalex&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2>A comment</h2>
<p>At some point, people need to understand that, business applications are not like console applications. So all these comments on the net, in blogs and forums, should be a little more double checked for real life development process because they mislead other people. Especially for LINQ to SQL and WCF, I am really bored reading about how great they are and how easy they are, but the truth is that LINQ to SQL is not for applications (reason in another <a href="http://sarafianalex.wordpress.com/2008/06/17/linq-to-sql-not-suitable-for-lob/" target="_blank">post</a>) and I was one of the victims that tried to adopt it, and WCF although is great, it can also be a pain in the ass. When searching through the net, keep in mind always that Internet is not always correct as I have wrote <a href="http://www.codeproject.com/KB/dotnet/ClearUpSerialization.aspx" target="_blank">here</a>. I really suspect that many of the blog post although, they can be helping, are not revealing entirely the truth and the disadvantages. I have always been fun of Microsoft Technologies but there is a limit to the indirect advertisement.</p>
<h2>Following instructions</h2>
<p>Back to the post subject. Many of you have done what everybody on Internet says. Add a WCF Service and a Service Reference and Great, all is ready and done. Even for debug, every time I execute debug the application, a dummy Debug Host is raised and I can debug the service. All is great? No.</p>
<h2>Questions</h2>
<p>First of all. What if I&#8217;m not running parts of the solution that require the service. Why should I be punished with the overhead of raising the host?</p>
<p>Second and most serious. Has really anyone tried to debug the service, and every underlying class used by it? Has anybody tried to utilize edit and continue, among all these guys who say how great WCF is?</p>
<p>I tried and as you can guess from my attitude, I could not utilize Edit And Continue. When I am developing a big Application, usually there will be at least 2 layers behind the service. Should I restart the application each time? And don&#8217;t let me talk about the debug through the dummy client, when an Operation Contract of mine, will use a complex data type. It is just not possible.</p>
<h2>So what is the solution?</h2>
<p>Easy someone can say, but easier said than done. As you would with .Net Remoting, If the service is located in your output directory, by whatever trick in the solution, then just raise the host programmatically in an address of your choice and then tell the client to hit this address. This way you have always simulating data transferring through WCF channels (<strong>very important</strong>), and you can of coarse use the feature of Edit and Continue.</p>
<p>The problem is that the dummy service the solution raised keeps coming up, which is very annoying. I haven&#8217;t found a solution, mainly because in the framework I&#8217;m developing, there is a single Operation Contract handling abstract Message Types. This was another great milestone for me in WCF. I really can&#8217;t understand why they have made DataContractSerializer as complicated, and not simple as the one used in plain old fashioned remoting. Having this service in my framework, I do not have in my solution the WCF Service so , there is no penalty overhead from the Debug Host that is raised.</p>
<h2>Last problem hopefully</h2>
<p>Finally a point of interest which was my last obstacle that took me a half day to find. I had implemented a provider class for the remoting part, which if needed, fired up the service host. Everything worked just great in the test projects, but at some point I tried to extend the framework with WPF.</p>
<p>The trick was that at first request, through static constructor I checked if the service was required to be hosted, and did that. But this did not work when I made the call from WPF. The only error was a timeout exception. I was going crazy, and then it kicked in. Never trust completely a 3 party library.</p>
<h2>Solution</h2>
<p>I made three clients, one Console, one Windows one WPF and stripped down the functionality of my framework to test. On each UI Client I made the call (and raised subsequently the host) after a UI reaction. I turns out that neither Windows Forms played correctly, when for example the call is made through a button click event. When I saw that, I made the host come up before the UI part was ever initialized and guess what? It all played just fine.</p>
<p>I really can&#8217;t understand how this has not been mentioned.</p>
<h2>Conclusion</h2>
<p>For me WCF is good for the plumbing. It is much more complicated than .Net remoting, really hard to troubleshoot if you are doing something outside the ordinary, which are discussed in all those praising posts and articles. Maybe I haven&#8217;t studied it as much, maybe I&#8217;m missing something but if the case is true, tell me how something that is advertised as easy and all remoting-problem solving can be this hard to utilize and debug. You will say that WPF, has as much difficult learning curve but WPF is not advertised as the magic trick that the programming world was missing. Since I have read about it, everyone mentioned that it is hard and difficult to adopt, and it is not for all kinds of applications. For me WPF is the star of .NET3. </p>
<p>Despite all these problems I really believe in WCF, because of other great stuff that it supports.&nbsp; Regarding security MS says <a href="http://msdn.microsoft.com/en-us/library/bb552363.aspx" target="_blank">here</a> that</p>
<blockquote><p>You should not use WCF Service Host to host services in a production environment, as it was not engineered for this purpose. WCF Service Host does not support the reliability, security, and manageability requirements of such an environment. Instead, use IIS since it provides superior reliability and monitoring features, and is the preferred solution for hosting services. Once development of your services is complete, you should migrate the services from WCF Service Host to IIS.</p>
</blockquote>
<p>Having this in mind, I can&#8217;t stop thinking whether WCF is a great overhead on development, when .NET is remoting is a well tested solution under IIS. But choices have been made, mainly because the new technology I believe is here to stay.</p>
<h2>Links</h2>
<p align="justify">Same <a href="http://www.codeproject.com/KB/WCF/WCFReviewAndDebug.aspx" target="_blank">Article</a> at code project.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sarafianalex.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sarafianalex.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sarafianalex.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sarafianalex.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sarafianalex.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sarafianalex.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sarafianalex.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sarafianalex.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sarafianalex.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sarafianalex.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sarafianalex.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sarafianalex.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sarafianalex.wordpress.com&blog=2367780&post=24&subd=sarafianalex&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sarafianalex.wordpress.com/2008/06/17/wcf-debuging/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/64f00567ef7dda3ec36dcf0e01043d11?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sarafian</media:title>
		</media:content>
	</item>
	</channel>
</rss>