VAB and WCF - Validation Behavior Error

Topics: Validation Application Block
Aug 5, 2009 at 1:29 PM

Hi,

Trying to use Validation Application Block, Ent Lib 4.1 with WCF services.

Want to validate a datamembers  “FirstName” and “LastName” of a DataContract “Customer” class.

It is a simple string length validation. If length of the strings is more than 10 an exception should be thrown.

Following is the system.serviceModel extract from Web.Config.

  <system.serviceModel>

    <services>

      <service behaviorConfiguration="CustomerService.CustomerServiceBehavior"

        name="CustomerService.CustomerService">

        <endpoint address="" binding="wsHttpBinding" contract="CustomerService.ICustomerService">

          <identity>

            <dns value="localhost" />

          </identity>

        </endpoint>

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

      </service>

    </services>

    <extensions>

      <behaviorExtensions>

        <add name="validation"

                   type="Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationElement,

             Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF,

             Version=4.1.0.0, Culture=neutral,

             PublicKeyToken=31bf3856ad364e35" />

      </behaviorExtensions>

    </extensions>

    <behaviors>

      <endpointBehaviors>

        <behavior name="ValidationBehavior">

          <validation enabled="true" ruleset="Bank2Rules"/>

        </behavior>

      </endpointBehaviors>

      <serviceBehaviors>

        <behavior name="CustomerService.CustomerServiceBehavior">

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

  </system.serviceModel>

Getting an error on the <validation> tag under “endpointBehaviors/ behavior” tags in Web.config.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'validation' cannot be added to this element.  Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions.
Parameter name: element

The problem is the validation tag.

Following warning is displayed when the solution is built:

Description: The element 'behavior' has invalid child element 'validation'. List of possible elements expected: 'clientVia, callbackDebug, callbackTimeouts, clientCredentials, transactedBatching, dataContractSerializer, synchronousReceive, enableWebScript, webHttp'.

File: D:\IBEP\P2P\Sprint12\Code\CustomerApplication\Service\CustomerService\Web.config         

Line: 121

Column: 12

The service project has a reference to Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF

I’m following the steps mentioned in the following link:

http://msdn.microsoft.com/en-us/library/dd140110.aspx

 

Regards,

Abhijeet.

Aug 6, 2009 at 7:57 AM

Hi,

Maybe you'll find my answer very weird. :) To start, I repro your error by also following the steps you pointed. I assume that you've just copy paste the:

<add name="validation"
           type="Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationElement,
             Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF,
             Version=4.1.0.0, Culture=neutral, 
             PublicKeyToken=31bf3856ad364e35" />

which I also did, so I got your error, one thing i did is to align the entry above, which turns out this way: As you've noticed, in the behaviorExtensions, I put them in just a single line. Can you please try this weird solution and see if that also works for you.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      
      <service name="MyWCFVAB.Service1" behaviorConfiguration="MyWCFVAB.Service1Behavior">
        
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8731/Design_Time_Addresses/MyWCFVAB/Service1/" />
          </baseAddresses>
        </host>

        <endpoint binding="basicHttpBinding"
            contract="MyWCFVAB.IService1"
            behaviorConfiguration="ValidationBehavior" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        
      </service>
      
    </services>

    <behaviors>

      <!-- Added -->
      <endpointBehaviors>
        <behavior name="ValidationBehavior">
          <validation enabled="true"/>
        </behavior>
      </endpointBehaviors>
      <!-- Added -->
      
      <serviceBehaviors>
        <behavior name="MyWCFVAB.Service1Behavior">
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>

      
    </behaviors>
    
    <extensions>
      <behaviorExtensions>
        <add name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationElement,Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </behaviorExtensions>
    </extensions>

  </system.serviceModel>
</configuration>

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Aug 6, 2009 at 10:21 AM

Hi Valiant,

Thanks for the reply. Unfortunately, it didn't work.

I've figured out 2 points:

  • I checked out that <behavior> tag accepts a pre-defined list of values, as mentioned in the child elements in the following post: http://msdn.microsoft.com/en-us/library/ms731403.aspx
  • If we change the target Framework, of the project, to 2.0, the error is gone. But, this change, leads to other errors.

Similar work is done in the post: http://www.codeproject.com/KB/WCF/WCFVAB.aspx

I downloaded the code and it worked fine.

I'm not able to figure out the cause of the error.

I’m using VS 2008 SP1, Team System. .Net Framework 3.5

 

Thanks,

Abhijeet.

Aug 6, 2009 at 10:30 AM

Hi,

Is it possible for you to send your sample solution? so I may try it out and compare to what I did.

Aug 6, 2009 at 2:40 PM

The warning still exists but the service and client have started working.

Thanks,

Abhijeet.