Redigera

Dela via


ServiceHealthBehavior Class

Definition

Provides a Windows Communication Foundation (WCF) service behavior that provides a health endpoint.

public ref class ServiceHealthBehavior : System::ServiceModel::Description::ServiceHealthBehaviorBase
public class ServiceHealthBehavior : System.ServiceModel.Description.ServiceHealthBehaviorBase
type ServiceHealthBehavior = class
    inherit ServiceHealthBehaviorBase
Public Class ServiceHealthBehavior
Inherits ServiceHealthBehaviorBase
Inheritance
ServiceHealthBehavior

Remarks

Health endpoints are used to perform health checks that assess the health of a component. Health endpoints can be used to:

  • Notify orchestration tools to kill a process that is failing a critical health check.

  • Serve as an early problem indicator for monitoring tools by tracking and providing alerts about the availability and performance of a service.

ServiceHealthBehavior is a WCF service behavior that extends IServiceBehavior and derives from ServiceHealthBehaviorBase. Adding a ServiceHealthBehavior instance to the ServiceDescription.Behaviors collection enables the following:

  • Publication of Service Health: Service-specific details such as service state, throttle counts, and capacity can be displayed using an HTTP/GET request with the ?health query string. Knowing and easily having access to the information displayed is of paramount importance when troubleshooting a misbehaving WCF service.

  • Return of HTTP response codes: One can specify in the query string the HTTP status code for an HTTP/GET health probe request.

A health endpoint is only meaningful in the context of the component whose health it monitors. It has no other meaning or purpose. As such, its health is a conduit to the health of the component. Clients should assume that the HTTP response code returned by the health endpoint is applicable to the entire component. This is compatible with the behavior expected by current infrastructural tooling that utilize health checks, such as load-balancers, service discoveries, and others.

Enable a health endpoint

There are two ways to specify how to expose the health endpoint and publish WCF service health information:

  • By using a configuration file. For example:

    <behaviors>
       <serviceBehaviors>
         <behavior name="DefaultBehavior">
           <serviceHealth httpGetEnabled="true"/>
         </behavior>
       </serviceBehaviors>
    </behaviors>
    
  • Programmatically. The following code fragment uses C# to expose the health endpoint:

    ServiceHost host = new ServiceHost(typeof(Service1),
        new Uri("http://jconde-dev1:81/Service1"));
    ServiceHealthBehavior healthBehavior =
                host.Description.Behaviors.Find<ServiceHealthBehavior>();
    if (healthBehavior == null)
    {
        healthBehavior = new ServiceHealthBehavior();
    }
    //healthBehavior.HttpGetEnabled = false;
    //healthBehavior.HttpsGetEnabled = false;
    host.Description.Behaviors.Add(healthBehavior);
    

Constructors

ServiceHealthBehavior()

Initializes a new instance of the ServiceHealthBehavior class.

Properties

HasXmlSupport

Gets a value that indicates whether XML response messages are supported.

HealthDetailsEnabled

Gets or sets a value that specifies if the health endpoint should return the service details or if the response should contain no content.

(Inherited from ServiceHealthBehaviorBase)
HttpGetBinding

Gets or sets the binding that is used for health retrieval via an HTTP/Get request.

(Inherited from ServiceHealthBehaviorBase)
HttpGetEnabled

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

(Inherited from ServiceHealthBehaviorBase)
HttpGetUrl

Gets or sets a Uri that specifies the address to which metadata is published for retrieval using an HTTP/Get request.

(Inherited from ServiceHealthBehaviorBase)
HttpsGetBinding

Gets or sets the binding that is used for health retrieval via an HTTPS/Get request.

(Inherited from ServiceHealthBehaviorBase)
HttpsGetEnabled

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

(Inherited from ServiceHealthBehaviorBase)
HttpsGetUrl

Gets or sets a Uri that specifies the address to which metadata is published for retrieval using an HTTPS/Get request.

(Inherited from ServiceHealthBehaviorBase)
ServiceStartTime

Gets the date and time that the health check service started.

(Inherited from ServiceHealthBehaviorBase)

Methods

AddHttpProperty(Message, HttpStatusCode, Boolean)

Sets the content type and the HTTP status code for the response message.

EnsureHttpStatusCode(Int32)

Ensure that the HTTP status code is within the range of 200 and 599, inclusive.

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)
GetHttpResponseCode(ServiceHostBase, String[])

Parses the query string fields and returns its defined HTTP response code.

GetServiceHealthSections(ServiceHostBase)

Gets a collection of the ServiceHealthSection objects defined in the ServiceHealthBehavior.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetXmlDocument(ServiceHostBase)

Serializes the ServiceHealthModel object associated with the specified serviceHost and returns it in XML format.

HandleHealthRequest(ServiceHostBase, Message, String[], Message)

Returns the response message to a specified request.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)
TryParseBooleanQueryParameter(String, String, Boolean, Boolean)

Attempts to parse a Boolean query string parameter and returns a value that indicates whether the parsing operation succeeded.

TryParseHttpStatusCodeQueryParameter(String, String, HttpStatusCode, HttpStatusCode)

Attempts to parse the HTTP status code of a query string variable and returns a value that indicates whether the parsing operation succeeded.

Explicit Interface Implementations

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

Passes custom data to binding elements to support the contact implementation.

(Inherited from ServiceHealthBehaviorBase)
IServiceBehavior.ApplyDispatchBehavior(ServiceDescription, ServiceHostBase)

Changes run-time property values or inserts custom extension objects such as error handlers, message or parameter interceptors, security extensions, and other custom extension objects.

(Inherited from ServiceHealthBehaviorBase)
IServiceBehavior.Validate(ServiceDescription, ServiceHostBase)

Inspects the service host and the service description to confirm that the service can run successfully.

(Inherited from ServiceHealthBehaviorBase)

Applies to