Export (0) Print
Expand All

IServiceBehavior::Validate Method

Provides the ability to inspect the service host and the service description to confirm that the service can run successfully.

Namespace:  System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

void Validate(
	ServiceDescription^ serviceDescription, 
	ServiceHostBase^ serviceHostBase
)

Parameters

serviceDescription
Type: System.ServiceModel.Description::ServiceDescription

The service description.

serviceHostBase
Type: System.ServiceModel::ServiceHostBase

The service host that is currently being constructed.

Use the Validate method to confirm whether the current service can execute properly according to your scenario.

NoteNote

All of the IServiceBehavior methods pass System.ServiceModel.Description::ServiceDescription and System.ServiceModel::ServiceHostBase objects as a parameters. The ServiceDescription parameter is for examination and insertion of customizations only; if you otherwise modify these objects the execution behavior is undefined.

The following code example shows the use of a service behavior specified in a configuration file to insert a custom error handler in a service application. In this example, the error handler catches all exceptions and converts them into a custom GreetingFault SOAP fault that is then returned to the client.

The following IServiceBehavior implementation adds no binding parameter objects, adds the custom System.ServiceModel.Dispatcher::IErrorHandler object to each ChannelDispatcher::ErrorHandlers property, and validates that each operation of the service to which the service behavior is applied and has a System.ServiceModel::FaultContractAttribute of type GreetingFault.

No code example is currently available or this language may not be supported.

In this example, the behavior class also implements System.ServiceModel.Configuration::BehaviorExtensionElement, which enables the service behavior to be inserted by using it in an application configuration file, as the following code example demonstrates.

No code example is currently available or this language may not be supported.
<configuration>
  <system.serviceModel>
    <services>
      <service 
        name="Microsoft.WCF.Documentation.SampleService"
        behaviorConfiguration="metaAndErrors">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/SampleService"/>
          </baseAddresses>
        </host>
        <endpoint
          address=""
          binding="wsHttpBinding"
          contract="Microsoft.WCF.Documentation.ISampleService"
         />
        <endpoint
          address="mex"
          binding="mexHttpBinding"
          contract="IMetadataExchange"
         />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metaAndErrors">
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true"/>
          <enforceGreetingFaults />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <add 
          name="enforceGreetingFaults" 
          type="Microsoft.WCF.Documentation.EnforceGreetingFaultBehavior, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
        />
      </behaviorExtensions>
    </extensions>
  </system.serviceModel>
</configuration>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft