A Proxy Proxy Factory
I have a system that sometimes uses a fast local object and sometimes needs to communicate over a network. I have built a proxy object that wraps the proxy factory for creating typed proxies together with a proxy factory for creating local objects. Are there any downsides to this strategy?
Historically, there have been a number of attempts to hide whether objects are local or remote from programmers. These attempts have had varying degrees of success. Ultimately, the sticky issue is that it's difficult to prevent network abstractions from leaking. A leaky abstraction allows the environmental details that the abstraction is supposed to be hiding surface into the calling code. Like a leaky basement, a leaky abstraction can lay in wait for a long time before you realize that it's a problem.
Problems with leaky abstractions show up when the abstraction author tries to make the surface layer completely seamless. Programmers love seamless abstractions because it makes their code very simple. However, implementers haven't yet figured out how to make any interesting abstraction be truly seamless.
WCF attempts to deal with this issue by defining standard behaviors for channels. These standard behaviors are an escape valve so that when the abstraction leaks, it can leak in a controlled manner. For example, channels allow almost any operation to fail but restrict the exception types that the implementer can use and gives those types particular meanings. Or, channels require the programmer specify timeouts and quotas even when the application would rather trust the other side to behave. Or, and this is the most relevant one to the original question, channels require that the sender and receiver decouple their view of message data.
Decoupling the sender and receiver means that there can be no way for the sender to modify the receiver's view of the data after a message is sent. In practical terms, achieving this decoupling requires that the data almost always be copied even when using direct object calls. While you can shortcut a lot of things with local objects, the system can't guarantee the abstraction if you bypass channels. There's not a big speed difference between a channel optimized for local communication and a local object that obeys all of the channel rules. Another way of saying that is that channels are extremely cheap if they don't have underlying network resources. There's currently no channel truly optimized for local communication although the named pipe channel turns out to be good enough for most people.
Note: I don't actually remember whether the question was about building a proxy proxy factory or a proxy factory factory. The original question had too many levels of indirection to keep track of. It doesn't really change the answer whether it's a proxy or a factory for proxy factories.
Next time: Finding Data in Client Certificates
Comments
Anonymous
January 28, 2008
"There's currently no channel truly optimized for local communication" So what are your thoughts on the NullTranport for WCF? I realize this isn't the eventual official solution from Microsoft, but if you didn't work for Microsoft, would you use it? http://www.codeproject.com/KB/WCF/NullTransportForWCF.aspxAnonymous
January 28, 2008
How do I add custom annotations to the contracts that are generated from WSDL? You first need to startAnonymous
January 28, 2008
Hi Oran, I haven't looked at the code for the transport but the basic idea appears to be sound. It's actually possible to optimize local message delivery even a bit more.