<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0"><channel><title>U2U WCF feed</title><description /><item><guid isPermaLink="false">https://blogs.u2u.be/kris/post.aspx?id=11a9376d-3a0e-4291-bac2-43c34ae7492b</guid><link>https://blogs.u2u.be/kris/post/U2U-Consult-TechDays-2011-CD-Available-for-Download</link><category>.NET</category><category>Tools</category><category>WCF</category><title>U2U Consult TechDays 2011 CD Available for Download</title><description>&lt;p&gt;At TechDays 2011 in Antwerp, U2U Consult distributed a CD-ROM with two free tools. I’m happy to announce that the CD-ROM contents is now also &lt;a href="http://www.u2uconsult.com/DL/U2UConsultTechDays2011CD.ZIP" target="_blank"&gt;available for download&lt;/a&gt; from &lt;a href="http://www.u2uconsult.com/" target="_blank"&gt;our web site&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The U2U Consult SQL Database Analyzer is a tool for SQL Server database administrators and developers. It displays diagnostic information about a database and its hosting instance that is hard to collect when you only use the standard SQL Server tools. Just point the tool at a SQL Server database of your choice, and have a look at the reports generated by the tool.&lt;/p&gt;  &lt;p&gt;The U2U Consult Code Analysis Rules for Visual Studio 2010 are a series of additional code analysis rules for Visual Studio 2010 Premium or Ultimate, and two rule sets with recommended rules for libraries and applications. The rules include additional general performance and design rules, as well as a series of rules specifically for WCF. All rules are documented on the CD-ROM. Obviously, they are applicable to all .NET languages, including C# and VB.&lt;/p&gt;  &lt;p&gt;With this CD, for the first time we make two of our own tools available to you. These are only two small components out of the U2U Consult Framework, but we hope they are as useful to you as they are to us and our clients. Enjoy.&lt;/p&gt;</description><pubDate>Mon, 25 Apr 2011 14:15:19 Z</pubDate><comments>https://blogs.u2u.be/kris/post/U2U-Consult-TechDays-2011-CD-Available-for-Download#comment</comments><dc:publisher xmlns:dc="http://purl.org/dc/elements/1.1/">Kris Vandermotten</dc:publisher><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">https://blogs.u2u.be/kris/pingback.axd</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">https://blogs.u2u.be/kris/post.aspx?id=11a9376d-3a0e-4291-bac2-43c34ae7492b</pingback:target><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">17</slash:comments><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">https://blogs.u2u.be/kris/trackback.axd?id=11a9376d-3a0e-4291-bac2-43c34ae7492b</trackback:ping><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">https://blogs.u2u.be/kris/post/U2U-Consult-TechDays-2011-CD-Available-for-Download#comment</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">https://blogs.u2u.be/kris/syndication.axd?post=11a9376d-3a0e-4291-bac2-43c34ae7492b</wfw:commentRss></item><item><guid isPermaLink="false">https://blogs.u2u.be/kris/post.aspx?id=08608f9b-06a9-4e1c-b335-e01c388bb4e3</guid><link>https://blogs.u2u.be/kris/post/Safe-disposal-of-WCF-proxies</link><category>WCF</category><title>Safe disposal of WCF proxies</title><description>&lt;p&gt;The issue has been known for a long time: you cannot safely dispose a WCF proxy that inherits from &lt;a href="http://msdn.microsoft.com/en-us/library/ms576141.aspx" target="_blank"&gt;ClientBase&amp;lt;T&amp;gt;&lt;/a&gt; with a using statement, because the dispose method may throw.&amp;#160; For more information, see &lt;a title="http://www.google.com/search?q=wcf+proxy+dispose" href="http://www.google.com/search?q=wcf+proxy+dispose"&gt;http://www.google.com/search?q=wcf+proxy+dispose&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;However, I’ve always found most solutions out there to be too complex, too cumbersome, or both. Some of them even seek to replace the Visual Studio (or svcutil.exe) generated proxy by handwritten code, in which case you loose the convenience of the “Add Service Reference” dialog and the automatic configuration file generation. I wanted a simple but effective solution that does not replace the Visual Studio code generation, and is easy to use at the same time.&lt;/p&gt;  &lt;p&gt;I came up with a simple extension method, that you use as follows:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;proxy = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SomeServiceClient&lt;/span&gt;();
&lt;span style="color: blue"&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;(proxy.SafeDisposer())
{
    &lt;span style="color: green"&gt;// use the proxy here
&lt;/span&gt;}&lt;/pre&gt;

