Export (0) Print
Expand All

TransactedBatchingBehavior Class

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

System.Object
  System.ServiceModel.Description.TransactedBatchingBehavior

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

public class TransactedBatchingBehavior : IEndpointBehavior

The TransactedBatchingBehavior type exposes the following members.

  NameDescription
Public methodTransactedBatchingBehaviorInitializes a new instance of the TransactedBatchingBehavior class with the specified batch size.
Top

  NameDescription
Public propertyMaxBatchSizeGets or sets the maximum number of receive operations that can be batched together in one transaction.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIEndpointBehavior.AddBindingParametersApplies binding settings to the specified service endpoint. This method cannot be inherited.
Explicit interface implemetationPrivate methodIEndpointBehavior.ApplyClientBehaviorApplies transaction batching behavior settings to the specified service endpoint. This method cannot be inherited.
Explicit interface implemetationPrivate methodIEndpointBehavior.ApplyDispatchBehaviorAssociates an endpoint dispatcher with the specified service endpoint. This method cannot be inherited.
Explicit interface implemetationPrivate methodIEndpointBehavior.ValidateEnsures that transacted batching is applicable only for the bindings that support transacted receive operation. This method cannot be inherited.
Top

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.

<system.serviceModel>
  <services>
    <service name="Microsoft.ServiceModel.Samples.CalculatorService"
             behaviorConfiguration="CalculatorServiceBehavior">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>
        </baseAddresses>
      </host>

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

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

  <behaviors>
    <endpointBehaviors>
      <behavior name="endpointBehavior">
        <transactedBatching maxBatchSize="10" />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="CalculatorServiceBehavior">
        <serviceMetadata httpGetEnabled="true" />
      </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();
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

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