Redigera

Dela via


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
ServiceMetadataBehavior
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()

Initializes a new instance of the ServiceMetadataBehavior class.

Fields

MexContractName

Returns the string IMetadataContract.

Properties

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.

Methods

Equals(Object)

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

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(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)

Explicit Interface Implementations

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

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

IServiceBehavior.ApplyDispatchBehavior(ServiceDescription, ServiceHostBase)

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

IServiceBehavior.Validate(ServiceDescription, ServiceHostBase)

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

Applies to