This documentation is archived and is not being maintained.

TransactedBatchingBehavior Class

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

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

public class TransactedBatchingBehavior implements IEndpointBehavior

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.

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

    <service name="Microsoft.ServiceModel.Samples.CalculatorService"
          <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>

      <!-- Define NetMsmqEndpoint -->
      <endpoint address="net.msmq://localhost/private/ServiceModelSamples"
                contract="Microsoft.ServiceModel.Samples.IQueueCalculator" />

      <!-- the mex endpoint is explosed at http://localhost:8000/ServiceModelSamples/service/mex -->
      <endpoint address="mex"
                contract="IMetadataExchange" />

      <behavior name="endpointBehavior">
        <transactedBatching maxBatchSize="10" />
      <behavior name="CalculatorServiceBehavior">
        <serviceMetadata httpGetEnabled="true" />

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.

    // The service can now be accessed.
    Console.WriteLine("The service is ready.");
    Console.WriteLine("Press <ENTER> to terminate service.");

    // Close the ServiceHost to shutdown the service.


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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0