<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brant Burnett&#039;s Development Blog &#187; WCF</title>
	<atom:link href="http://btburnett.com/category/wcf/feed" rel="self" type="application/rss+xml" />
	<link>http://btburnett.com</link>
	<description></description>
	<lastBuildDate>Fri, 25 Mar 2011 13:39:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Create A Self-Signed SSL Certificate In .NET</title>
		<link>http://btburnett.com/2009/05/create-a-self-signed-ssl-certificate-in-net.html</link>
		<comments>http://btburnett.com/2009/05/create-a-self-signed-ssl-certificate-in-net.html#comments</comments>
		<pubDate>Fri, 08 May 2009 13:50:43 +0000</pubDate>
		<dc:creator>Brant Burnett</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://btburnett.com/?p=95</guid>
		<description><![CDATA[A problem that I have commonly run into is trying to secure communications using SSL or other encryption for a intranet application. In this scenario, it is unnecessary to have a secure certificate signed by an expensive Internet authority. And often it is intended for deployment in a small-scale scenario where there might not be [...]]]></description>
			<content:encoded><![CDATA[<p>A problem that I have commonly run into is trying to secure communications using SSL or other encryption for a intranet application.  In this scenario, it is unnecessary to have a secure certificate signed by an expensive Internet authority.  And often it is intended for deployment in a small-scale scenario where there might not be a Certification Authority running on a Window Server.  In this case, you want to create a self-signed certificate and use the thumbprint of the certificate for phishing prevention.</p>
<p>Microsoft does provide a utility, makecert, which can create a self-signed certificate.  However, it isn&#8217;t distributed with Windows, is command line only, and definately NOT end user friendly.  I wanted a method for creating a certificate just by clicking a button, without using a shell calls and distributing a copy of makecert with my applications.</p>
<p>To this end, I created a VB.Net class that calls out to the CryptoAPI and creates a self signed certificate with a 2048-bit RSA key.  The certificate and private key are stored in the Local Machine store.  In the Local Machine store it can be accessed by system processes and services.  I&#8217;ve attached an example of the class to this post, feel free to use it as you see fit.</p>
<a class="downloadlink" href="http://btburnett.com/wp-content/plugins/download-monitor/download.php?id=5" title=" downloaded 791 times" >Certificate Creator (791)</a>
]]></content:encoded>
			<wfw:commentRss>http://btburnett.com/2009/05/create-a-self-signed-ssl-certificate-in-net.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Monitoring a WCF Service Host</title>
		<link>http://btburnett.com/2008/10/monitoring-a-wcf-service-host.html</link>
		<comments>http://btburnett.com/2008/10/monitoring-a-wcf-service-host.html#comments</comments>
		<pubDate>Mon, 13 Oct 2008 12:22:00 +0000</pubDate>
		<dc:creator>Brant Burnett</dc:creator>
				<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.btburnett.com/?p=24</guid>
		<description><![CDATA[One problem I&#8217;ve been running into is my ServiceHosts failing out in my long running background services. I&#8217;ve written the following class to help monitor the service hosts and restart them if they fail. This is still experimental, and I&#8217;m not sure how well it&#8217;s going to work, so any feedback would be appreciated. The [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:85%;">One problem I&#8217;ve been running into is my ServiceHosts failing out in my long running background services.  I&#8217;ve written the following class to help monitor the service hosts and restart them if they fail.  This is still experimental, and I&#8217;m not sure how well it&#8217;s going to work, so any feedback would be appreciated.</span></p>
<p>The delegate is used to recreate the host whenever it needs to be created.  Just pass in a delegate to a function that creates the ServiceHost and initializes all of its bindings, etc.<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode"><span class="kwrd">Public</span> <span class="kwrd">Delegate</span> <span class="kwrd">Function</span> ServiceHostCreateDelegate() <span class="kwrd">As</span> ServiceHost

<span class="kwrd">Public</span> <span class="kwrd">Class</span> ServiceHostMonitor
    <span class="kwrd">Implements</span> IDisposable

    <span class="kwrd">Private</span> _del <span class="kwrd">As</span> ServiceHostCreateDelegate
    <span class="kwrd">Private</span> <span class="kwrd">WithEvents</span> _host <span class="kwrd">As</span> ServiceHost
    <span class="kwrd">Public</span> <span class="kwrd">ReadOnly</span> <span class="kwrd">Property</span> Host() <span class="kwrd">As</span> ServiceHost
        <span class="kwrd">Get</span>
            <span class="kwrd">If</span> _host <span class="kwrd">Is</span> <span class="kwrd">Nothing</span> <span class="kwrd">Then</span>
                CreateHost()
            <span class="kwrd">End</span> <span class="kwrd">If</span>

            <span class="kwrd">Return</span> _host
        <span class="kwrd">End</span> <span class="kwrd">Get</span>
    <span class="kwrd">End</span> <span class="kwrd">Property</span>

    <span class="kwrd">Public</span> <span class="kwrd">ReadOnly</span> <span class="kwrd">Property</span> HostCreated() <span class="kwrd">As</span> <span class="kwrd">Boolean</span>
        <span class="kwrd">Get</span>
            <span class="kwrd">Return</span> _host IsNot <span class="kwrd">Nothing</span>
        <span class="kwrd">End</span> <span class="kwrd">Get</span>
    <span class="kwrd">End</span> <span class="kwrd">Property</span>

    <span class="kwrd">Private</span> _hostName <span class="kwrd">As</span> <span class="kwrd">String</span>
    <span class="kwrd">Public</span> <span class="kwrd">ReadOnly</span> <span class="kwrd">Property</span> HostName() <span class="kwrd">As</span> <span class="kwrd">String</span>
        <span class="kwrd">Get</span>
            <span class="kwrd">Return</span> _hostName
        <span class="kwrd">End</span> <span class="kwrd">Get</span>
    <span class="kwrd">End</span> <span class="kwrd">Property</span>

    <span class="kwrd">Public</span> <span class="kwrd">ReadOnly</span> <span class="kwrd">Property</span> State() <span class="kwrd">As</span> CommunicationState
        <span class="kwrd">Get</span>
            <span class="kwrd">Return</span> Host.State
        <span class="kwrd">End</span> <span class="kwrd">Get</span>
    <span class="kwrd">End</span> <span class="kwrd">Property</span>

    <span class="kwrd">Public</span> <span class="kwrd">Sub</span> <span class="kwrd">New</span>(<span class="kwrd">ByVal</span> createDelegate <span class="kwrd">As</span> ServiceHostCreateDelegate, <span class="kwrd">ByVal</span> hostName <span class="kwrd">As</span> <span class="kwrd">String</span>)
        <span class="kwrd">If</span> createDelegate <span class="kwrd">Is</span> <span class="kwrd">Nothing</span> <span class="kwrd">Then</span>
            <span class="kwrd">Throw</span> <span class="kwrd">New</span> ArgumentNullException(<span class="str">"createDelegate"</span>)
        <span class="kwrd">End</span> <span class="kwrd">If</span>
        <span class="kwrd">If</span> hostName <span class="kwrd">Is</span> <span class="kwrd">Nothing</span> <span class="kwrd">Then</span>
            <span class="kwrd">Throw</span> <span class="kwrd">New</span> ArgumentNullException(<span class="str">"hostName"</span>)
        <span class="kwrd">End</span> <span class="kwrd">If</span>

        _del = createDelegate
        _hostName = hostName
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> Finalize()
        Dispose(<span class="kwrd">False</span>)
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Protected</span> <span class="kwrd">Sub</span> CreateHost()
        <span class="kwrd">If</span> HostCreated <span class="kwrd">Then</span>
            Close()
        <span class="kwrd">End</span> <span class="kwrd">If</span>

        _host = _del.Invoke()
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Public</span> <span class="kwrd">Sub</span> Open()
        <span class="kwrd">Try</span>
            CreateHost()
            Host.Open()

            Logger.LogMessage(<span class="str">"Opened Service Host "</span> &amp; _hostName)
        <span class="kwrd">Catch</span> ex <span class="kwrd">As</span> Exception
            Logger.LogException(ex, <span class="str">"Error Opening Service Host "</span> &amp; _hostName)
        <span class="kwrd">End</span> <span class="kwrd">Try</span>
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Public</span> <span class="kwrd">Sub</span> Close()
        <span class="kwrd">Try</span>
            <span class="kwrd">If</span> HostCreated <span class="kwrd">Then</span>
                <span class="kwrd">If</span> State = CommunicationState.Opened <span class="kwrd">Then</span>
                    Host.Close()
                <span class="kwrd">End</span> <span class="kwrd">If</span>

                _host = <span class="kwrd">Nothing</span>
            <span class="kwrd">End</span> <span class="kwrd">If</span>
        <span class="kwrd">Catch</span> ex <span class="kwrd">As</span> Exception
            Logger.LogException(ex, <span class="str">"Error Closing Service Host "</span> &amp; _hostName)
        <span class="kwrd">End</span> <span class="kwrd">Try</span>
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Private</span> <span class="kwrd">Sub</span> _host_Faulted(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> <span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> System.EventArgs) <span class="kwrd">Handles</span> _host.Faulted
        Logger.LogError(<span class="str">"Service Host Faulted "</span> &amp; _hostName)
        Open()
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

<span class="preproc">#Region</span> <span class="str">"IDisposable"</span>

    <span class="kwrd">Private</span> disposedValue <span class="kwrd">As</span> <span class="kwrd">Boolean</span> = <span class="kwrd">False</span>        <span class="rem">' To detect redundant calls</span>

    <span class="rem">' IDisposable</span>
    <span class="kwrd">Protected</span> <span class="kwrd">Overridable</span> <span class="kwrd">Sub</span> Dispose(<span class="kwrd">ByVal</span> disposing <span class="kwrd">As</span> <span class="kwrd">Boolean</span>)
        <span class="kwrd">If</span> <span class="kwrd">Not</span> <span class="kwrd">Me</span>.disposedValue <span class="kwrd">Then</span>
            <span class="kwrd">If</span> disposing <span class="kwrd">Then</span>
                Close()
            <span class="kwrd">End</span> <span class="kwrd">If</span>

            <span class="rem">' TODO: free shared unmanaged resources</span>
        <span class="kwrd">End</span> <span class="kwrd">If</span>
        <span class="kwrd">Me</span>.disposedValue = <span class="kwrd">True</span>
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

<span class="preproc">#Region</span> <span class="str">" IDisposable Support "</span>
    <span class="rem">' This code added by Visual Basic to correctly implement the disposable pattern.</span>
    <span class="kwrd">Public</span> <span class="kwrd">Sub</span> Dispose() <span class="kwrd">Implements</span> IDisposable.Dispose
        <span class="rem">' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.</span>
        Dispose(<span class="kwrd">True</span>)
        GC.SuppressFinalize(<span class="kwrd">Me</span>)
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>
<span class="preproc">#End Region</span>

<span class="preproc">#End Region</span>

<span class="kwrd">End</span> Class</pre>
<p>Please note that the Logger.LogError and Logger.LogMessage calls are for the custom error logging in my application.  You should replace this with your own error logging as you see fit.</p>
]]></content:encoded>
			<wfw:commentRss>http://btburnett.com/2008/10/monitoring-a-wcf-service-host.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Odd WSHttpBinding Scenario</title>
		<link>http://btburnett.com/2008/05/odd-wshttpbinding-scenario.html</link>
		<comments>http://btburnett.com/2008/05/odd-wshttpbinding-scenario.html#comments</comments>
		<pubDate>Thu, 08 May 2008 15:15:00 +0000</pubDate>
		<dc:creator>Brant Burnett</dc:creator>
				<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.btburnett.com/?p=10</guid>
		<description><![CDATA[I was having lots of trouble recently with a WCF WSHttpBinding scenario on a server. It had been working, and the only thing I had changed recently was to the base address of some of the bindings. On top of that, everything was working in my test environment. When I did trace logging on the [...]]]></description>
			<content:encoded><![CDATA[<div xmlns="http://www.w3.org/1999/xhtml"><small>I was having lots of trouble recently with a WCF WSHttpBinding scenario on a server.  It had been working, and the only thing I had changed recently was to the base address of some of the bindings.  On top of that, everything was working in my test environment.  When I did trace logging on the server, I wasn&#8217;t seeing any messages at all other than stating that listening had been started on the correct base addresses.  On the client side, I was receiving the following message during the negotiation for the secure session (I&#8217;m using message encryption via certificates):<br /></small><br />
<blockquote><small>An error occurred while receiving the HTTP response to http://xx.xx.xx.xx:yy/AdvWebClient/CapacityManager. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.</small></p></blockquote>
<p><small><br />I replaced the ip and port numbers for security purposes.</p>
<p>I worked on this for almost a day, restarting the windows service, changing configuration, staring at trace logs, etc.  Finally, as a last ditch effort, I rebooted the server and everything started working.  Apparently, there was some kind of hang up in the http.sys that was preventing it from processing the traffic.  This is despite the listeners opening and closing (I watched using netstat) when I started and stopped the service.</p>
<p>Hopefully this helps anyone else who encounters this problem.  If anyone knows of a way to reset the http.sys system without rebooting the entire computer, please let me know.  Thanks.</p>
<p></small></div>
]]></content:encoded>
			<wfw:commentRss>http://btburnett.com/2008/05/odd-wshttpbinding-scenario.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

