Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF fault handling
    text
    copied!<p><strong>Q</strong> How can I get the original exception (occurred on the server) on the client side?</p> <p>I am working with a self-hosted WCF service and C# 4 and trying to set up proper exception handling.</p> <p>I have a client that looks like this</p> <pre><code>private ServiceResponse PerformRemoteAction(ServiceRequest request, ProcessOperations operation) { ... try { //remote call switch (operation) { ... case ProcessOperations.VerifyAction: { response = client.VerifyAction(request); break; } default: throw new NotImplementedException(); } } catch (Exception ex) { AppManager.LogException(ex); } return response; } </code></pre> <p>And service implementation</p> <pre><code>public override ServiceResponse VerifyAction(ServiceRequest request) { RegisterRequest(request); try { var chain = new VerificationChain(); Responce = chain.Run(request); } catch (Exception ex) { throw new FaultException&lt;WcfException&gt;(ExceptionFactory.Create(ex), new FaultReason(ex.Message)); } SetSuccessfulResponce(); return Responce; } </code></pre> <p>Service web.config has</p> <pre><code>&lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior&gt; &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; </code></pre> <p>This is my original exception <img src="https://i.stack.imgur.com/n2wFN.png" alt="enter image description here"></p> <p>And this is what I get on the client<img src="https://i.stack.imgur.com/YzKKS.png" alt="enter image description here"></p> <p>If needed I can post full details on the client side, however the exception on the client does not have any reference to the original one.</p> <p><strong>Update</strong><br/> This is my interface with defined <em>FaultContractAttribute</em></p> <pre><code>[ServiceContract] public interface IServiceOperation : IOperation { ... [OperationContract(Action = "http://tempuri.org/ITestRunnerService/VerifyAction", ReplyAction = "http://tempuri.org/ITestRunnerService/VerifyAction")] [FaultContractAttribute(typeof(WcfException), Action = "http://tempuri.org/ITestRunnerService/ExecuteRequestWcfExceptionFault", Name = "WcfException", Namespace = "http://schemas.datacontract.org/2004/07/TH.Core.Exceptions")] ServiceResponse VerifyAction(ServiceRequest request); } </code></pre> <p>And this is my <em>WcfException</em> class</p> <pre><code>[DataContract] public class WcfException : Exception { [DataMember] public string Title { get; set; } [DataMember] public new string Message { get; set; } [DataMember] public new string InnerException { get; set; } [DataMember] public new string StackTrace { get; set; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload