<?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; C#</title>
	<atom:link href="http://www.scienco.org/category/programming/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scienco.org</link>
	<description>Life&#039;s too short to be unenthusiastic</description>
	<lastBuildDate>Thu, 07 Jul 2011 13:47:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<atom:link rel="next" href="http://www.scienco.org/category/programming/csharp/feed/?page=2" />

		<item>
		<title>IEnumerable versus implicit conversion</title>
		<link>http://www.scienco.org/2007/ienumerable-versus-implicit-conversion/</link>
		<comments>http://www.scienco.org/2007/ienumerable-versus-implicit-conversion/#comments</comments>
		<pubDate>Thu, 04 Oct 2007 20:02:19 +0000</pubDate>
		<dc:creator>Mikkel Meyer Andersen</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.scienco.org/2007/programming/csharp/ienumerable-versus-implicit-conversion/</guid>
		<description><![CDATA[Maybe it's really just a sick thought, but who cares?! What is actually going to happen if one is enumerating an object which implements both an enumerator-interface and an implicit conversion to a type also implementing an enumerator-interface? At this time I actually know the answer (for Mono at least), but if we should reason [...]]]></description>
			<content:encoded><![CDATA[<p>Maybe it's really just a sick thought,  but who cares?! What is actually going to happen if one is enumerating an object which implements both an enumerator-interface and an implicit conversion to a type also implementing an enumerator-interface? At this time I actually know the answer (for Mono at least), but if we should reason about it, it's almost given that it should use the direct implementation of the enumarator-interface and in that way avoid an implicit conversion. </span></p>
<p>Now it's time to shower this post with some code (inspired by [1]):</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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> experiments
<span style="color: #008000;">&#123;</span>
	<span style="color: #6666cc; font-weight: bold;">class</span> MainClass
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			C<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> c <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> C<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;IEnumerable&lt;T&gt;:&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> e <span style="color: #0600FF; font-weight: bold;">in</span> c<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>				
				Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
			Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Implicit conversion to List&lt;T&gt;:&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>			
			<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> e <span style="color: #0600FF; font-weight: bold;">in</span> <span style="color: #008000;">&#40;</span>List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#41;</span>c<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
			Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Implicit conversion to T[]:&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> e <span style="color: #0600FF; font-weight: bold;">in</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>c<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>	
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">class</span> C<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> <span style="color: #008000;">:</span> IEnumerable<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> 		
	<span style="color: #008000;">&#123;</span>		
		<span style="color: #0600FF; font-weight: bold;">protected</span> List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> list<span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">public</span> C<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">params</span> T<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> elements<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>		
			<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">list</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> elements<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> <span style="color: #008000;">++</span>i<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>elements<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">public</span> IEnumerator<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> GetEnumerator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> 
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> <span style="color: #008000;">--</span>i<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #0600FF; font-weight: bold;">yield</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		IEnumerator IEnumerable<span style="color: #008000;">.</span><span style="color: #0000FF;">GetEnumerator</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> 
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> GetEnumerator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">implicit</span> <span style="color: #0600FF; font-weight: bold;">operator</span> List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>C<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> c<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>c<span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>		
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">implicit</span> <span style="color: #0600FF; font-weight: bold;">operator</span> T<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#40;</span>C<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> c<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			T<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> arr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> T<span style="color: #008000;">&#91;</span>c<span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>			
&nbsp;
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>c<span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
				<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> <span style="color: #008000;">--</span>i<span style="color: #008000;">&#41;</span>
				<span style="color: #008000;">&#123;</span>
					arr<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">++</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
&nbsp;
				<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>c<span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> <span style="color: #008000;">++</span>i<span style="color: #008000;">&#41;</span>
				<span style="color: #008000;">&#123;</span>
					arr<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">++</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">list</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
			<span style="color: #008000;">&#125;</span>
&nbsp;
			<span style="color: #0600FF; font-weight: bold;">return</span> arr<span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>		
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And the result:</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
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">IEnumerable<span style="color: #000000; font-weight: bold;">&lt;</span>T<span style="color: #000000; font-weight: bold;">&gt;</span>:
<span style="color: #000000;">5</span>
<span style="color: #000000;">4</span>
<span style="color: #000000;">3</span>
<span style="color: #000000;">2</span>
<span style="color: #000000;">1</span>
&nbsp;
Implicit conversion to List<span style="color: #000000; font-weight: bold;">&lt;</span>T<span style="color: #000000; font-weight: bold;">&gt;</span>:
<span style="color: #000000;">1</span>
<span style="color: #000000;">2</span>
<span style="color: #000000;">3</span>
<span style="color: #000000;">4</span>
<span style="color: #000000;">5</span>
&nbsp;
Implicit conversion to T<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>:
<span style="color: #000000;">3</span>
<span style="color: #000000;">2</span>
<span style="color: #000000;">1</span>
<span style="color: #000000;">4</span>
<span style="color: #000000;">5</span></pre></td></tr></table></div>

<p>..gets as expected - still a interesting test (in my opinion), though.</p>
<p>[1]: "C# Precisely" by Peter Sestoft and Henrik I. Hansen</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scienco.org/2007/ienumerable-versus-implicit-conversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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 - the .NET 2.0-frameworks provides tons of functionality. To jump into the exciting issue, I'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 - the .NET 2.0-frameworks provides tons of functionality. To jump into the exciting issue, I'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'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 - 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>
		<item>
		<title>Not null or not null or...</title>
		<link>http://www.scienco.org/2007/not-null-or-not-null-or/</link>
		<comments>http://www.scienco.org/2007/not-null-or-not-null-or/#comments</comments>
		<pubDate>Wed, 04 Jul 2007 22:13:16 +0000</pubDate>
		<dc:creator>Mikkel Meyer Andersen</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.scienco.org/2007/programming/csharp/not-null-or-not-null-or/</guid>
		<description><![CDATA[Excuse me for publishing such a shot post (it's now the last one, so please don't feel too annoyed), but this little nice thing in C# can be nice to know: 1 2 3 string a = null; string b = &#34;hello&#34;; string c = a ?? b; // c equals &#34;hello&#34; In other words, [...]]]></description>
			<content:encoded><![CDATA[<p>Excuse me for publishing such a shot post (it's now the last one, so please don't feel too annoyed), but this little nice thing in C# can be nice to know:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">string</span> a <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">string</span> b <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;hello&quot;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">string</span> c <span style="color: #008000;">=</span> a <span style="color: #008000;">??</span> b<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// c equals &quot;hello&quot;</span></pre></td></tr></table></div>

<p>In other words, it returns the first argument that is not null.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scienco.org/2007/not-null-or-not-null-or/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thread safe queue</title>
		<link>http://www.scienco.org/2007/thread-safe-queue/</link>
		<comments>http://www.scienco.org/2007/thread-safe-queue/#comments</comments>
		<pubDate>Sat, 05 May 2007 18:21:21 +0000</pubDate>
		<dc:creator>Mikkel Meyer Andersen</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.scienco.org/2007/uncategorized/test/</guid>
		<description><![CDATA[It's often quite nice to have a blocking queue (thread safe queue) - how many times haven't you used the producer/consumer-pattern? Because we're lazy we make one class we can use every time (long live recycling) instead of making that blocking mechanism implicit in out program: 1 2 3 4 5 6 7 8 9 [...]]]></description>
			<content:encoded><![CDATA[<p>It's often quite nice to have a blocking queue (thread safe queue) - how many times haven't you used the producer/consumer-pattern? Because we're lazy we make one class we can use every time (long live recycling) instead of making that blocking mechanism implicit in out program:</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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Threading</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> Scienco
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">class</span> ThreadSafeQueue<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> 
        <span style="color: #0600FF; font-weight: bold;">where</span> T <span style="color: #008000;">:</span> <span style="color: #6666cc; font-weight: bold;">class</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> Queue<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> mQueue<span style="color: #008000;">;</span> 
        <span style="color: #0600FF; font-weight: bold;">private</span> Semaphore mSemaphore<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> ThreadSafeQueue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            mQueue <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Queue<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            mSemaphore <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Semaphore<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MaxValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Enqueue<span style="color: #008000;">&#40;</span>T element<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>element <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> ArgumentNullException<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">lock</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">mQueue</span><span style="color: #008000;">&#41;</span> 
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">mQueue</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Enqueue</span><span style="color: #008000;">&#40;</span>element<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">mSemaphore</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Release</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> T Dequeue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">mSemaphore</span><span style="color: #008000;">.</span><span style="color: #0000FF;">WaitOne</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">lock</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">mQueue</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">mQueue</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">mQueue</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Dequeue</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">else</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>You probably don't like my coding-style in some way ({, mQueue or whatever) - please feel free to follow whatever guidelines rocking your world.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scienco.org/2007/thread-safe-queue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

