tags:

views:

482

answers:

2

I'm using the Enterprise Library Validation Application Block for my WCF service. All is fine, and .Net consumers can catch the FaultException<ValidationFault> exception to get a collection of human-readable business errors. However, it doesn't look quite as great for non-.Net consumers, especially those that are going to be looking at the raw SOAP message. The SOAP Reason text is always "The creator of this fault did not specify a Reason." This isn't very helpful, as there is a reason, it's specified under the <Detail> element, as shown in the example Fault message below.

Is there any way to change the text "The creator of this fault did not specify a Reason." to something more helpful like "See ValidationFault Details"?

<s:Body>
   <s:Fault>
      <s:Code>
         <s:Value>s:Sender</s:Value>
      </s:Code>
      <s:Reason>
         <s:Text xml:lang="en-GB">The creator of this fault did not specify a Reason.</s:Text>
      </s:Reason>
      <s:Detail>
         <ValidationFault xmlns="http://www.microsoft.com/practices/EnterpriseLibrary/2007/01/wcf/validation" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
            <Details xmlns:b="http://schemas.datacontract.org/2004/07/Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF"&gt;
               <b:ValidationDetail>
                  <b:Key i:nil="true"/>
                  <b:Message>Value Validator</b:Message>
                  <b:Tag>request</b:Tag>
               </b:ValidationDetail>
            </Details>
         </ValidationFault>
      </s:Detail>
   </s:Fault>
</s:Body>
A: 

How is your WCF service generating these faults?

When you look at the FaultException class in WCF, there are numerous ways you can construct one of those - including some constructors which allow you to specify a FaultReason for the SOAP fault.

Marc

marc_s
Yes, but the EntLib validation is kicking in before my service implementation code. The service can handle errors that occur after validation has taken place and wrap them up in SOAP Faults fine, but the validation occurs slightly before all this.
Graham Clark
However in this case the FaultException is created by the enterprise library and not explicitly by user code.
Pratik
Then you may want to customize the Enterprise Library code (and contribute it back). I'd recommend retrieving the reason from a configuration entry.
John Saunders
+3  A: 

Well, it seems like the EntLib people didn't think of this one. I've noted where the change in the EntLib code needs to be and raised an issue at their CodePlex site. I guess this could also be done by anyone as part of the EntLibContrib project, but they seem to still be on Enterprise Library 3.1, whereas I'm using 4.1.

I guess if anyone's desperate, the solution would be to download the EntLib source code, and modify the BeforeCall method in the ValidationParameterInspector class (in the Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF namespace). This is where the FaultException is created. An overload to this constructor can specify the FaultReason.

Graham Clark
Right, and that's also where you should pull the `FaultReason` from the configuration.
John Saunders