<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Simplifying WCF: Using Exceptions as Faults</title>
	<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/</link>
	<description>Absolutes never work</description>
	<pubDate>Wed, 08 Sep 2010 21:27:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Harvo Jones</title>
		<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-3195</link>
		<dc:creator>Harvo Jones</dc:creator>
		<pubDate>Tue, 27 Jul 2010 19:38:01 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-3195</guid>
		<description>Oleg, very good stuff.  Thanks for helping us navigate the intricacies of WCF configuration.</description>
		<content:encoded><![CDATA[<p>Oleg, very good stuff.  Thanks for helping us navigate the intricacies of WCF configuration.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Unwrap WCF FaultException &#171; maonet technotes</title>
		<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-2898</link>
		<dc:creator>Unwrap WCF FaultException &#171; maonet technotes</dc:creator>
		<pubDate>Wed, 10 Feb 2010 17:04:56 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-2898</guid>
		<description>[...] other faultexception, so I don&#8217;t need investigating ExceptionMarshallingBehavior described here and [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] other faultexception, so I don&#8217;t need investigating ExceptionMarshallingBehavior described here and [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A debug only WCF Exception problem &#171; maonet technotes</title>
		<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-2690</link>
		<dc:creator>A debug only WCF Exception problem &#171; maonet technotes</dc:creator>
		<pubDate>Thu, 31 Dec 2009 16:13:26 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-2690</guid>
		<description>[...] http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/ [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] <a href="http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/" rel="nofollow">http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/</a> [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wout</title>
		<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-2545</link>
		<dc:creator>Wout</dc:creator>
		<pubDate>Wed, 16 Dec 2009 21:09:08 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-2545</guid>
		<description>Hi, thanks for the insights! I couldn't get the IErrorHandler to work still, but I did find a sneaky workaround. I've just written a post about the details (seems bl##dy .NET BCL bug): http://www.woutware.com/blog/post/Implementing-IErrorHandler-and-working-around-SerializationException.aspx

- Wout</description>
		<content:encoded><![CDATA[<p>Hi, thanks for the insights! I couldn&#8217;t get the IErrorHandler to work still, but I did find a sneaky workaround. I&#8217;ve just written a post about the details (seems bl##dy .NET BCL bug): <a href="http://www.woutware.com/blog/post/Implementing-IErrorHandler-and-working-around-SerializationException.aspx" rel="nofollow">http://www.woutware.com/blog/post/Implementing-IErrorHandler-and-working-around-SerializationException.aspx</a></p>
<p>- Wout</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike V</title>
		<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-2433</link>
		<dc:creator>Mike V</dc:creator>
		<pubDate>Tue, 10 Nov 2009 21:41:29 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-2433</guid>
		<description>FYI, your zip file appears to be missing the file "Examples.cs".</description>
		<content:encoded><![CDATA[<p>FYI, your zip file appears to be missing the file &#8220;Examples.cs&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bunty Singh</title>
		<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-1216</link>
		<dc:creator>Bunty Singh</dc:creator>
		<pubDate>Wed, 01 Apr 2009 09:37:17 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-1216</guid>
		<description>Firstly thanks for your wonderful explanation.

One wierd thing that I have noticed was, though exceptions cannot be serialized using DataContractSerializer hance the NetDataContractSerializer. However is the client throws FaulException instead of the exception i.e. instead of client throwing say ArgumentNullException if it throws FaultException, the error handler will be bypassed and the exception get serialized using the normal DataContractSerializer without any serialization exception. And at the client end you would IClientMessageInspector would throw serialization exception.</description>
		<content:encoded><![CDATA[<p>Firstly thanks for your wonderful explanation.</p>
<p>One wierd thing that I have noticed was, though exceptions cannot be serialized using DataContractSerializer hance the NetDataContractSerializer. However is the client throws FaulException instead of the exception i.e. instead of client throwing say ArgumentNullException if it throws FaultException, the error handler will be bypassed and the exception get serialized using the normal DataContractSerializer without any serialization exception. And at the client end you would IClientMessageInspector would throw serialization exception.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Carr</title>
		<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-1198</link>
		<dc:creator>Michael Carr</dc:creator>
		<pubDate>Fri, 13 Mar 2009 18:10:30 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-1198</guid>
		<description>I believe I've isolated the problem with BasicHttpBinding. The two bindings (NetTcpBinding vs BasicHttpBinding) seem to use different Fault objects when serializing faults. The NetTcpBinding uses a Fault that serializes out with a "Details" tag, while the BasicHttpBinding uses a Fault that serializes out with a "details" tag. This causes the ExceptionMarshallingMessageInspector to break when trying to locate the Details element. I modified the code as follows to fix this problem:

ExceptionMarshallingMessageInspector.cs:

40: const string detailElementName = "detail";

47: if (reader.NodeType == XmlNodeType.Element &#38;&#38; reader.LocalName.ToLower() == detailElementName)

54: if (reader.NodeType != XmlNodeType.Element &#124;&#124; reader.LocalName.ToLower() != detailElementName)</description>
		<content:encoded><![CDATA[<p>I believe I&#8217;ve isolated the problem with BasicHttpBinding. The two bindings (NetTcpBinding vs BasicHttpBinding) seem to use different Fault objects when serializing faults. The NetTcpBinding uses a Fault that serializes out with a &#8220;Details&#8221; tag, while the BasicHttpBinding uses a Fault that serializes out with a &#8220;details&#8221; tag. This causes the ExceptionMarshallingMessageInspector to break when trying to locate the Details element. I modified the code as follows to fix this problem:</p>
<p>ExceptionMarshallingMessageInspector.cs:</p>
<p>40: const string detailElementName = &#8220;detail&#8221;;</p>
<p>47: if (reader.NodeType == XmlNodeType.Element &amp;&amp; reader.LocalName.ToLower() == detailElementName)</p>
<p>54: if (reader.NodeType != XmlNodeType.Element || reader.LocalName.ToLower() != detailElementName)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-1197</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Fri, 13 Mar 2009 17:21:01 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-1197</guid>
		<description>This only seems to work with the NetTcpBinding ... not BasicHttpBinding.</description>
		<content:encoded><![CDATA[<p>This only seems to work with the NetTcpBinding &#8230; not BasicHttpBinding.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guido Govers</title>
		<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-1082</link>
		<dc:creator>Guido Govers</dc:creator>
		<pubDate>Thu, 12 Feb 2009 15:19:42 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-1082</guid>
		<description>I am trying to use this in conjunction of RESTful services using WCF, which makes use of WebHttpBindings and WebServiceHost. Using TCP will allow for soap serialization, but I cant quite figure out why I cant make this work over HTTP. Any help would be greatly appreciated.</description>
		<content:encoded><![CDATA[<p>I am trying to use this in conjunction of RESTful services using WCF, which makes use of WebHttpBindings and WebServiceHost. Using TCP will allow for soap serialization, but I cant quite figure out why I cant make this work over HTTP. Any help would be greatly appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-1017</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Thu, 22 Jan 2009 00:56:05 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/07/simplifying-wcf-using-exceptions-as-faults/#comment-1017</guid>
		<description>This code is great and it greatly simplified what were were attempting to do with our project after migrating our code to WCF from .NET Remoting.

I have found one somewhat big problem with the implementation provided in that the stack trace doesn't appear to be preserved from the server. I understand that this may actually be desirable depending on the amount of information that one desires to disclose to the client however I have found a hack that seems to be working for us in the meantime.

In the AfterReceiveReply() method of the ExceptionMarshallingMessageInspector class the following code can be changed as shown below.
______________________
object faultDetail = ReadFaultDetail(copy);
Exception exception = faultDetail as Exception;
if (exception != null)
{
    throw exception;
}
______________________

By adding a little reflection magic to the code shown above as shown below, you should then see the server stack trace.

______________________
object faultDetail = ReadFaultDetail(copy);
Exception exception = faultDetail as Exception;
if(exception != null)
{
    // NB: Error checking etc. excluded
    // Get the _remoteStackTraceString of the Exception class
    FieldInfo remoteStackTraceString = typeof(Exception).GetField(
        "_remoteStackTraceString",
        BindingFlags.Instance &#124; BindingFlags.NonPublic
        );

    // Set the InnerException._remoteStackTraceString to the current InnerException.StackTrace
    remoteStackTraceString.SetValue(
        exception,
        exception.StackTrace + Environment.NewLine
        );

    throw exception;
}
______________________

I can't take all the credit for this hack though since I found it at Chris Taylor's blog.

http://www.dotnetjunkies.com/WebLog/chris.taylor/archive/2004/03/03/8353.aspx

NOTE: With this technique you the original stack trace however it is muddied up with some of the intermediate exception marshaling code which would be nice to bypass and it appears that the proxy automatically shoves some of the client side portions of the stack trace under the "Server stack trace" section.</description>
		<content:encoded><![CDATA[<p>This code is great and it greatly simplified what were were attempting to do with our project after migrating our code to WCF from .NET Remoting.</p>
<p>I have found one somewhat big problem with the implementation provided in that the stack trace doesn&#8217;t appear to be preserved from the server. I understand that this may actually be desirable depending on the amount of information that one desires to disclose to the client however I have found a hack that seems to be working for us in the meantime.</p>
<p>In the AfterReceiveReply() method of the ExceptionMarshallingMessageInspector class the following code can be changed as shown below.<br />
______________________<br />
object faultDetail = ReadFaultDetail(copy);<br />
Exception exception = faultDetail as Exception;<br />
if (exception != null)<br />
{<br />
    throw exception;<br />
}<br />
______________________</p>
<p>By adding a little reflection magic to the code shown above as shown below, you should then see the server stack trace.</p>
<p>______________________<br />
object faultDetail = ReadFaultDetail(copy);<br />
Exception exception = faultDetail as Exception;<br />
if(exception != null)<br />
{<br />
    // NB: Error checking etc. excluded<br />
    // Get the _remoteStackTraceString of the Exception class<br />
    FieldInfo remoteStackTraceString = typeof(Exception).GetField(<br />
        &#8220;_remoteStackTraceString&#8221;,<br />
        BindingFlags.Instance | BindingFlags.NonPublic<br />
        );</p>
<p>    // Set the InnerException._remoteStackTraceString to the current InnerException.StackTrace<br />
    remoteStackTraceString.SetValue(<br />
        exception,<br />
        exception.StackTrace + Environment.NewLine<br />
        );</p>
<p>    throw exception;<br />
}<br />
______________________</p>
<p>I can&#8217;t take all the credit for this hack though since I found it at Chris Taylor&#8217;s blog.</p>
<p><a href="http://www.dotnetjunkies.com/WebLog/chris.taylor/archive/2004/03/03/8353.aspx" rel="nofollow">http://www.dotnetjunkies.com/WebLog/chris.taylor/archive/2004/03/03/8353.aspx</a></p>
<p>NOTE: With this technique you the original stack trace however it is muddied up with some of the intermediate exception marshaling code which would be nice to bypass and it appears that the proxy automatically shoves some of the client side portions of the stack trace under the &#8220;Server stack trace&#8221; section.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