&lt;p&gt;Here’s the code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;U2UConsult.ServiceModel
{
    &lt;span style="color: blue"&gt;using &lt;/span&gt;System;
    &lt;span style="color: blue"&gt;using &lt;/span&gt;System.Diagnostics;
    &lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel;

    &lt;span style="color: blue"&gt;public static class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ClientBaseExtensions
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;private static readonly &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TraceSource &lt;/span&gt;traceSource = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TraceSource&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;U2UConsult.ServiceModel&amp;quot;&lt;/span&gt;);

        &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IDisposable &lt;/span&gt;SafeDisposer&amp;lt;T&amp;gt;(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ClientBase&lt;/span&gt;&amp;lt;T&amp;gt; proxy) &lt;span style="color: blue"&gt;where &lt;/span&gt;T : &lt;span style="color: blue"&gt;class
        &lt;/span&gt;{
            &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SafeDisposerProxy&lt;/span&gt;&amp;lt;T&amp;gt;(proxy);
        }

        &lt;span style="color: blue"&gt;private sealed class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SafeDisposerProxy&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="color: blue"&gt;where &lt;/span&gt;T : &lt;span style="color: blue"&gt;class
        &lt;/span&gt;{
            &lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ClientBase&lt;/span&gt;&amp;lt;T&amp;gt; proxy;

            &lt;span style="color: blue"&gt;public &lt;/span&gt;SafeDisposerProxy(&lt;span style="color: #2b91af"&gt;ClientBase&lt;/span&gt;&amp;lt;T&amp;gt; proxy)
            {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.proxy = proxy;
            }

            &lt;span style="color: blue"&gt;public void &lt;/span&gt;Dispose()
            {
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.proxy != &lt;span style="color: blue"&gt;null&lt;/span&gt;)
                {
                    &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.proxy.State == &lt;span style="color: #2b91af"&gt;CommunicationState&lt;/span&gt;.Opened)
                    {
                        &lt;span style="color: blue"&gt;try
                        &lt;/span&gt;{
                            &lt;span style="color: blue"&gt;this&lt;/span&gt;.proxy.Close();
                        }
                        &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;ex)
                        {
                            &lt;span style="color: #2b91af"&gt;ClientBaseExtensions&lt;/span&gt;.traceSource.TraceEvent(
                                &lt;span style="color: #2b91af"&gt;TraceEventType&lt;/span&gt;.Error, 
                                0, 
                                &lt;span style="color: #a31515"&gt;&amp;quot;Could not close client proxy, reason: {0}&amp;quot;&lt;/span&gt;, 
                                ex.Message);
                            &lt;span style="color: blue"&gt;this&lt;/span&gt;.proxy.Abort();
                        }
                    }
                    &lt;span style="color: blue"&gt;else
                    &lt;/span&gt;{
                        &lt;span style="color: blue"&gt;this&lt;/span&gt;.proxy.Abort();
                    }

                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.proxy = &lt;span style="color: blue"&gt;null&lt;/span&gt;;
                }
            }
        }
    }
}&lt;/pre&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;</description><pubDate>Tue, 28 Sep 2010 18:34:37 Z</pubDate><comments>https://blogs.u2u.be/kris/post/Safe-disposal-of-WCF-proxies#comment</comments><dc:publisher xmlns:dc="http://purl.org/dc/elements/1.1/">Kris Vandermotten</dc:publisher><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">https://blogs.u2u.be/kris/pingback.axd</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">https://blogs.u2u.be/kris/post.aspx?id=08608f9b-06a9-4e1c-b335-e01c388bb4e3</pingback:target><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">16</slash:comments><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">https://blogs.u2u.be/kris/trackback.axd?id=08608f9b-06a9-4e1c-b335-e01c388bb4e3</trackback:ping><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">https://blogs.u2u.be/kris/post/Safe-disposal-of-WCF-proxies#comment</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">https://blogs.u2u.be/kris/syndication.axd?post=08608f9b-06a9-4e1c-b335-e01c388bb4e3</wfw:commentRss></item></channel></rss>