简体   繁体   中英

WCF + Enterprise Library + ValidationFault

I am trying to catch the ValidationFault exceptions of my service and return a instance of MyClass with the property Message filled with the validation error provided by EntLib when my client calls one of my service methods without the correct parameters (I can't use complex types).

I tried to implement two interfaces to accomplish this task: IParameterInspector and IOperationInvoker . The problem is after the method BeforeCall is called (of the IParameterInspector interface), EntLib throws the ValidationFault exception but I can't catch it and my code doesn't reach the Invoke method of my IOperationInvoker class and because of that I can't replace the return value with a instance of MyClass .

Remember, my client is not based on .NET platform and there's no such thing as catch( FaultException<ValidationFault> ex) there. That's why I MUST work with a default object on my service responses.

I appreciate the help.

Can you use an IErrorHandler implementation similar to Enterprise Library's WCF ExceptionShielding? Basically catch all exceptions and if it's a FaultException<ValidationFault> then convert the ValidationFault to your custom message and return it.

It looks like the output of ProvideFault is a Message so you could return a message instead of a fault. This posting seems to give the approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM