ServiceMetadataBehavior Class

 

Controls the publication of service metadata and associated information.

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

System.Object
  System.ServiceModel.Description.ServiceMetadataBehavior

public class ServiceMetadataBehavior : IServiceBehavior

NameDescription
System_CAPS_pubmethodServiceMetadataBehavior()

Initializes a new instance of the ServiceMetadataBehavior class.

NameDescription
System_CAPS_pubpropertyExternalMetadataLocation

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

System_CAPS_pubpropertyHttpGetBinding

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

System_CAPS_pubpropertyHttpGetEnabled

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

System_CAPS_pubpropertyHttpGetUrl

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

System_CAPS_pubpropertyHttpsGetBinding

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

System_CAPS_pubpropertyHttpsGetEnabled

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

System_CAPS_pubpropertyHttpsGetUrl

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

System_CAPS_pubpropertyMetadataExporter

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

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticMexContractName

Returns the string IMetadataContract.

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

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

System_CAPS_pubinterfaceSystem_CAPS_privmethodIServiceBehavior.ApplyDispatchBehavior(ServiceDescription, ServiceHostBase)

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

System_CAPS_pubinterfaceSystem_CAPS_privmethodIServiceBehavior.Validate(ServiceDescription, ServiceHostBase)

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.

        // 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>

.NET Framework
Available since 3.0

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

Return to top
Show: