Q How can I get the original exception (occurred on the server) on the client side?
I am working with a self-hosted WCF service and C# 4 and trying to set up proper exception handling.
I have a client that looks like this
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;
}
And service implementation
public override ServiceResponse VerifyAction(ServiceRequest request)
{
RegisterRequest(request);
try
{
var chain = new VerificationChain();
Responce = chain.Run(request);
}
catch (Exception ex)
{
throw new FaultException<WcfException>(ExceptionFactory.Create(ex),
new FaultReason(ex.Message));
}
SetSuccessfulResponce();
return Responce;
}
Service web.config has
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
This is my original exception
And this is what I get on the client
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.
Update
This is my interface with defined FaultContractAttribute
[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);
}
And this is my WcfException class
[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; }
}
Have you tried to catch a FaultException instead?
catch (FaultException<WcfException> ex)
{
AppManager.LogException(ex);
}
catch (FaultException unknownFault)
{
AppManager.LogException(unknownFault);
}
You will need to include a FaultContractAttribute in your contract for this to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With