<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>WCF on Bits and Pieces</title>
		<link>https://bits.strawjackal.org/tags/wcf/</link>
		<description>Recent content in WCF on Bits and Pieces</description>
		<generator>Hugo</generator>
		<language>en-us</language>
		
		
		
		
			<lastBuildDate>Wed, 16 Aug 2006 15:28:08 +0200</lastBuildDate>
		
			<atom:link href="https://bits.strawjackal.org/tags/wcf/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Code Generation, SharedContracts and The Sneaky Bug</title>
				<link>https://bits.strawjackal.org/164/</link>
				<pubDate>Wed, 16 Aug 2006 15:28:08 +0200</pubDate>
				<guid>https://bits.strawjackal.org/164/</guid>
				<description>&lt;p&gt;A short discussion ensued today on the topic of Code Generation tools like CodeSmith. &lt;/p&gt; &lt;p&gt;Like Unit Testing, code generation is a topic that some people swear by and some reject out of hand. I&#39;m sure this is mostly a question of getting used to the concept. Only after I had used unit tests extensively in a real project could I appreciate the real value of having them - not just occasionally running some tests, or writing some cases beforehand. I&#39;m talking a full suite of automated tests that could be run nightly or as part of a continuous integration setup. But I digress.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Creating CustomBindings programatically</title>
				<link>https://bits.strawjackal.org/165/</link>
				<pubDate>Thu, 10 Aug 2006 21:49:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/165/</guid>
				<description>&lt;p&gt;I had another revelation earlier, when going over Nicholas Allen&amp;#39;s explanation of the GetProperty&lt;T&gt; method and BindingContexts:&lt;/p&gt;&lt;p&gt;The Binding objects supplied by the WCF framework are only a wrapper. They have no logic in them. They mean nothing. They do nothing except allow access to the internal properties of their BindingElements. The BindingElements are the ones who do the real work.&lt;/p&gt;&lt;p&gt;There. It&amp;#39;s a bit harsh, but it had to be said. Took me a while to wrap my head around it. It&amp;#39;s syntactic sugar, since it&amp;#39;s easier to do this:&lt;/p&gt;</description>
			</item>
			<item>
				<title>WCF: Navigating the Binding maze</title>
				<link>https://bits.strawjackal.org/167/</link>
				<pubDate>Mon, 07 Aug 2006 07:24:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/167/</guid>
				<description>&lt;p&gt;A few days ago I &lt;a href=&#34;../../avnerk/archive/2006/07/31/WCF-and-Non_2D00_polymorphic-bindings_2C00_-_3C00_small_3E00_or-How-to-write-an-incomprehensible-post-title_3C002F00_small_3E00_.aspx&#34;&gt;ranted&lt;/a&gt; a bit about the Binding object model in WCF and how restrictive it feels when I want to imperatively describe my service bindings without being tied down to a specific transport. If I want to disable security or set the maximum allowed size per field in a message, I have to write identical-looking code for each different binding - something that just begs for refactoring which can&amp;#39;t be done.&lt;/p&gt;</description>
			</item>
			<item>
				<title>WCF Serialization Part 2d: A Solution, a Conclusion and a Contribution</title>
				<link>https://bits.strawjackal.org/168/</link>
				<pubDate>Thu, 03 Aug 2006 13:23:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/168/</guid>
				<description>&lt;p&gt;This is the last part of my continuing saga of serializing dictionaries over WCF and beyond.&lt;/p&gt;&lt;p&gt;Quick recap: While WCF allows me to serialize an IDictionary easily, trying to serialize that dictionary later for other uses fails - specifically, caching it to disk using the Enterprise Library. This is because the Enterprise Library relies on the BinaryFormatter, which in turns relies on the type implementing ISerializable. An alternate solution was to use the NameValueCollection which implements ISerializable, but is incompatible with WCF&amp;#39;s serialization.&lt;/p&gt;</description>
			</item>
			<item>
				<title>WCF Serialization Part 2c: Hacking the NameValueCollection (unsuccesfully)</title>
				<link>https://bits.strawjackal.org/169/</link>
				<pubDate>Wed, 02 Aug 2006 13:28:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/169/</guid>
				<description>&lt;p style=&#34;margin: 0in 0in 0pt; direction: ltr; unicode-bidi: embed; text-align: left&#34; dir=&#34;ltr&#34; class=&#34;MsoNormal&#34;&gt;&lt;span style=&#34;font-family: Verdana&#34;&gt;&lt;font size=&#34;3&#34;&gt;As we mentioned &lt;/font&gt;&lt;a href=&#34;../../avnerk/archive/2006/08/02/WCF-Serialization-Part-2_3A00_-NameValueCollection-Denied_2100_.aspx&#34;&gt;&lt;font size=&#34;3&#34;&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size=&#34;3&#34;&gt; and &lt;/font&gt;&lt;a href=&#34;../../avnerk/archive/2006/08/02/WCF-Serialization-Part-2b_3A00_-WCF-Collection-Serialization.aspx&#34;&gt;&lt;font size=&#34;3&#34;&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size=&#34;3&#34;&gt;, I&amp;#39;ve been struggling to get the NameValueCollection object to pass through WCF serialization. Please read the first two posts first for some context.&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&#34;margin: 0in 0in 0pt; direction: ltr; unicode-bidi: embed; text-align: left&#34; dir=&#34;ltr&#34; class=&#34;MsoNormal&#34;&gt;&lt;span style=&#34;font-family: Verdana&#34;&gt;&lt;font size=&#34;3&#34;&gt; &lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&#34;margin: 0in 0in 0pt; direction: ltr; unicode-bidi: embed; text-align: left&#34; dir=&#34;ltr&#34; class=&#34;MsoNormal&#34;&gt;&lt;span style=&#34;font-family: Verdana&#34;&gt;&lt;font size=&#34;3&#34;&gt;In the previous episodes, we saw that we can&amp;#39;t get WCF to serialize the NameValueCollection (NVC, from now on) because it incorrectly marked for its CollectionDataContract serialization, but then choked because it had no Add(object) method.&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;</description>
			</item>
			<item>
				<title>WCF Serialization Part 2b: WCF Collection Serialization</title>
				<link>https://bits.strawjackal.org/170/</link>
				<pubDate>Wed, 02 Aug 2006 13:25:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/170/</guid>
				<description>&lt;p style=&#34;margin: 0in 0in 0pt; direction: ltr; unicode-bidi: embed; text-align: left&#34; class=&#34;MsoNormal&#34;&gt;&lt;span style=&#34;font-family: Verdana&#34;&gt;&lt;font size=&#34;3&#34;&gt;As we mentioned &lt;/font&gt;&lt;a href=&#34;../../avnerk/archive/2006/08/02/WCF-Serialization-Part-2_3A00_-NameValueCollection-Denied_2100_.aspx&#34;&gt;&lt;font size=&#34;3&#34;&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size=&#34;3&#34;&gt;, I&amp;#39;m currently struggling with getting WCF to serialize my NameValueCollection object on a service operation. The previous post goes over the general details, while here I&amp;#39;ll dive a bit deeper. It&amp;#39;s recommended to read the first part before continuing.&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&#34;margin: 0in 0in 0pt; direction: ltr; unicode-bidi: embed; text-align: left&#34; class=&#34;MsoNormal&#34;&gt;&lt;span style=&#34;font-family: Verdana&#34;&gt;&lt;font size=&#34;3&#34;&gt; &lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&#34;margin: 0in 0in 0pt; direction: ltr; unicode-bidi: embed; text-align: left&#34; class=&#34;MsoNormal&#34;&gt;&lt;span style=&#34;font-family: Verdana&#34;&gt;&lt;font size=&#34;3&#34;&gt;I don&amp;#39;t know exactly the logic that goes in the WCF serialization engine to determine what data contract will be selected for serialization.. I tried wading in with Reflector but got a bit lost. I managed to track down some interesting places, though. Both in the System.Runtime.Serialization assembly:&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;</description>
			</item>
			<item>
				<title>WCF Serialization Part 2a: NameValueCollection Denied!</title>
				<link>https://bits.strawjackal.org/171/</link>
				<pubDate>Wed, 02 Aug 2006 12:40:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/171/</guid>
				<description>&lt;div style=&#34;font-size: 12pt; font-family: Verdana&#34;&gt;&lt;p&gt;As we all &lt;a href=&#34;../../avnerk/archive/2006/05/23/Serilalizing-Dictionaries.aspx&#34;&gt;know&lt;/a&gt;, IDictionaries aren&amp;#39;t serializable. This is has been a cause of much concern and consternation throughout the years. Throughout these trying times, however, we had one shining beacon in the night - the NameValueCollection in the System.Collections.Specialized namespace was a completely serializable implementation of a string/string dictionary. Used by the framework for everything from configuration settings to ASP query strings.&lt;/p&gt;&lt;p&gt;Now WCF comes along, and with it much &lt;a href=&#34;http://blogs.msdn.com/sowmy/archive/2006/02/22/536747.aspx&#34;&gt;serialization goodness&lt;/a&gt;, including the ability to easily serialize IDictionaries over the wire. While this is extremely convenient, we have to remember that IDictionaries are still not really serializable - they&amp;#39;re just special-cased in WCF. This means that if we want to transfer a dictionary over the wire and then persist it to disk (using the Caching Application Block, for instance) we&amp;#39;re still out of luck. &lt;/p&gt;</description>
			</item>
			<item>
				<title>WCF Serialization part 1: Interfaces, Base classes and the NetDataContractFormatSerializer</title>
				<link>https://bits.strawjackal.org/172/</link>
				<pubDate>Mon, 31 Jul 2006 14:46:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/172/</guid>
				<description>&lt;p&gt;One of WCF&amp;#39;s goals is interoperability with standard protocol stacks, like WSE or other WS-* implementations. This led, I am told, to the design of WCF&amp;#39;s default object serializer - the DataContractFormatSerializer. This &lt;a href=&#34;http://blogs.msdn.com/sowmy/archive/2006/02/22/536747.aspx&#34;&gt;handy little engine&lt;/a&gt; serializes primitive types, common objects, enums, Collections and anything that implements IXmlSerializable or ISerializable, giving us a much nicer out-of-the-box-and-over-the-wire experience for our objects. &lt;/p&gt;&#xD;&#xA;&lt;p&gt;Because of the aforementioned design goal, however, it has one little problem - the serialized data it generates does not contain information about the .NET CLR type from which this data was serialized. This makes sense when you have interoperability in mind - the datatypes you pass should be described in your service metadata, such as WSDL, and not rely on an implementation detail like the CLR type itself.&lt;/p&gt;</description>
			</item>
			<item>
				<title>WCF and Non-polymorphic bindings</title>
				<link>https://bits.strawjackal.org/173/</link>
				<pubDate>Mon, 31 Jul 2006 06:06:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/173/</guid>
				<description>&lt;p style=&#34;margin: 0in 0in 0pt; direction: ltr; unicode-bidi: embed; text-align: left&#34; dir=&#34;ltr&#34; class=&#34;MsoNormal&#34;&gt;&lt;span style=&#34;font-size: 10pt; font-family: Arial&#34;&gt;I&amp;#39;ve been using WCF for the past few months and on the whole, I think the programming model works. I&amp;#39;m getting to really like the &lt;a href=&#34;../../avnerk/archive/2006/04/26/444013.aspx&#34; target=&#34;_blank&#34;&gt;&lt;span&gt;extensibility model&lt;/span&gt;&lt;/a&gt; and the whole deal seems to click rather well. One place where I feel it&amp;#39;s a bit broken, though, is around the object model for Bindings. &lt;/span&gt;&lt;/p&gt;&lt;p style=&#34;margin: 0in 0in 0pt; direction: ltr; unicode-bidi: embed; text-align: left&#34; dir=&#34;ltr&#34; class=&#34;MsoNormal&#34;&gt; &lt;/p&gt;</description>
			</item>
			<item>
				<title>My Singleton is disappearing!</title>
				<link>https://bits.strawjackal.org/181/</link>
				<pubDate>Mon, 19 Jun 2006 14:29:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/181/</guid>
				<description>&lt;P&gt;WCF&#39;s Instance Context model allows me to specify my service&#39;s instantiation behavior - I can get a new instance for every call, have WCF manage a session for me and keep an instance per session, or just get lazy and have my service instantiated as a singleton object and use the same instance forever and ever. Juval Lowy covered the basics of these features &lt;A href=&#34;http://msdn.microsoft.com/msdnmag/issues/06/06/WCFEssentials/default.aspx&#34;&gt;here&lt;/A&gt;. &lt;/P&gt;&#xD;&#xA;&lt;P&gt;I had a Singleton service defined, exposing several Operations through two different endpoints. After some testing, I noticed that every time a call was received on one of the interfaces the constructor would be called again - my singleton was getting dumped and recreated.&lt;/P&gt;&#xD;&#xA;&lt;P&gt;It turns out the operation that was causing the problems was marked like this:&lt;/P&gt;&#xD;&#xA;&lt;P&gt;&lt;FONT face=&#34;Courier New&#34;&gt;[&lt;FONT color=#008080 size=2&gt;OperationBehavior&lt;/FONT&gt;&lt;FONT size=2&gt;(TransactionScopeRequired = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;true&lt;/FONT&gt;&lt;FONT size=2&gt;, TransactionAutoComplete = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;true&lt;/FONT&gt;&lt;FONT size=2&gt;)]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&#xD;&#xA;&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT size=3&gt;Since the transaction behavior was the only lead I had, I started to look into it and checked out the other properties of the OperationBehavior attributes. I found the following attribute: (Warning: Links point to a local MSDN installation)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&#xD;&#xA;&lt;P&gt;&#xD;&#xA;&lt;TABLE class=memberListTable cellSpacing=2 cellPadding=5 width=&#34;100%&#34;&gt;&#xD;&#xA;&lt;TBODY&gt;&#xD;&#xA;&lt;TR vAlign=top notSupportedOn=&#34;netcf&#34;&gt;&#xD;&#xA;&lt;TD class=imageCell&gt;&lt;/IMG&gt;&lt;/TD&gt;&#xD;&#xA;&lt;TD&gt;&#xD;&#xA;&lt;BLOCKQUOTE dir=ltr style=&#34;MARGIN-RIGHT: 0px&#34;&gt;&#xD;&#xA;&lt;P&gt;&lt;A href=&#34;ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.WinFX4VS.1033/cpref20/html/P_System_ServiceModel_OperationBehaviorAttribute_ReleaseInstanceMode.htm&#34;&gt;&lt;FONT face=Verdana size=2&gt;ReleaseInstanceMode&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/TD&gt;&#xD;&#xA;&lt;TD&gt;&#xD;&#xA;&lt;BLOCKQUOTE dir=ltr style=&#34;MARGIN-RIGHT: 0px&#34;&gt;&#xD;&#xA;&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Gets or sets a value that indicates when in the course of an operation invocation to recycle the service object.&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/FONT&gt;This operation allows me to declaratively tell WCF to drop my current instance before, after or before AND after my call. This is to allow stateless service calls to ensure that they will not carry over any state between operations. Unfortunately, the default value for the ReleaseInstanceMode is None - this wasn&#39;t the reason I lost my instance.&lt;/P&gt;&#xD;&#xA;&lt;P&gt;The MSDN documentation for ReleaseInstanceMode, however, mentioned the following tidbit of information:&lt;/P&gt;&#xD;&#xA;&lt;BLOCKQUOTE dir=ltr style=&#34;MARGIN-RIGHT: 0px&#34;&gt;&#xD;&#xA;&lt;P&gt;&lt;FONT face=Verdana size=2&gt;In transaction scenarios, the &lt;B&gt;ReleaseInstanceMode&lt;/B&gt; property is often used to ensure that old data associated with the service object is cleaned up prior to processing a method call. You can also ensure that service objects associated with transactions are recycled after the transaction successfully completes by setting the &lt;/FONT&gt;&lt;A href=&#34;ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.WinFX4VS.1033/cpref20/html/P_System_ServiceModel_ServiceBehaviorAttribute_ReleaseServiceInstanceOnTransactionComplete.htm&#34;&gt;&lt;FONT face=Verdana size=2&gt;ReleaseServiceInstanceOnTransactionComplete&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; property to &lt;B&gt;true&lt;/B&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&#xD;&#xA;&lt;P dir=ltr&gt;This led me to the ServiceBehavior&#39;s ReleaseServiceInstanceOnTransactionComplete property which set a more general setting that automatically recycled my service instance whenever a transaction completed successfully. Unlike the ReleaseInstanceMode property, this one is by default set to True, meaning that my transactional operation always released my Singleton instance after each successful run.&lt;/P&gt;&#xD;&#xA;&lt;P dir=ltr&gt;The moral of the story? The usual. Always check default values, especially on WCF&#39;s Behavior attributes that have lots and lots of properties. Good luck.&lt;/P&gt;</description>
			</item>
			<item>
				<title>Context-Bound Thread Queuer - FunFun.</title>
				<link>https://bits.strawjackal.org/192/</link>
				<pubDate>Fri, 19 May 2006 16:12:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/192/</guid>
				<description>&lt;p class=&#34;MsoNormal&#34; dir=&#34;ltr&#34; style=&#34;text-align: left; direction: ltr; unicode-bidi: embed;&#34;&gt;As I mentioned in my previous post, I have a need to consistently pass an operation context to any thread I choose to spin. Doing so manually, as I did here, involves a lot of ugly, repetitive code for every thread. A lot of room for mistakes and bugs. &lt;br /&gt;So using the power that .NET delegates give us, I&#39;ve built a generic Context-bound threadpool queue class to wrap this logic for me.&lt;o:p&gt; &lt;br /&gt;&lt;/o:p&gt;&lt;/p&gt;</description>
			</item>
			<item>
				<title>OperationContext is ThreadStatic</title>
				<link>https://bits.strawjackal.org/193/</link>
				<pubDate>Thu, 18 May 2006 14:29:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/193/</guid>
				<description>&lt;p&gt;WCF Services tend to be big, heavy duty things. When I write a service I often want it to do a lot of work for a lot of clients, and it should do it efficiently. This usually means that I will use multithreaded code to get things done concurrently. Whether using the ThreadPool or instantiating a thread of my own, I expect this is a common scenario for WCF service writers. &lt;br /&gt;&lt;br /&gt;That&amp;rsquo;s why I was suprised today to find out that the OperationContext of the current service call, our entry point for getting context information about the current call, its headers and so forth - is marked as [ThreadStatic]. This means that the moment I fork off to another thread, I lose all context information. If I want it available, I have to do it myself. &lt;br /&gt;&lt;br /&gt;I don&amp;rsquo;t know how ASP.NET deals with this problem. If I spin a new thread under ASP.NET, I don&amp;rsquo;t lose my current HttpContext. A quick glance with Reflector shows that there&amp;rsquo;s no [ThreadStatic] anywhere. Whatever features of IIS they use there, it&amp;rsquo;s probably unavailable for WCF, so we have to do it manually. &lt;br /&gt;&lt;br /&gt;The simplest way to pass the context to a thread is just to send it as a parameter: &lt;br /&gt;&lt;br /&gt;&lt;font face=&#34;Courier New&#34; size=&#34;2&#34;&gt;void Method () &lt;br /&gt;{ &lt;br /&gt;    ThreadPool.QueueUserWorkItem(ThreadMethod, OperationContext.Current); &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void ThreadMethod(object state) &lt;br /&gt;{ &lt;br /&gt;    OperationContext.Current = state as OperationContext; &lt;br /&gt;    // Do whatever. &lt;br /&gt;}&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Side note: Note the automatic delegate inference that .NET 2.0 does, rather than forcing me to manually create a WaitCallback delegate: &lt;br /&gt;&lt;font face=&#34;&#39;Courier New&#39;,Courier,monospace&#34;&gt;ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadMethod), OperationContext.Current);&lt;/font&gt; &lt;br /&gt;I don&amp;rsquo;t think this was possible in v1.1.&lt;/i&gt; &lt;br /&gt;&lt;br /&gt;If we want to spin a thread of our own, we can use the ParameterizedThreadStart delegate: &lt;br /&gt;&lt;br /&gt;&lt;font face=&#34;Courier New&#34;&gt;void Method () &lt;br /&gt;{ &lt;br /&gt;    Thread t = new Thread(new ParameterizedThreadStart(ThreadMethod), OperationContext.Current); &lt;br /&gt;    t.Start(); &lt;br /&gt;} &lt;/font&gt;&lt;br /&gt;&lt;br /&gt; If we have parameters to pass to our method, though, we need to be even hackier - maybe define a struct or class to hold our OperationContext as well as the custom parameters, and pass that on to the ThreadMethod and have it disassemble it. &lt;br /&gt;&lt;br /&gt;There is a better way to build a Thread Launcher than can pass the ObjectContext. I&amp;rsquo;ll elaborate on that in my next post.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Share your interfaces - avoid static proxies.</title>
				<link>https://bits.strawjackal.org/194/</link>
				<pubDate>Wed, 17 May 2006 12:24:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/194/</guid>
				<description>&lt;p&gt;When using WCF services, we have several options for creating the proxies. We can create them statically using SVCUTIL or the build-in IDE support (Add Service Reference&amp;hellip;), or we can generate them dynamically using the ChannelFactory&lt;T&gt; or &lt;a href=&#34;http://blogs.microsoft.co.il/blogs/bursteg/archive/2006/04/17/103.aspx&#34;&gt;GenericProxy&lt;T&gt;&lt;/a&gt; approaches.&lt;br /&gt;&lt;br /&gt;The advantage of the static proxy approach is that it we local code for us based on remote metadata (WSDL). Even if the service is somewhere out of our reach and control, all we need is for it to expose metadata for us to access it. We get a copy of the service contract and interfaces and we&amp;rsquo;re good to go. &lt;br /&gt;The problems with it is that I have to maintain that proxy. If the service changes, our proxy needs to adapt too. I&amp;rsquo;m not referring to versioning issues and new methods added, but to big changes in the service contract itself. This may not be an issue when accessing stable services, but certainly happens a lot during development.&lt;br /&gt;&lt;br /&gt;The second approach is much more limited - for it to work we need to have a reference to a shared assembly containing the contracts. It means our services and contracts are .NET classes using the WCF framework, rather than generic WS-* services that can have any implementation. This approach is only useful when we have access to the our services&amp;rsquo; code or assemblies, so it&amp;rsquo;s out of the question for public services. &lt;br /&gt;In short, the dynamic proxy approach is only for use when we control both client and server in the scope of a single application (or group of familiar applications).&lt;br /&gt;&lt;br /&gt;But in this context, this is &lt;b&gt;the&lt;/b&gt; best way to work. I&amp;rsquo;ll stress the point again - if we meet all the criteria above for using dynamic proxies, we should use them without hesitation.&lt;br /&gt;The amount of work that goes into maintaining the static proxies, making sure that the client and server copies of the contracts are identical, hours of debugging mysterious errors caused by contract mismatches - all with perplexing error messages and little documentation - all these things are simply not worth it.&lt;br /&gt;&lt;br /&gt;I&amp;rsquo;ll say it again - if you&amp;rsquo;re writing an N-tier application that uses WCF for communication, have the contracts shared by both client and server and use the GenericProxy&lt;T&gt; class to access it rather than relying on generated proxies and SVCUTIL. Trust me. Your deadline will thank you for it.&lt;br /&gt;&lt;/p&gt;</description>
			</item>
			<item>
				<title>Deperplexing WCF errors pt. 3 - Interfaces and KnownTypes</title>
				<link>https://bits.strawjackal.org/195/</link>
				<pubDate>Tue, 16 May 2006 13:40:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/195/</guid>
				<description>&lt;p&gt;Another error message that stumped me today (after I had removed the &lt;A href=&#34;http://weblogs.asp.net/avnerk/archive/2006/05/16/446673.aspx&#34;&gt;IsOneWay&lt;/a&gt; parameter and actually got to see it) was the following exception:&lt;br /&gt;&lt;font size=&#34;2&#34;&gt;&lt;b&gt;&lt;br /&gt;&lt;font face=&#34;Verdana&#34;&gt;System.ServiceModel.CommunicationException&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/font&gt;&lt;span style=&#34;font-size: 12pt; font-family: &#34; new=&#34;&#34; roman=&#34;&#34;&gt;&lt;font face=&#34;Verdana&#34; size=&#34;2&#34;&gt;The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;This little gem was caused when calling a method on a service with an interface as a parameter, something like this:&lt;br /&gt;&lt;br /&gt;&lt;font face=&#34;Courier New&#34; size=&#34;2&#34;&gt;[OperationContract]&lt;br /&gt;void DoSomething (IMessage message)&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;When deserializing the IMessage, WCF had no way of knowing what type to deserialize it as, so it through the charming message above.&lt;br /&gt;I don&amp;rsquo;t know how this situation came to be, since the proxy generated by svcutil seems to create the message as DoSomething(object message) and not IMessage, but the principle should be the same.&lt;br /&gt;&lt;br /&gt;The immediate solution that fixed this was adding the [KnownType(typeof(myMessage))] attribute to the method. This allows the deserialization engine to understand the message and do something constructive with it rather than crashing.&lt;br /&gt;&lt;br /&gt;Naturally, I am less than pleased with this solution. The whole purpose of using interfaces is that I won&amp;rsquo;t have to know, when coding, what objects will be passed to my service. I just want to expose the interface.&lt;br /&gt;&lt;br /&gt;One way to keep this flexibility can be found in the very last paragraph of the long and detailed &lt;a href=&#34;http://windowssdk.msdn.microsoft.com/library/default.asp?url=../../library/en-us/wcf_con/html/1a0baea1-27b7-470d-9136-5bbad86c4337.asp&#34;&gt;Data Contract Known Types&lt;/a&gt; article on MSDN - it seems that the list of Known Types can be defined globally in the system using the &amp;lt;system.runtime.serialization&amp;gt; section in the config file. Details about that are also sparse, and I&amp;rsquo;m not at all sure if it&amp;rsquo;s possible in the January CTP - the section names seem to have changed from &lt;xmlformatter&gt; to &lt;datacontractserializer&gt; between January and February, and there are no samples to explain the proper structure for the January version. I hope this gets clearer with the next beta.&lt;br /&gt;&lt;/span&gt;&lt;span style=&#34;font-size: 12pt; font-family: &#34; new=&#34;&#34; roman=&#34;&#34;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;</description>
			</item>
			<item>
				<title>Deperplexing WCF errors pt. 2 - IsOneWay swallowing exceptions</title>
				<link>https://bits.strawjackal.org/196/</link>
				<pubDate>Tue, 16 May 2006 12:28:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/196/</guid>
				<description>&lt;p&gt;The first step in understanding WCF error messages is making sure you actually get them.&lt;br /&gt;&lt;br /&gt;You can have an OperationContract defined with the IsOneWay parameter set to True, thus optimizing it by not requiring a reply message. &lt;br /&gt;Since faults and exceptions are represented as replies to the message sent, however, setting IsOneWay to true will cause WCF to simply swallow the exception and not report it - as far as the framework is concerned the message was sent successfully and that&amp;rsquo;s it.&lt;br /&gt;&lt;br /&gt;If you want to use the IsOneWay optimization, it&amp;rsquo;s best to save it for later parts of development, after the basic debugging work is done.&lt;br /&gt;&lt;/p&gt;</description>
			</item>
			<item>
				<title>Deperplexing WCF errors pt. 1 - CommunicationObjectAbortedException for security mismatch</title>
				<link>https://bits.strawjackal.org/197/</link>
				<pubDate>Mon, 15 May 2006 10:03:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/197/</guid>
				<description>&lt;p&gt;As a follow-up to this &lt;A href=&#34;http://weblogs.asp.net/avnerk/archive/2006/05/08/445599.aspx&#34;&gt;post&lt;/a&gt;: another reason why we get CommunicationObjectAbortedExceptions is because our client channel definition does not send any credentials (using a binding that has the SecurityMode set to None) while the service is still set to the default settings, expecting Windows authentication. Rather than throwing some sort of SecurityException, the exception is raised. &lt;br /&gt;Just a heads up.&lt;br /&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;/p&gt;</description>
			</item>
			<item>
				<title>Indigo Errors Perplexing</title>
				<link>https://bits.strawjackal.org/199/</link>
				<pubDate>Mon, 08 May 2006 12:06:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/199/</guid>
				<description>&lt;p&gt;I was writing a very simple WCF service. Nothing fancy - just returning an array of structs via TCP, just like 3 others already implemented. Started testing, stepped through the server code, returned the value from the service interface, then WHAM - a big scary exception:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;System.ServiceModel.CommunicationObjectAbortedException&lt;/b&gt;&lt;br /&gt;The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue.&lt;br /&gt;&lt;br /&gt;Inner Exception: &lt;br /&gt;&lt;b&gt;System.Net.SocketException&lt;/b&gt;&lt;br /&gt;An existing connection was forcibly closed by the remote host&lt;br /&gt;&lt;br /&gt;This rather scary error message is not very helpful. Was it because of a timeout? (Unlikely, as it happened immediately). Underlying network resource issue? Happens too predictably. Error processing your message? What does that mean, anyway? WHAT error processing my message? And anyway, the inner SocketException seems to imply that it&amp;rsquo;s a network error, not a message error.&lt;br /&gt;&lt;br /&gt;But of course it is. WCF didn&amp;rsquo;t really point me towards it, but it seems I had forgotten to mark my struct as a [DataContract] and its members as [DataMember]s. No contract, nothing to serialize, no message. &lt;br /&gt;&lt;br /&gt;Perfectly understandable, once you know what&amp;rsquo;s going on. Totally perplexing until you do.&lt;br /&gt;&lt;font size=&#34;1&#34;&gt;&lt;br /&gt;&lt;/font&gt;&lt;font size=&#34;1&#34;&gt;Now let&amp;rsquo;s give this entry some Googlejuice so people who are experiencing this problem can find it: &lt;br /&gt;&lt;i&gt;WCF, Indigo, CommunicationObjectAbortedException,  SocketException, DataContract.&lt;/i&gt;&lt;br /&gt;There. That should do it. &lt;/font&gt;&lt;br /&gt;&lt;/p&gt;</description>
			</item>
			<item>
				<title>Adding custom headers to every WCF call - a solution</title>
				<link>https://bits.strawjackal.org/204/</link>
				<pubDate>Wed, 26 Apr 2006 08:20:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/204/</guid>
				<description>&lt;p&gt;At last, a solution presented itself. While I must admit that at first I was very skeptical of the extensibilty model for WCF which seemed far too involved and complicated, but after implementing a simple extension I must say it&amp;rsquo;s simple and quite intuitive.&lt;br /&gt;&lt;br /&gt;My goal was to have several custom headers added to each call made through a proxy, rather than manually adding them to each call&amp;rsquo;s OperationContext. With a little help from &lt;a href=&#34;http://blogs.msdn.com/ralph.squillace/&#34;&gt;Ralph Squillace&amp;rsquo;s blog&lt;/a&gt;, I was able to get an extension up and running within minutes, and it Just Works.&lt;br /&gt;&lt;br /&gt;The first item to build is the actual extension logic. In this case, I needed an IProxyMessageInspector object that inspects each outgoing message and adds the custom headers:&lt;br /&gt;&lt;br /&gt;&lt;font face=&#34;Courier New&#34; size=&#34;2&#34;&gt;public class ContextPusher : IProxyMessageInspector&lt;br /&gt;    {&lt;br /&gt;        public void AfterReceiveReply(ref Message reply, object correlationState)&lt;br /&gt;        {&lt;br /&gt;            // Do nothing.&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public object BeforeSendRequest(ref Message request, IClientChannel channel)&lt;br /&gt;        {&lt;br /&gt;            MessageHeader myHeader = new MessageHeader&lt;string&gt;(&amp;ldquo;HeaderValue&amp;rdquo;).GetUntypedHeader(&amp;ldquo;MyHeader&amp;rdquo;, &amp;ldquo;ns&amp;rdquo;);&lt;br /&gt;            request.Headers.Add(&lt;/font&gt;&lt;font face=&#34;Courier New&#34; size=&#34;2&#34;&gt;myHeader&lt;/font&gt;&lt;font face=&#34;Courier New&#34; size=&#34;2&#34;&gt;);&lt;br /&gt;            return null; &lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;Now we want to attach that inspector to proxy. We do that wth Behavior objects. This can be done on an operation-by-operation basis or for all operations on a given channel. We can make the same class implement both behaviors, for flexibility:&lt;br /&gt;&lt;br /&gt;&lt;font face=&#34;Courier New&#34; size=&#34;2&#34;&gt;public class CallContextAttribute : Attribute, IChannelBehavior, IOperationBehavior&lt;br /&gt;    {&lt;br /&gt;        #region IOperationBehavior Members&lt;br /&gt;&lt;br /&gt;        public void ApplyBehavior(OperationDescription description, ProxyOperation proxy, BindingParameterCollection parameters)&lt;br /&gt;        {       &lt;br /&gt;            // Add my MessageInspector to each message sent by the proxy.&lt;br /&gt;            proxy.Parent.MessageInspectors.Add(new ContextPusher());&lt;br /&gt;   &lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public void ApplyBehavior(OperationDescription description, DispatchOperation dispatch, BindingParameterCollection parameters)&lt;br /&gt;        {&lt;br /&gt;            // No server-side behaviors for now.&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        #endregion&lt;br /&gt;                &lt;br /&gt;        #region IChannelBehavior Members&lt;br /&gt;&lt;br /&gt;        public void ApplyBehavior(ChannelDescription description, ProxyBehavior behavior, BindingParameterCollection parameters)&lt;br /&gt;        {&lt;br /&gt;            // Add the MessageInspector to every message sent through the channel.&lt;br /&gt;            behavior.MessageInspectors.Add(new ContextPusher());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        #endregion&lt;br /&gt;    }&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;And then simply put it on a Service or Operation.&lt;br /&gt;I think in this case, putting the attribute on both will result in an error when trying to add duplicate headers. But this allows me flexibility in adding the headers only to certain calls.&lt;br /&gt;&lt;br /&gt;&lt;font face=&#34;Courier New&#34; size=&#34;2&#34;&gt;[ServiceContract]&lt;br /&gt;[CallContext]&lt;br /&gt;public interface ILocalizationServices&lt;br /&gt;{&lt;br /&gt;   [OperationContract]&lt;br /&gt;   [CallContext]&lt;br /&gt;   string DoSomething(string param);&lt;br /&gt;}&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;I think this is the first time I got really excited by the WCF framework and the ease of using and extending it. This is FUN.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;</description>
			</item>
			<item>
				<title>How do I add a custom header to every WCF message?</title>
				<link>https://bits.strawjackal.org/205/</link>
				<pubDate>Tue, 25 Apr 2006 12:10:00 +0200</pubDate>
				<guid>https://bits.strawjackal.org/205/</guid>
				<description>&lt;p&gt;One thing I still haven&amp;rsquo;t managed to do is create my proxy in such a way that a custom header is added to every call that is made through that proxy. &lt;br /&gt;Currently, this is done by instantiating a new OperationContext around each call through the proxy. This can be optimized in several ways:&lt;br /&gt;1) Create a shared OperationContext object and always instatiate the OperationContextScope with it:&lt;br /&gt;&lt;font face=&#34;Courier New&#34; size=&#34;2&#34;&gt;using (OperationContextScope scope = new     &lt;br /&gt;            OperationContextScope(standardContextObject))&lt;br /&gt;{&lt;br /&gt;   &amp;hellip;&lt;br /&gt;}&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;I don&amp;rsquo;t know if it&amp;rsquo;s a good idea, though. Should OperationContext objects be persisted between calls, or would it have unexpected side effects?&lt;br /&gt;&lt;br /&gt;2) Create a wrapper around the OperationContextScope class that fills the OperationContext with the proper headers:&lt;br /&gt;&lt;br /&gt;&lt;font face=&#34;Courier New&#34; size=&#34;2&#34;&gt;public class MyOperationContextScope : IDisposable&lt;br /&gt;{&lt;br /&gt;   OperationContextScope contextScope;&lt;br /&gt;&lt;br /&gt;   public MyOperationContextScope ()&lt;br /&gt;   {&lt;br /&gt;      contextScope = new OperationContextScope();&lt;br /&gt;      MessageHeader standardHeader = new    &lt;br /&gt;      MessageHeader&lt;string&gt;(&amp;ldquo;StringHeaderValue&amp;rdquo;).GetUntypedHeader(&amp;ldquo;StringHeader&amp;rdquo;, &amp;ldquo;ns&amp;rdquo;);&lt;br /&gt;      OperationContext.Current.OutgoingMessageHeaders.Add(standardHeader );&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void Dispose()&lt;br /&gt;    {&lt;br /&gt;      if (contextScope != null)&lt;br /&gt;      {&lt;br /&gt;          contextScope.Dispose();&lt;br /&gt;      }&lt;br /&gt;    }      &lt;br /&gt; }&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;This is a bit cleaner, but still requires me to wrap every proxy call with a using() statement.&lt;br /&gt;&lt;br /&gt;Is there a way to interecept all calls and have my headers added automatically?&lt;br /&gt;&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
