Validation Application Block - not getting the MessageTemplate value on the client

Topics: Validation Application Block
Dec 4, 2008 at 7:54 PM
Hi,

I have a client that calls a WCF service which has been configured to use a Range Validator to validate one of the input parameters. The validation works but I can't get the correct exception on the client. I want to show a messagebox with the message specified in the MessageTemplate property.

Heres how I decorated my method:-

[WCF::

FaultContract(typeof(WCFService1.FaultContracts.GetSOEFault))]
[WCF::
FaultContract(typeof(Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationFault))]
[Microsoft.Practices.EnterpriseLibrary.PolicyInjection.
Tag("TestPolicy")]
[WCF::
OperationContract(IsTerminating = false, IsInitiating = true, IsOneWay = false, AsyncPattern = false, Action = "http://scm/Service1Soap/GetSOEUser", ProtectionLevel = ProtectionLevel.None)]
WCFService1.MessageContracts.
GetSOEUserRespMsg GetSOEUser(WCFService1.MessageContracts.GetSOEUserReqMsg request);

 

Heres the exception I get on the client. I can't see the MessageTemplate value :-

Parameter validation failed\r\nParameter name: request"}
[System.ServiceModel.FaultException<System.ServiceModel.ExceptionDetail>]: {"Parameter validation failed\r\nParameter name: request"}
base {System.ServiceModel.CommunicationException}: {"Parameter validation failed\r\nParameter name: request"}
Action: "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault"
Code: {System.ServiceModel.FaultCode}
Message: "Parameter validation failed\r\nParameter name: request"
Reason: {Parameter validation failed

Here's my config:-

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="policyInjection" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.PolicyInjectionSettings, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <validation>
    <type assemblyName="WCFService1.MessageContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      name="WCFService1.MessageContracts.GetSOEUserReqMsg">
      <ruleset name="UserRequestRules">
        <properties>
          <property name="UserId">
            <validator lowerBound="1" lowerBoundType="Inclusive" upperBound="100"
              upperBoundType="Inclusive" negated="false" messageTemplate="The user ID must be between 1 and 100"
              messageTemplateResourceName="" messageTemplateResourceType=""
              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              name="Range Validator" />
          </property>
        </properties>
      </ruleset>
    </type>
  </validation>
  <policyInjection>
    <policies>
      <add name="TestPolicy">
        <matchingRules>
          <add match="TestPolicy" ignoreCase="false" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.TagAttributeMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Tag Attribute Matching Rule" />
        </matchingRules>
        <handlers>
          <add logBehavior="BeforeAndAfter" beforeMessage="Started" afterMessage="Done"
            eventId="0" includeParameterValues="true" includeCallStack="false"
            includeCallTime="true" priority="-1" severity="Information"
            order="0" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.LogCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Logging Handler">
            <categories>
              <add name="General" />
            </categories>
          </add>
          <add ruleSet="UserRequestRules" specificationSource="Both" order="0"
            type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.ValidationCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Validation Handler" />
        </handlers>
      </add>
    </policies>
  </policyInjection>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add source="Enterprise Library Logging" formatter="Text Formatter"
        log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Formatted EventLog TraceListener" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
</configuration>

 

Dec 5, 2008 at 5:28 AM
The detailed error messages are in the FaultException's Details property.  See this post.. http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/04/06/11509.aspx


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com