Logging validation details with WCF exception shielding

Topics: Exception Handling Application Block, Validation Application Block
May 8, 2007 at 2:42 PM
Hi,

I have a WCF service for which I've configured the ValidationHandler using policy injection, when validation fails the correct Fault contract type is thrown with the detail element containing the reasons for validation failure eg from string lenght validator etc - this happens via the validation block integration with WCF

However, I can't see a way to get a meaningful message in the logging via the ExceptionShieldingAttribute - the message logs but I only get the "The creator of this fault did not specify a Reason" default message (see below for an example of the log message)

I've tried specifiting MessageTemplate on the validator attributes at various points but it doesn't seem to make a difference?

How can I log the validation details as well as sending them back to the calling client?

Thanks
Richard

Timestamp: 08/05/2007 14:33:30
Message: HandlingInstanceID: 9bccf461-e403-40a6-8629-c06775c8c6cb
An exception of type 'System.ServiceModel.FaultException`1[Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationFault, Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]' occurred and was caught.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
05/08/2007 15:33:30
Type : System.ServiceModel.FaultException`1[Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationFault, Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a], System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : The creator of this fault did not specify a Reason.
Source : Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF
Help link :
Detail : Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationFault
Action :
Code : System.ServiceModel.FaultCode
Reason : The creator of this fault did not specify a Reason.
Data : System.Collections.ListDictionaryInternal
TargetSite : System.Object BeforeCall(System.String, System.Object[])
Stack Trace : at Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationParameterInspector.BeforeCall(String operationName, Object[] inputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InspectInputsCore(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

Additional Info:

MachineName : XXXX
TimeStamp : 08/05/2007 14:33:30
FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
AppDomainName : c95eccdf-5-128231084079879725
ThreadIdentity :
WindowsIdentity : XXXXXXXXXX

Type Name: <Error: property TypeName not found>
Method Name: <Error: property MethodName not found>
Category: General
Priority: 0
EventId: 100
Severity: Error
Title:Enterprise Library Exception Handling
Machine: XXXXXX
Application Domain: c95eccdf-5-128231084079879725
Process Id: 4952
Process Name: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE
Win32 Thread Id: 720
Thread Name:
Extended Properties:

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
May 8, 2007 at 7:03 PM
I have not used WCF Exception Shielding yet, but this was talked about it another thread that may be of help:

http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=9808

Regards,

Dave

___________________________

David Hayden
Microsoft MVP C#
Apr 21, 2008 at 10:43 PM
Hi!!!
I have the same problem, but with a Update, (Update Service with WCF Addin for VS2005 or the Update Service Reference in VS2008) it works!!

Well you must do something like this to use it:

try
{
MessageBox.Show(proxy.CrearDetalleBeneficiarios(req).Resultado.MensajeDeRespuesta);
}
catch (FaultException<ValidationFault> fault)
{
foreach (ValidationDetail detail in fault.Detail.Details)
{
MessageBox.Show(string.Format("Error with {0} - {1}", detail.Key, detail.Message));
}
}

And there is!!!