ServiceSecurityAuditBehavior ServiceSecurityAuditBehavior ServiceSecurityAuditBehavior ServiceSecurityAuditBehavior Class

Definition

Specifies the audit behavior of security events. In general, the security events consist of authentication events such as transport, message or negotiate authentication and authorization event. For more information, see ServiceAuthorizationManager.

public ref class ServiceSecurityAuditBehavior sealed : System::ServiceModel::Description::IServiceBehavior
public sealed class ServiceSecurityAuditBehavior : System.ServiceModel.Description.IServiceBehavior
type ServiceSecurityAuditBehavior = class
    interface IServiceBehavior
Public NotInheritable Class ServiceSecurityAuditBehavior
Implements IServiceBehavior
Inheritance
ServiceSecurityAuditBehaviorServiceSecurityAuditBehaviorServiceSecurityAuditBehaviorServiceSecurityAuditBehavior
Implements

Examples

The following code creates an instance of the ServiceHost class and adds a new ServiceSecurityAuditBehavior to its collection of behaviors.

public static void Main()
{
    // Get base address from appsettings in configuration.
    Uri baseAddress = new Uri(ConfigurationManager.
        AppSettings["baseAddress"]);

    // Create a ServiceHost for the CalculatorService type 
    // and provide the base address.
    using (ServiceHost serviceHost = new 
        ServiceHost(typeof(CalculatorService), baseAddress))
    {
        // Create a new auditing behavior and set the log location.
        ServiceSecurityAuditBehavior newAudit = 
            new ServiceSecurityAuditBehavior();
        newAudit.AuditLogLocation = 
            AuditLogLocation.Application;
        newAudit.MessageAuthenticationAuditLevel = 
            AuditLevel.SuccessOrFailure;
        newAudit.ServiceAuthorizationAuditLevel = 
            AuditLevel.SuccessOrFailure;
        newAudit.SuppressAuditFailure = false;
        // Remove the old behavior and add the new.
        serviceHost.Description.
            Behaviors.Remove<ServiceSecurityAuditBehavior>();
        serviceHost.Description.Behaviors.Add(newAudit);
        // Open the ServiceHostBase to create listeners 
        // and start listening for messages.
        serviceHost.Open();

        // 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.
        serviceHost.Close();
    }
}
Public Shared Sub Main() 
    ' Get base address from appsettings in configuration.
    Dim baseAddress As New Uri(ConfigurationManager.AppSettings("baseAddress"))
    
    ' Create a ServiceHost for the CalculatorService type 
    ' and provide the base address.
    Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)
    Try
        ' Create a new auditing behavior and set the log location.
        Dim newAudit As New ServiceSecurityAuditBehavior()
        newAudit.AuditLogLocation = AuditLogLocation.Application
        newAudit.MessageAuthenticationAuditLevel = _
            AuditLevel.SuccessOrFailure
        newAudit.ServiceAuthorizationAuditLevel = _
            AuditLevel.SuccessOrFailure
        newAudit.SuppressAuditFailure = False
        ' Remove the old behavior and add the new.
        serviceHost.Description.Behaviors.Remove(Of ServiceSecurityAuditBehavior)
        serviceHost.Description.Behaviors.Add(newAudit)
        ' Open the ServiceHostBase to create listeners 
        ' and start listening for messages.
        serviceHost.Open()
        
        ' 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.
        serviceHost.Close()
    Finally
    End Try

End Sub 

Remarks

The ServiceSecurityAuditBehavior class is used to audit Windows Communication Foundation (WCF) authentication events. When auditing is enabled, either successful or failed authentication attempts (or both) can be audited. The events are written to one of three event logs: application, security, or the default log for the operating system version. The event logs can all be viewed using the Windows Event viewer.

Use this class to specify which event log is written to, as well as kinds of authentication events to write. You can also specify whether to suppress audit failures by setting the SuppressAuditFailure property to false (the default is true).

For more information about auditing security events for WCF applications, see Auditing.

To specify audit behavior in configuration, use the <serviceSecurityAudit>.

Constructors

ServiceSecurityAuditBehavior() ServiceSecurityAuditBehavior() ServiceSecurityAuditBehavior() ServiceSecurityAuditBehavior()

Initializes a new instance of the ServiceSecurityAuditBehavior class.

Properties

AuditLogLocation AuditLogLocation AuditLogLocation AuditLogLocation

Gets or sets the location where secure-related event logs are written.

MessageAuthenticationAuditLevel MessageAuthenticationAuditLevel MessageAuthenticationAuditLevel MessageAuthenticationAuditLevel

Gets or sets the type of authentication events to audit at the message level.

ServiceAuthorizationAuditLevel ServiceAuthorizationAuditLevel ServiceAuthorizationAuditLevel ServiceAuthorizationAuditLevel

Gets or sets the type of authorization events to audit at the service level.

SuppressAuditFailure SuppressAuditFailure SuppressAuditFailure SuppressAuditFailure

Gets or sets a value that indicates whether failure to audit affects the application.

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)

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

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

Provides the ability to change run-time property values or insert custom extension objects such as error handlers, message or parameter interceptors, security extensions, and other custom extension objects.

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

Not implemented.

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