Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
<behaviors>
<serviceBehaviors>
<behavior>
 <serviceMetadata>
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
<serviceMetadata>

Specifies the publication of service metadata and associated information.

<serviceMetadata 
    externalMetadataLocation="String"
    httpGetBinding=”String”
    httpGetEnabled="Boolean" 
    httpGetUrl="String"
    httpsGetBinding=”String”
    httpsGetEnabled="Boolean" 
    httpsGetUrl="String"
    policyVersion="Policy12/Policy15"/>

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.

httpGetBinding

A string value that allows the binding to be used in HTTP GET scenarios to be specified by name.

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 "http://localhost:8080/CalculatorService", the HTTP/Get metadata address is "http://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.

httpsGetBinding

A string value that allows the binding to be used in HTTPS GET scenarios to be specified by name.

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.

policyVersion

A string that specifies the version of the WS-Policy specification being used. This attribute is of type PolicyVersion.

Child Elements

None

Parent Elements

Element Description

<behavior> of <endpointBehaviors>

Specifies a behavior element.

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 detailed code example of configuring this behavior, see Metadata Publishing Behavior.

The optional httpGetBinding and httpsGetBinding attributes allow you to configure the bindings used for metadata retrieval via HTTP GET (or HTTPS GET). If they are not specified, the default bindings (HttpTransportBindingElement, in the case of HTTP and HttpsTransportBindingElement, in the case of HTTPS) are used for metadata retrieval as appropriate. Notice that you cannot use these attributes with the built-in WCF bindings. Only bindings with inner binding elements that support System.ServiceModel.Channels.IReplyChannel will be supported. Additionally, the System.ServiceModel.Channels.MessageVersion property of the binding must be System.ServiceModel.Channels.MessageVersion.None.

To reduce the exposure of a service to malicious users, it is possible to secure the transfer using the SSL over HTTP (HTTPS) mechanism. To do so, you must first bind a suitable X.509 certificate to a specific port on the computer that is hosting the service. (For more information, see Working with Certificates.) Second, add this element to the service configuration and set the httpsGetEnabled attribute to true. Finally, set the httpsGetUrl attribute to the URL of the service metadata endpoint, as shown in the following example.

<behaviors>
 <serviceBehaviors>
  <behavior name="NewBehavior">
    <serviceMetadata httpsGetEnabled="true" 
     httpsGetUrl="https://myComputerName/myEndpoint" />
  </behavior>
 </serviceBehaviors>
</behaviors>

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 http://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: http://localhost/servicemodelsamples/service.svc  -->
      <endpoint address=""
                binding="wsHttpBinding"
                contract="Microsoft.ServiceModel.Samples.ICalculator" />
      <!-- the mex endpoint is exposed at http://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. http://localhost/servicemodelsamples/service.svc?wsdl -->
        <serviceMetadata httpGetEnabled="True"/>
        <serviceDebug includeExceptionDetailInFaults="False" />
      </behavior>
    </serviceBehaviors>
  </behaviors>

</system.serviceModel>

</configuration>


© 2007 Microsoft Corporation. All rights reserved.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Showing the serviceMetadata in an ASP.NET AJAX Service      Ken Cox - MVP   |   Edit   |   Show History

Here's an example of configuring a web.config file to show the meta data for an ASP.NET 3.5 AJAX WCF service.

In this case, you first add the service using Add New Item -> AJAX-Enabled WCF Service -> (Name WeatherService.svc) -> Add.

Next, configure the web.config's <system.serviceModel> section to look like this:

<system.serviceModel>
<services>
<service name="WeatherService"
behaviorConfiguration="WeatherServiceAspNetAjaxBehavior">
<endpoint address=""
binding="webHttpBinding" contract="WeatherService" />
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="WeatherServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WeatherServiceAspNetAjaxBehavior" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker