This documentation is archived and is not being maintained.

ServiceMetadataBehavior Class

Controls the publication of service metadata and associated information.

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

public ref class ServiceMetadataBehavior : IServiceBehavior
public class ServiceMetadataBehavior implements IServiceBehavior
public class ServiceMetadataBehavior implements IServiceBehavior
Not applicable.

Add a ServiceMetadataBehavior object to the ServiceDescription.Behaviors collection (or the <serviceMetadata> element in an application configuration file) to enable or disable the publication of service metadata. However, adding the behavior to a service is not sufficient to enable metadata publication.

  • To enable WS-Transfer GET metadata retrieval, you must also add an endpoint to your service in which the contract is IMetadataExchange. For an example, see How To: Publish Metadata for a Service Using Code. The IMetadataExchange endpoint can be configured as can any other endpoint.

  • To enable HTTP GET metadata retrieval, set the HttpGetEnabled property to true. For details about the address of HTTP GET metadata, see HttpGetEnabled.

The address of the IMetadataExchange endpoint follows the normal rules regarding the combination of base addresses and endpoint addresses. For complete information, see Publishing Metadata.

To enable the publication of metadata using a configuration file, add the <serviceMetadata> element to the <serviceBehaviors> element and associate the element with the <service> element for which you want to publish metadata. For an example, see How to: Publish Metadata for a Service Using a Configuration File. The class has the following members.

  • The HttpGetEnabled property specifies whether metadata is returned for HTTP/GET requests.

  • The HttpGetUrl property (in conjunction with the base addresses) specifies the HTTP/GET address.

  • The HttpsGetEnabled property specifies whether metadata is returned for an HTTPS/GET request.

  • The HttpsGetUrl property (in conjunction with the base addresses) specifies the HTTPS/GET address.

  • The MetadataExporter property returns the underlying exporter.

Typically the ServiceMetadataBehavior is used from an application configuration file. See the Example section for a code example.

The following code example demonstrates the use of ServiceMetadataBehavior in a configuration file to enable metadata support for HTTP GET and WS-Transfer GET requests.

            <add baseAddress="http://localhost:8080/SampleService" />
        <!-- Adds a WS-MetadataExchange endpoint at -->
        <!-- "http://localhost:8080/SampleService/mex" -->
      <behavior name="metadataSupport">
        <!-- Enables the IMetadataExchange endpoint in services that -->
        <!-- use "metadataSupport" in their behaviorConfiguration attribute. -->
        <!-- In addition, the httpGetEnabled and httpGetUrl attributes publish -->
        <!-- Service metadata for retrieval by HTTP/GET at the address -->
        <!-- "http://localhost:8080/SampleService?wsdl" -->
        <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0