Redigera

Dela via


TransactedBatchingBehavior Class

Definition

Represents a behavior that optimizes the receive operations for transports that support transactional receives.

public ref class TransactedBatchingBehavior : System::ServiceModel::Description::IEndpointBehavior
public class TransactedBatchingBehavior : System.ServiceModel.Description.IEndpointBehavior
type TransactedBatchingBehavior = class
    interface IEndpointBehavior
Public Class TransactedBatchingBehavior
Implements IEndpointBehavior
Inheritance
TransactedBatchingBehavior
Implements

Examples

The following example shows how to add the transacted batching behavior to a service in a configuration file.

<system.serviceModel>
  <services>
    <service name="Microsoft.ServiceModel.Samples.CalculatorService"
             behaviorConfiguration="CalculatorServiceBehavior">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>
        </baseAddresses>
      </host>
     
      <endpoint address="net.msmq://localhost/private/ServiceModelSamples"
                binding="netMsmqBinding"
                contract="Microsoft.ServiceModel.Samples.IQueueCalculator" />
     
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="CalculatorServiceBehavior">
        <serviceMetadata httpGetEnabled="True"/>
      </behavior>
      <behavior name="transactedBatching" maxBatchSize="10">
      </behavior>
    </serviceBehaviors>
  </behaviors>

</system.serviceModel>

The following example shows how to add the transacted batching behavior to a service in code.

// Note: Service class must be marked with [ServiceBehavior(ReleaseServiceInstanceOnTransactionComplete=false)].

Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/service");

// Create a ServiceHost for the CalculatorService type.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
    ServiceEndpoint endpoint;
    endpoint = serviceHost.AddServiceEndpoint(typeof(IQueueCalculator), new NetMsmqBinding(),"net.msmq://localhost/private/ServiceModelSamples");
    endpoint.Behaviors.Add(new TransactedBatchingBehavior(10));

    // Open the ServiceHost 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 ServiceHost to shutdown the service.
    serviceHost.Close();
}

Remarks

A transport that is configured with this behavior attempts to batch several receive operations into one transaction. By doing so, the relatively high cost of creating a transaction and committing it in every receive operation is avoided.

Constructors

TransactedBatchingBehavior(Int32)

Initializes a new instance of the TransactedBatchingBehavior class with the specified batch size.

Properties

MaxBatchSize

Gets or sets the maximum number of receive operations that can be batched together in one transaction.

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

IEndpointBehavior.AddBindingParameters(ServiceEndpoint, BindingParameterCollection)

Applies binding settings to the specified service endpoint. This method cannot be inherited.

IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint, ClientRuntime)

Applies transaction batching behavior settings to the specified service endpoint. This method cannot be inherited.

IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher)

Associates an endpoint dispatcher with the specified service endpoint. This method cannot be inherited.

IEndpointBehavior.Validate(ServiceEndpoint)

Ensures that transacted batching is applicable only for the bindings that support transacted receive operation. This method cannot be inherited.

Applies to