Share via


<serviceMetadata> Element

Specifies the publication of service metadata and associated information.

<system.serviceModel>

  <behaviors>

    <serviceBehaviors>

      <behavior> of <serviceBehaviors>

        <serviceMetadata> Element

                                    
                                    <serviceMetadata 
                                
                                    
                                           
                                    
                                       externalMetadataLocation="String"
                                
                                    
                                         
                                    
                                       httpGetEnabled="Boolean" 
                                
                                    
                                           
                                    
                                       httpGetUrl="String"
                                
                                    
                                         
                                    
                                       httpsGetEnabled="Boolean" 
                                
                                    
                                           
                                    
                                       httpsGetUrl="String"
                                
                                    
                                    />
                                

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute Description

externalMetadataLocation

A Uri that contains the location of a WSDL file, which is returned to the user in response to WSDL and MEX requests instead of the auto-generated WSDL. When this attribute is not set, the default WSDL is returned. The default is an empty string.

httpGetEnabled

A Boolean value that specifies whether to publish service metadata for retrieval using an HTTP/Get request. The default is false.

If the httpGetUrl attribute is not specified, the address at which the metadata is published is the service address plus a "?wsdl". For example, if the service address is "https://localhost:8080/CalculatorService", the HTTP/Get metadata address is "https://localhost:8080/CalculatorService?wsdl".

If this property is false, or the address of the service is not based on HTTP or HTTPS, “?wsdl” is ignored.

httpGetUrl

A Uri that specifies the address at which the metadata is published for retrieval using an HTTP/Get request.

httpsGetEnabled

A Boolean value that specifies whether to publish service metadata for retrieval using an HTTPS/Get request. The default is false.

If the httpsGetUrl attribute is not specified, the address at which the metadata is published is the service address plus a "?wsdl". For example, if the service address is "https://localhost:8080/CalculatorService", the HTTP/Get metadata address is "https://localhost:8080/CalculatorService?wsdl".

If this property is false, or the address of the service is not based on HTTP or HTTPS, “?wsdl” is ignored.

httpsGetUrl

A Uri that specifies the address at which the metadata is published for retrieval using an HTTPS/Get request.

Child Elements

None

Parent Elements

Element Description

<behavior> of <endpointBehaviors>

Specifies a behavior element.

Remarks

This configuration element allows you to control the metadata publishing features of a service. To prevent unintentional disclosure of potentially sensitive service metadata, the default configuration for Windows Communication Foundation (WCF) services disables metadata publishing. This behavior is secure by default, but also means that you cannot use a metadata import tool (such as Svcutil.exe) to generate the client code required to call the service unless the service’s metadata publishing behavior is explicitly enabled in configuration. Using this configuration element, you can enable this publishing behavior for your service.

For a code example of using configuring this behavior, see Metadata Publishing Behavior.

Example

The following example configure a service to expose metadata by using the <serviceMetadata> element. It also configures an endpoint to expose the IMetadataExchange contract as an implementation of a WS-MetadataExchange (MEX) protocol. The example uses the mexHttpBinding, which is a convenience standard binding that is equivalent to the wsHttpBinding with the security mode set to None. A relative address of "mex" is used in the endpoint, which when resolved against the services base address results in an endpoint address of https://localhost/servicemodelsamples/service.svc/mex.

<configuration>
<system.serviceModel>
  <services>
    <service 
        name="Microsoft.ServiceModel.Samples.CalculatorService"
        behaviorConfiguration="CalculatorServiceBehavior">
      <!-- This endpoint is exposed at the base address provided by the host: https://localhost/servicemodelsamples/service.svc  -->
      <endpoint address=""
                binding="wsHttpBinding"
                contract="Microsoft.ServiceModel.Samples.ICalculator" />
      <!-- the mex endpoint is exposed at https://localhost/servicemodelsamples/service.svc/mex 
           To expose the IMetadataExchange contract, you 
           must enable the serviceMetadata behavior as demonstrated below -->
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
    </service>
  </services>

  <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
  <behaviors>
    <serviceBehaviors>
      <behavior name="CalculatorServiceBehavior">
        <!-- The serviceMetadata behavior publishes metadata through 
             the IMetadataExchange contract. When this behavior is 
             present, you can expose this contract through an endpoint 
             as shown above. Setting httpGetEnabled to true publishes 
             the service's WSDL at the <baseaddress>?wsdl
             eg. https://localhost/servicemodelsamples/service.svc?wsdl -->
        <serviceMetadata httpGetEnabled="True"/>
        <serviceDebug includeExceptionDetailInFaults="False" />
      </behavior>
    </serviceBehaviors>
  </behaviors>

</system.serviceModel>

</configuration>

See Also

Reference

ServiceMetadataPublishingElement

Other Resources

Metadata Publishing Behavior

Footer image

Send comments about this topic to Microsoft.
© Microsoft Corporation. All rights reserved.