<?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>Scienco.org &#187; web services</title>
	<atom:link href="http://www.scienco.org/tag/web-services/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scienco.org</link>
	<description>Life&#039;s too short to be unenthusiastic</description>
	<lastBuildDate>Wed, 14 Jul 2010 19:06:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
	<atom:link rel="next" href="http://www.scienco.org/tag/web-services/feed/?page=2" />

		<item>
		<title>SoapHeaderException: SoapException</title>
		<link>http://www.scienco.org/2007/soapheaderexception-soapexception/</link>
		<comments>http://www.scienco.org/2007/soapheaderexception-soapexception/#comments</comments>
		<pubDate>Thu, 04 Oct 2007 14:32:41 +0000</pubDate>
		<dc:creator>Mikkel Meyer Andersen</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[IdM]]></category>
		<category><![CDATA[CA Identity Manager]]></category>
		<category><![CDATA[TEWS]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.scienco.org/2007/programming/csharp/soapheaderexception-soapexception/</guid>
		<description><![CDATA[The other day I had to use a web service from a C# 2.0 application. No problem &#8211; the .NET 2.0-frameworks provides tons of functionality. To jump into the exciting issue, I&#8217;d generated the proxy classes using WSDL, and started communicating with the WS. When no errors occured everything worked fine, but if something went [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I had to use a web service from a C# 2.0 application. No problem &#8211; the .NET 2.0-frameworks provides tons of functionality. To jump into the exciting issue, I&#8217;d generated the proxy classes using WSDL, and started communicating with the WS. When no errors occured everything worked fine, but if something went wrong I just got an standard non-informative SoapHeaderException with no details whatsoever. Certainly less useful than a wet newspaper.</p>
<p>The problem was that a SOAP-fault (this name avoids mixing up the concepts of SOAP- and run-time exceptions) occurred, but the actual description of the error in the SOAP-response was not deserialized properly and was therefore not included in the run-time exception. The SOAP-response looks like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soapenv:envelope</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:soapenv</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://tews6/wsdl&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:xsd</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:SOAP-ENC</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soapenv:body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soapenv:fault<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;faultcode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>soapenv:Client<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/faultcode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;faultstring<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Error performing operation.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/faultstring<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;detail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;imsexception</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;6.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exception<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CheckForDuplicates<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;code<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>500<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/code<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #808080; font-style: italic;">&lt;!--[CDATA[User id johndoe is a duplicate. ProcessStep::BLTHValidate TabName:  ERRORLEVEL::Error]]--&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exception<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/imsexception<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/detail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/soapenv:fault<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/soapenv:body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/soapenv:envelope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>I read about this several places, and all these said that it was just the way .NET worked in that area. Sounds a bit odd, but nevertheless I instead started to figure out how to solve it.</p>
<p>The solution is actually quite simple, but it took some time to figure out how it should be done. It consists of three parts:</p>
<ul>
<li>A custom Exception so that it can be caught separately</li>
<li>A <a href="http://msdn2.microsoft.com/en-us/library/system.web.services.protocols.soapextension.aspx" title="SoapExtension">SoapExtension</a> that handled serialization and deserialization of the SOAP-messages and in that way were possible to <span title="OversÃ¦ttelse">intervene if a SOAP-fault occurred and throw the custom exception instead of a generic SoapException</span>
<ul>
<li><span title="OversÃ¦ttelse">It&#8217;s worth noticing that I used the <a href="http://msdn2.microsoft.com/en-us/library/system.web.services.protocols.soapextension.processmessage.aspx" title="ProcessMessage">ProcessMessage</a>-method and especially the <a href="http://msdn2.microsoft.com/en-us/library/system.web.services.protocols.soapmessage.aspx" title="SoapMessage">SoapMessage</a> stage BeforeDeserialize</span></li>
</ul>
</li>
<li>A <a href="http://msdn2.microsoft.com/en-us/library/system.web.services.protocols.soapextensionattribute.aspx" title="SoapExtensionAttribute">SoapExtensionAttribute</a> used to mark the web methods should use the SOAP-extension</li>
</ul>
<p>It actually works very well! The only <span title="OversÃ¦ttelse">drawback is that every web method has to be marked with the attribute &#8211; but just another opportunity to celebrate sed!</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scienco.org/2007/soapheaderexception-soapexception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
