Can't get FaultException back to client

Topics: Exception Handling Application Block
Mar 9, 2009 at 7:53 PM
Hi,
I'm trying to use EntLib 4.1 to handle exceptions over WCF. Here's the code:
Fault Class:

[

DataContract (Name = "ServiceFault", Namespace = "LSS.AnI.ServicesContracts.FileAdmin")]
public class ServiceFault
{
public ServiceFault()
{
}

 

 

private string message;
private Guid id;

 

[

DataMember]
public string MessageText
{
get { return message; }
set { message = value; }
}

 

 [

DataMember]
public Guid Id
{
get { return id; }
set { id = value; }
}
}

 

Service contarct:

[

ServiceContract(Namespace = "LSS.AnI.ServicesContracts.FileAdmin")]
[
ExceptionShielding]
public interface IFileAdminService
{

[

OperationContract]
[
FaultContract(typeof(ServiceFault))]
List<FileType> GetFileTypes();

 

}

Service:

 

public class FileAdminService : IFileAdminService
{

 

 

public List<FileType> GetFileTypes()

 

{

throw new InvalidOperationException("200~DatabaseStandardError");
}

 

 

 

Configuration - Server:

 

<

 

exceptionHandling>
<
exceptionPolicies>
<

 

add name="WCF Exception Shielding">
<
exceptionTypes>
<
add type="System.InvalidOperationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException" name="ArgumentNullException">
<
exceptionHandlers>
<
add faultContractType="LSS.AnI.Core.ServicesContracts.ServiceFault, LSS.AnI.Core.ServicesContracts" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF" name="DefaultFaultContract Handler">
<
mappings>
<
add source="{Guid}" name="Id" />
<
add source="{Massage}" name="MessageText" />
</
mappings>
</
add>
</
exceptionHandlers>
</
add>
</
exceptionTypes>
</
add>
</
exceptionPolicies>
</
exceptionHandling>

 

 

 

Client side:

public List<FileType> GetFileTypes()
{
try
{
if (OpenChannel())
{
return channel.GetFileTypes();
}
}
catch (FaultException<ServiceFault> ex)
{
ExceptionManager.ThrowExceptionWithIntrinsicPolicy(ex, ex.Details);
}
catch (Exception ex)
{
ExceptionManager.ThrowExceptionWithIntrinsicPolicy(ex, STR_ENTLIB_EXCEPTION_CODE_GENERAL);
}
finally
{
CloseChannel();
}
return null;
}

 

 

The problem is that the catch (FaultException<ServiceFault> ex) is never hit only the exception catch is and so I never get the original message thrown by the server... The exception mesage is:
"An error has occurred while consuming this service. Please contact your administrator for more information. Error ID: f443251c-8b21-49cb-8972-72f8b6979c7d"

And the stack trace is:

Server stack trace:
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at AnI.Core.ServiceProxies.FileAdminService.IFileAdminService.GetFileTypes()
   at LSS.AnI.Core.FileProxy.FileServiceProxy.GetFileTypes() in C:\AnI\AuditAndInvestigations\AnI.Core.ServiceProxies\FileServiceProxy.cs:line 143

I've seen the exact same code working in other examples but from some reasons mine is failing. Any ideas?
Thank you,
Ken

Mar 10, 2009 at 11:09 AM
Hi,

Sorry cant seem to repro your problem. Would you mind sending me a sample solution? What value do you get in the message in the client? Also, do you get a value for the Id property of your fault contract?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com