ServiceMetadataBehavior ServiceMetadataBehavior ServiceMetadataBehavior ServiceMetadataBehavior Class

Definition

Controls the publication of service metadata and associated information.

public ref class ServiceMetadataBehavior : System::ServiceModel::Description::IServiceBehavior
public class ServiceMetadataBehavior : System.ServiceModel.Description.IServiceBehavior
type ServiceMetadataBehavior = class
    interface IServiceBehavior
Public Class ServiceMetadataBehavior
Implements IServiceBehavior
Inheritance
ServiceMetadataBehaviorServiceMetadataBehaviorServiceMetadataBehaviorServiceMetadataBehavior
Implements

Examples

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.

        // Create a new metadata behavior object and set its properties to 
        // create a secure endpoint. 
        ServiceMetadataBehavior sb = new ServiceMetadataBehavior();
        //sb.EnableHelpPage= true;
        //sb.HttpsGetUrl = new Uri("https://myMachineName:8036/myEndpoint");
        //myServiceHost.Description.Behaviors.Add(sb);
            

    }

      private void SnippetServiceMetadataBehavior()
      {
          // service for which <<indigo2>> automatically adds a 
          // ServiceMetadataBehavior to publish metadata as well as 
          // an HTML service help page

          // from C_HowToSecureEndpoint\cs
          // Create a new metadata behavior object and set its properties to 
          // create a secure endpoint. 
          ServiceMetadataBehavior sb = new ServiceMetadataBehavior();
/*          sb.EnableHelpPage = true;
          sb.enableMetadataExchange = true;
          sb.HttpsGetUrl = new Uri("https://myMachineName:8036/myEndpoint");
          myServiceHost.Description.Behaviors.Add(sb);
 */


      }

    private void Run()
    {

      // T:System.ServiceModel.ServiceMetadataBehavior
      // <Snippet#0>

      // Create a ServiceHost for the service type and use the base address from configuration.
      ServiceHost host = new ServiceHost(typeof(SampleService));
      try
      {
        ServiceMetadataBehavior metad 
          = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
        if (metad == null)
          metad = new ServiceMetadataBehavior();
        metad.HttpGetEnabled = true;
        host.Description.Behaviors.Add(metad);
        host.AddServiceEndpoint(
          ServiceMetadataBehavior.MexContractName, 
          MetadataExchangeBindings.CreateMexHttpBinding(), 
          "mex"
        );

        // The service can now be accessed.
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");
        Console.WriteLine();
        Console.ReadLine();

        // Close the ServiceHostBase to shutdown the service.
        host.Close();

        // </Snippet#0>

Remarks

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, 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.

Constructors

ServiceMetadataBehavior() ServiceMetadataBehavior() ServiceMetadataBehavior() ServiceMetadataBehavior()

Initializes a new instance of the ServiceMetadataBehavior class.

Fields

MexContractName MexContractName MexContractName MexContractName

Returns the string IMetadataContract.

Properties

ExternalMetadataLocation ExternalMetadataLocation ExternalMetadataLocation ExternalMetadataLocation

Gets or sets a value that is the location of service metadata.

HttpGetBinding HttpGetBinding HttpGetBinding HttpGetBinding

Gets or sets a binding used to configure metadata retrieval when the transport is HTTP.

HttpGetEnabled HttpGetEnabled HttpGetEnabled HttpGetEnabled

Gets or sets a value that indicates whether to publish service metadata for retrieval using an HTTP/GET request.

HttpGetUrl HttpGetUrl HttpGetUrl HttpGetUrl

Gets or sets the location of metadata publication for HTTP/GET requests.

HttpsGetBinding HttpsGetBinding HttpsGetBinding HttpsGetBinding

Gets or sets a binding used to configure metadata retrieval when the transport is HTTPS.

HttpsGetEnabled HttpsGetEnabled HttpsGetEnabled HttpsGetEnabled

Gets or sets a value that indicates whether to publish service metadata for retrieval using an HTTPS/GET request.

HttpsGetUrl HttpsGetUrl HttpsGetUrl HttpsGetUrl

Gets or sets the location of metadata publication for HTTPS/GET requests.

MetadataExporter MetadataExporter MetadataExporter MetadataExporter

Gets or sets the internal MetadataExporter object used to publish the service metadata.

Explicit Interface Implementations

IServiceBehavior.AddBindingParameters(ServiceDescription, ServiceHostBase, Collection<ServiceEndpoint>, BindingParameterCollection) IServiceBehavior.AddBindingParameters(ServiceDescription, ServiceHostBase, Collection<ServiceEndpoint>, BindingParameterCollection) IServiceBehavior.AddBindingParameters(ServiceDescription, ServiceHostBase, Collection<ServiceEndpoint>, BindingParameterCollection) IServiceBehavior.AddBindingParameters(ServiceDescription, ServiceHostBase, Collection<ServiceEndpoint>, BindingParameterCollection)

Implementation of IServiceBehavior that configures the underlying bindings to support the behavior.

IServiceBehavior.ApplyDispatchBehavior(ServiceDescription, ServiceHostBase) IServiceBehavior.ApplyDispatchBehavior(ServiceDescription, ServiceHostBase) IServiceBehavior.ApplyDispatchBehavior(ServiceDescription, ServiceHostBase) IServiceBehavior.ApplyDispatchBehavior(ServiceDescription, ServiceHostBase)

Implementation of IServiceBehavior that configures the underlying bindings to support the behavior on the service.

IServiceBehavior.Validate(ServiceDescription, ServiceHostBase) IServiceBehavior.Validate(ServiceDescription, ServiceHostBase) IServiceBehavior.Validate(ServiceDescription, ServiceHostBase) IServiceBehavior.Validate(ServiceDescription, ServiceHostBase)

Implementation of IServiceBehavior that validates that the service description can support the behavior.

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to