ServiceMetadataBehavior Class
Controls the publication of service metadata and associated information.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
The ServiceMetadataBehavior type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ServiceMetadataBehavior | Initializes a new instance of the ServiceMetadataBehavior class. |
| Name | Description | |
|---|---|---|
![]() | ExternalMetadataLocation | Gets or sets a value that is the location of service metadata. |
![]() | HttpGetBinding | Gets or sets a binding used to configure metadata retrieval when the transport is HTTP. |
![]() | HttpGetEnabled | Gets or sets a value that indicates whether to publish service metadata for retrieval using an HTTP/GET request. |
![]() | HttpGetUrl | Gets or sets the location of metadata publication for HTTP/GET requests. |
![]() | HttpsGetBinding | Gets or sets a binding used to configure metadata retrieval when the transport is HTTPS. |
![]() | HttpsGetEnabled | Gets or sets a value that indicates whether to publish service metadata for retrieval using an HTTPS/GET request. |
![]() | HttpsGetUrl | Gets or sets the location of metadata publication for HTTPS/GET requests. |
![]() | MetadataExporter | Gets or sets the internal MetadataExporter object used to publish the service metadata. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() ![]() | IServiceBehavior::AddBindingParameters | Implementation of IServiceBehavior that configures the underlying bindings to support the behavior. |
![]() ![]() | IServiceBehavior::ApplyDispatchBehavior | Implementation of IServiceBehavior that configures the underlying bindings to support the behavior on the service. |
![]() ![]() | IServiceBehavior::Validate | Implementation of IServiceBehavior that validates that the service description can support the behavior. |
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 more information 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 more information, seePublishing 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.
<configuration>
<system.serviceModel>
<services>
<service
name="Microsoft.WCF.Documentation.SampleService"
behaviorConfiguration="metadataSupport"
>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ServiceMetadata" />
</baseAddresses>
</host>
<endpoint
address="/SampleService"
binding="wsHttpBinding"
contract="Microsoft.WCF.Documentation.ISampleService"
/>
<!-- Adds a WS-MetadataExchange endpoint at -->
<!-- "http://localhost:8080/ServiceMetadata/mex" -->
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<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/ServiceMetadata?wsdl" -->
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
<configuration>
<system.serviceModel>
<services>
<service
name="Microsoft.WCF.Documentation.SampleService"
behaviorConfiguration="metadataSupport"
>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/SampleService" />
</baseAddresses>
</host>
<endpoint
address=""
binding="wsHttpBinding"
contract="Microsoft.WCF.Documentation.ISampleService"
/>
<!-- Adds a WS-MetadataExchange endpoint at -->
<!-- "http://localhost:8080/SampleService/mex" -->
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<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=""/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
