<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.silverlight.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Programming with .NET - General</title><link>http://forums.silverlight.net/forums/17.aspx</link><description>General discussions around authoring Silverlight .NET applications.</description><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Re: Re: Re: Re: Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/201067.aspx</link><pubDate>Fri, 03 Apr 2009 21:04:35 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:201067</guid><dc:creator>ticcoid</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/201067.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=201067</wfw:commentRss><description>big big thank you sladapter. works very good.</description></item><item><title>Re: Re: Re: Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/200812.aspx</link><pubDate>Fri, 03 Apr 2009 13:29:20 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:200812</guid><dc:creator>sladapter</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/200812.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=200812</wfw:commentRss><description>&lt;p&gt;You need to download the sample code from this link:&lt;/p&gt;&lt;p&gt; &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=silverlightws&amp;amp;DownloadId=3473" title="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=silverlightws&amp;amp;DownloadId=3473"&gt;http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=silverlightws&amp;amp;DownloadId=3473&lt;/a&gt;&lt;/p&gt;&lt;p&gt;And run the SilverlightRawFault sample project you can see what I mean this is the best solution so far for handling the error thrown from WCF.&amp;nbsp; If you take a look at WCF Service.svc.cs code you can see the DoWork function just throw an exception. There is nothing special in the service code. You just write your service code as you normally do. But the error thrown from WCF will be catched in the Silverlight end. All you need to do is the following:&lt;/p&gt;&lt;p&gt;1) Add reference of SilverlightFaultBehavior.dll (which is included in the sample files) to the Web project, and add the following behavior to the Web.config file:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;lt;system.serviceModel&amp;gt;&lt;b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;extensions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;behaviorExtensions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add name=&amp;quot;silverlightFaults&amp;quot; type=&amp;quot;Microsoft.Silverlight.Samples.SilverlightFaultBehavior, SilverlightFaultBehavior, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/behaviorExtensions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/extensions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;behaviors&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;endpointBehaviors&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&amp;nbsp; &amp;lt;behavior name=&amp;quot;SilverlightFaultBehavior&amp;quot;&amp;gt;&lt;b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;silverlightFaults/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&amp;nbsp; &amp;lt;/behavior&amp;gt;&lt;b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/endpointBehaviors&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; ...&lt;/p&gt;&lt;p&gt;&amp;lt;/system.serviceModel&amp;gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;2) Add reference of SilverlightMessageInspector.dll (included in the sample) to the Silverlight project. &lt;/p&gt;&lt;p&gt;3) Add SilverlightFaultMessageInspector.cs (included in the sample) to your Silverlight project or your Silverlight Library project. &lt;/p&gt;&lt;p&gt;4) Change your WCF calling code to the following:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strike&gt;&amp;nbsp;&amp;nbsp; YourServiceClient proxy = new YourServiceClient();&lt;/strike&gt;&amp;nbsp; // Your WCF service default consturctor&lt;br /&gt;&amp;nbsp;
&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EndpointAddress address = new EndpointAddress(&amp;quot;http://localhost:52620/Service.svc&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;BasicHttpMessageInspectorBinding binding = new BasicHttpMessageInspectorBinding(new SilverlightFaultMessageInspector());&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ServiceClient proxy = new ServiceClient(binding, address);&amp;nbsp; // Use this WCF service constructor, pass new binding&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proxy.DoWorkCompleted += new System.EventHandler&amp;lt;System.ComponentModel.AsyncCompletedEventArgs&amp;gt;(proxy_DoWorkCompleted);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proxy.DoWorkAsync(); //code to call WCF &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;void proxy_DoWorkCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt;&amp;nbsp;&lt;/b&gt; if (e.Error != null)&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; { &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(e.Error is RawFaultException)&lt;/b&gt;&amp;nbsp; // Now you can catch the Exception thrown from WCF&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RawFaultException exception = (RawFaultException)e.Error;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(&amp;quot;Service says: &amp;quot; + exception.FaultMessage + Environment.NewLine +&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;Exception type: &amp;quot; + exception.FaultType + Environment.NewLine +&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;Stack trace: &amp;quot; + exception.StackTrace);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; else // None WCF error&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; MessageBox.Show(e.Message);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;</description></item><item><title>Re: Re: Re: Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/200422.aspx</link><pubDate>Thu, 02 Apr 2009 22:01:20 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:200422</guid><dc:creator>ticcoid</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/200422.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=200422</wfw:commentRss><description>thank you, i tested your approach from an other thread and it works fine. you said that the solution in that blog is the best. but which do you mean? i cant find catching exception in this blog. thank you</description></item><item><title>Re: Re: Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/200231.aspx</link><pubDate>Thu, 02 Apr 2009 13:54:22 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:200231</guid><dc:creator>sladapter</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/200231.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=200231</wfw:commentRss><description>&lt;p&gt;The best solution for catching Exception thrown in WCF is given in this blog:&amp;nbsp; &lt;a href="http://blogs.msdn.com/silverlightws/" title="http://blogs.msdn.com/silverlightws/"&gt;http://blogs.msdn.com/silverlightws/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The sample code can download from here: &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=silverlightws&amp;amp;DownloadId=3473" title="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=silverlightws&amp;amp;DownloadId=3473"&gt;http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=silverlightws&amp;amp;DownloadId=3473 &lt;/a&gt;&lt;/p&gt;&lt;p&gt;The code they provided is very straightforward without having to change much of
the current code. You do not have to do anything on the WCF end. All you need to do to create &lt;b&gt;BasicHttpMessageInspectorBinding&lt;/b&gt;
instead of BasicHttpBinding and pass it to the Service constructor.
Then the e.Error should return the exceptions thrown from the
Service end. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;</description></item><item><title>Re: Re: Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/200134.aspx</link><pubDate>Thu, 02 Apr 2009 11:15:43 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:200134</guid><dc:creator>ticcoid</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/200134.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=200134</wfw:commentRss><description>&lt;p&gt;hey, thank you for that code. i rebuilt it but there is always a runtime error. something like the exceptions are not handling by usercode. sry this is not the exact error because i translate it from german. but maybe you know what it can be. thank you&lt;/p&gt;</description></item><item><title>Re: Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/94861.aspx</link><pubDate>Mon, 22 Sep 2008 08:04:17 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:94861</guid><dc:creator>sravoux</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/94861.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=94861</wfw:commentRss><description>&lt;p&gt;My solution is :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;to&amp;nbsp;memorize the WCF exception on the session and rethrow it (&amp;quot;as is&amp;quot; or a FaultException)&lt;/li&gt;
&lt;li&gt;to implement a GetLastError method on my WCF service that gives the exception&amp;#39;s details&lt;/li&gt;
&lt;li&gt;to catch the ProtocolException on the SL2 client and recall the server to know what happened&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Something like this :&lt;/p&gt;&lt;pre class="coloredcode"&gt;[OperationContract]
&lt;span class="kwd"&gt;public void&lt;/span&gt; Hello()
{
&lt;span class="kwd"&gt;try&lt;/span&gt; { … }
&lt;span class="kwd"&gt;catch&lt;/span&gt; (Exception ex)
{&lt;/pre&gt;&lt;pre class="coloredcode"&gt;// NB: I give a nice context&amp;#39;s message in UserState parameter
HandleError(&lt;span class="st"&gt;&amp;quot;The hello method failed&amp;quot;&lt;/span&gt;, ex);
}
}

[DataContract]
&lt;span class="kwd"&gt;public class&lt;/span&gt; ErrorInfos
{
[DataMember]
&lt;span class="kwd"&gt;public string&lt;/span&gt; Message;

[DataMember]
&lt;span class="kwd"&gt;public string&lt;/span&gt; Details;
}

&lt;span class="kwd"&gt;private void&lt;/span&gt; HandleError(&lt;span class="kwd"&gt;string&lt;/span&gt; message, Exception ex)
{
var error = &lt;span class="kwd"&gt;new&lt;/span&gt; ErrorInfos() { Message = message , Details = &lt;span class="kwd"&gt;null&lt;/span&gt; };
&lt;span class="kwd"&gt;if&lt;/span&gt; (ex != &lt;span class="kwd"&gt;null&lt;/span&gt;)
{
&lt;span class="cmt"&gt;// Ajout du détails de l&amp;#39;exception&lt;/span&gt;
error.Details = ex.ToString();

&lt;span class="cmt"&gt;// Ajout du message de la premiere exception dans le message&lt;/span&gt;
&lt;span class="kwd"&gt;while&lt;/span&gt; (ex.InnerException != &lt;span class="kwd"&gt;null&lt;/span&gt;)
{
ex = ex.InnerException;
}
error.Message += &lt;span class="st"&gt;&amp;quot; (&amp;quot;&lt;/span&gt; + ex.Message + &lt;span class="st"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;;
}

&lt;span class="cmt"&gt;// Mémorisation de l&amp;#39;erreur en session (Workaround du bug SL2 Beta 2)&lt;/span&gt;
&lt;span class="kwd"&gt;if&lt;/span&gt; (HttpContext.Current != &lt;span class="kwd"&gt;null&lt;/span&gt;)
{
HttpContext.Current.Session[&lt;span class="st"&gt;&amp;quot;LastError&amp;quot;&lt;/span&gt;] = error;
}

&lt;span class="cmt"&gt;// Génération d&amp;#39;une faute SOAP (NB: pas géré par SL2 Beta2)&lt;/span&gt;
&lt;span class="kwd"&gt;throw new&lt;/span&gt; FaultException(&lt;span class="kwd"&gt;new&lt;/span&gt; FaultReason(error.Message));
}

[OperationContract]
&lt;span class="kwd"&gt;public&lt;/span&gt; ErrorInfos GetLastError()
{
ErrorInfos error = &lt;span class="kwd"&gt;null&lt;/span&gt;;
&lt;span class="kwd"&gt;if&lt;/span&gt; (HttpContext.Current != &lt;span class="kwd"&gt;null&lt;/span&gt;)
{
error = (ErrorInfos)HttpContext.Current.Session[&lt;span class="st"&gt;&amp;quot;LastError&amp;quot;&lt;/span&gt;];
&lt;span class="kwd"&gt;return&lt;/span&gt; error;
}
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;On the SL2 client :&lt;/p&gt;&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;private void&lt;/span&gt; OnXxxCompleted(&lt;span class="kwd"&gt;object&lt;/span&gt; sender, AsyncCompletedEventArgs e)
{
&lt;span class="kwd"&gt;try&lt;/span&gt;
{
var result = e.Result;
&lt;span class="cmt"&gt;//…&lt;/span&gt;
}
&lt;span class="kwd"&gt;catch&lt;/span&gt; (ProtocolException ex)
{
CompleteAndDisplayError(ex);
}
}

&lt;span class="kwd"&gt;public static void&lt;/span&gt; CompleteAndDisplayError(&lt;span class="kwd"&gt;string&lt;/span&gt; msg, Exception e)
{
var client = ServicesManager.GetClient();
client.GetLastErrorCompleted += &lt;span class="kwd"&gt;new&lt;/span&gt; EventHandler(OnGetLastErrorCompleted);
client.GetLastErrorAsync(msg);
}

&lt;span class="kwd"&gt;private static void&lt;/span&gt; OnGetLastErrorCompleted(&lt;span class="kwd"&gt;object&lt;/span&gt; sender, GetLastErrorCompletedEventArgs e)
{
&lt;span class="kwd"&gt;if&lt;/span&gt; (!e.Cancelled &amp;amp;&amp;amp; e.Error == &lt;span class="kwd"&gt;null&lt;/span&gt;)
{
DisplayError(e.Result.Message, e.Result.Details);
}
&lt;span class="kwd"&gt;else&lt;/span&gt;
{
DisplayError(e.UserState &lt;span class="kwd"&gt;as string&lt;/span&gt;);
}
}&lt;/pre&gt;&amp;nbsp;</description></item><item><title>Re: Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/67982.aspx</link><pubDate>Thu, 03 Jul 2008 19:22:00 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:67982</guid><dc:creator>spoo</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/67982.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=67982</wfw:commentRss><description>&lt;p&gt;Ok, thanks for the answer.&lt;/p&gt;&lt;p&gt;This is - to speak honestly - rather lame, but oh well. I&amp;#39;ll just have to resort to passing the error string as part of the result set then.&lt;/p&gt;&lt;p&gt;Thanks.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/67980.aspx</link><pubDate>Thu, 03 Jul 2008 19:16:40 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:67980</guid><dc:creator>sladapter</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/67980.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=67980</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/silverlight/images/icon-quote.gif"&gt; &lt;strong&gt;spoo:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&lt;/p&gt;&lt;p&gt;But aren&amp;#39;t there any ways of getting this eveloped as a SOAP-fault response?&lt;/p&gt;&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;&lt;p&gt;Not with current Silverlight. Maybe later, I don&amp;#39;t know. I wish they do.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/67974.aspx</link><pubDate>Thu, 03 Jul 2008 19:07:32 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:67974</guid><dc:creator>spoo</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/67974.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=67974</wfw:commentRss><description>Hm, well so, testing the .asmx from the browser gives this text only, not even enveloped in XML - but &lt;i&gt;literally &lt;/i&gt;just this - as content-type text/plain. Why doesn&amp;#39;t the WS envelope this in a SOAP fault message?&amp;nbsp; (Output of: &amp;nbsp; throw new Exception(&amp;quot;failed!&amp;quot;) )&lt;br /&gt;&lt;pre&gt;&lt;b&gt;System.Exception: failed!&lt;br /&gt;   at Schedule_Web.MiscWebService.DummyFail() in C:\work\dotnet_sl_schedule\Schedule\Schedule_Web\MiscWebService.asmx.cs:line 152&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;I see what you&amp;#39;re saying with wrapping it in a result -- sure.... I could do that.&lt;/pre&gt;&lt;pre&gt;But aren&amp;#39;t there any ways of getting this eveloped as a SOAP-fault response?&lt;/pre&gt;&lt;pre&gt;E.g. &lt;a href="http://msdn.microsoft.com/en-us/library/aa480514.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa480514.aspx&lt;/a&gt; says I should be getting that message wrapped something like:&lt;/pre&gt;&lt;pre&gt;&amp;lt;soap:Fault&amp;gt;&lt;br /&gt;   &amp;lt;faultcode&amp;gt;soap:Server&amp;lt;/faultcode&amp;gt;&lt;br /&gt;   &amp;lt;faultstring&amp;gt;System.Web.Services.Protocols.SoapException: Server was &lt;br /&gt;unable to process request. ---&amp;amp;gt; System.Exception: Something bad &lt;br /&gt;happened at AYS17Sept2002.Service1.CallFault() in &lt;br /&gt;c:\inetpub\wwwroot\AYS17Sept2002\Service1.asmx.vb:line 49&lt;br /&gt;   --- End of inner exception stack trace ---&amp;lt;/faultstring&amp;gt;&lt;br /&gt;   &amp;lt;detail /&amp;gt;&lt;br /&gt;&amp;lt;/soap:Fault&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;Is this some configuration error from my side, or is it some attributes I have to decorate the WS with, or what? &lt;/pre&gt;&lt;pre&gt;I&amp;#39;ll admit I&amp;#39;m a noob at doing WSes from .NET based stuff. :)&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;</description></item><item><title>Re: Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/67969.aspx</link><pubDate>Thu, 03 Jul 2008 18:46:51 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:67969</guid><dc:creator>sladapter</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/67969.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=67969</wfw:commentRss><description>&lt;p&gt;In this thread we talked about how to catch WCF exception and pass it back to Silverlight. For WCF it&amp;#39;s little easier because we can add CustomException filed to all the return object from WCF so we do not need to do any seralization.&amp;nbsp; For asmx call you also need to catch the exception at all your WebMethod and serialize it to some form. If all your returning data is packaged in xml, you can always insert a error element and error message in that xml so you can parse it back on Silverlight side. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;a href="http://silverlight.net/forums/p/17944/60019.aspx#60019" title="http://silverlight.net/forums/p/17944/60019.aspx#60019"&gt;http://silverlight.net/forums/p/17944/60019.aspx#60019&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Some one also suggested using a out paramter to pass exception back in all WCF call. You can try the same in asxm call, I don&amp;#39;t think you can pass the custom exception object back, but you can try to pass the error message (string type) back.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://silverlight.net/forums/p/18885/64303.aspx#64303" title="http://silverlight.net/forums/p/18885/64303.aspx#64303"&gt;http://silverlight.net/forums/p/18885/64303.aspx#64303&lt;/a&gt; &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Getting the actual Exception thrown from a WebService (not just a 404 / ProtocolException)</title><link>http://forums.silverlight.net/forums/thread/67967.aspx</link><pubDate>Thu, 03 Jul 2008 18:31:37 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:67967</guid><dc:creator>spoo</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/67967.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=67967</wfw:commentRss><description>&lt;p&gt;I&amp;#39;m calling a web service from my Silverlight application, but if any of the web service methods throw an Exception, I&amp;#39;m just getting a ProtocolException in the BeginInvoke() call for the generated proxy code for the web service method, instead of the actual Exception the web service threw.&lt;/p&gt;
&lt;p&gt;E.g.the method could be something like:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre&gt;[WebMethod]&lt;br /&gt;public void GetItem(/* some parameters */)&lt;br /&gt;{&lt;br /&gt;  if (checkAccess()) throw new Exception(&amp;quot;you&amp;#39;re not allowed to do this&amp;quot;);&lt;br /&gt;  else&lt;br /&gt;  {&lt;br /&gt;     doWhateverIfAllowed();&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;pre&gt;The .InnerException is null. &lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;The .Message property will be: &amp;quot;The remote server returned an unexpected response: (404) Not Found.&amp;quot;&lt;/p&gt;
&lt;p&gt;The .StackTrack will be something like:&lt;/p&gt;
&lt;p&gt;&amp;quot;&amp;nbsp;&amp;nbsp; at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)\r\n&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)\r\n&amp;nbsp;&amp;nbsp; at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)\r\n&amp;nbsp;&amp;nbsp; at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)\r\n&amp;nbsp;&amp;nbsp; at Schedule.ScheduleProxyServiceReference.ScheduleProxyWebServiceSoapClient.ScheduleProxyWebServiceSoapClientChannel.EndAddItem(IAsyncResult result)\r\n&amp;nbsp;&amp;nbsp; at Schedule.ScheduleProxyServiceReference.ScheduleProxyWebServiceSoapClient.Schedule.ScheduleProxyServiceReference.ScheduleProxyWebServiceSoap.EndAddItem(IAsyncResult result)\r\n&amp;nbsp;&amp;nbsp; at Schedule.ScheduleProxyServiceReference.ScheduleProxyWebServiceSoapClient.EndAddItem(IAsyncResult result)\r\n&amp;nbsp;&amp;nbsp; at Schedule.ScheduleProxyServiceReference.ScheduleProxyWebServiceSoapClient.OnEndAddItem(IAsyncResult result)\r\n&amp;nbsp;&amp;nbsp; at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)&amp;quot;&lt;/p&gt;
&lt;p&gt;(ScheduleProxyService is the web service)&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;And before someone starts suggesting this; NO, it&amp;#39;s not a missing cross-domain policy file. The web services work fine as long as they don&amp;#39;t throw any exceptions.&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Is there no way of getting the actual Exception from the web service?&lt;/p&gt;&lt;p&gt;(And why am I getting a 404 here?? Shouldn&amp;#39;t the WS return a 501 if there&amp;#39;s was an internal error? :P)&lt;/p&gt;&lt;p&gt;Edit: if I open up the WS in IE and call the method that throws an exception, I&amp;#39;m actually getting a &amp;quot;500&amp;quot; response. Is there something else I have to do to make the WS pass on the exceptions? (This is through SOAP) &lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>