.NET Framework Class Library
CallbackBehaviorAttribute Class

Configures a callback service implementation in a client application.

Inheritance Hierarchy
SystemObject
   SystemAttribute
    System.ServiceModelCallbackBehaviorAttribute

Namespace:   System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)
Syntax
<[%$TOPIC/ms586338_en-us_VS_110_2_0_0_0_0%]([%$TOPIC/ms586338_en-us_VS_110_2_0_0_0_1%].Class)> _
Public NotInheritable Class CallbackBehaviorAttribute _
	Inherits [%$TOPIC/ms586338_en-us_VS_110_2_0_0_0_2%] _
	Implements [%$TOPIC/ms586338_en-us_VS_110_2_0_0_0_3%]
[[%$TOPIC/ms586338_en-us_VS_110_2_0_1_0_0%]([%$TOPIC/ms586338_en-us_VS_110_2_0_1_0_1%].Class)]
public sealed class CallbackBehaviorAttribute : [%$TOPIC/ms586338_en-us_VS_110_2_0_1_0_2%], 
	[%$TOPIC/ms586338_en-us_VS_110_2_0_1_0_3%]
[[%$TOPIC/ms586338_en-us_VS_110_2_0_2_0_0%]([%$TOPIC/ms586338_en-us_VS_110_2_0_2_0_1%]::Class)]
public ref class CallbackBehaviorAttribute sealed : public [%$TOPIC/ms586338_en-us_VS_110_2_0_2_0_2%], 
	[%$TOPIC/ms586338_en-us_VS_110_2_0_2_0_3%]
[<[%$TOPIC/ms586338_en-us_VS_110_2_0_3_0_0%]>]
[<[%$TOPIC/ms586338_en-us_VS_110_2_0_3_0_1%]([%$TOPIC/ms586338_en-us_VS_110_2_0_3_0_2%].Class)>]
type CallbackBehaviorAttribute =  
    class 
        inherit [%$TOPIC/ms586338_en-us_VS_110_2_0_3_0_3%] 
        interface [%$TOPIC/ms586338_en-us_VS_110_2_0_3_0_4%] 
    end

The CallbackBehaviorAttribute type exposes the following members.

Constructors
  NameDescription
Public method Supported in .NET for Windows Store apps CallbackBehaviorAttributeInitializes a new instance of the CallbackBehaviorAttribute class.
Top
Properties
  NameDescription
Public property Supported in .NET for Windows Store apps AutomaticSessionShutdownSpecifies whether to automatically close a session when a service closes a duplex session.
Public property ConcurrencyModeGets or sets whether a service supports one thread, multiple threads, or reentrant calls.
Public property IgnoreExtensionDataObjectGets or sets a value that specifies whether to send unknown serialization data onto the wire.
Public property IncludeExceptionDetailInFaultsGets or sets a value that specifies that general unhandled execution exceptions are to be converted into a FaultExceptionTDetailof type String and sent as a fault message. Set this to true only during development to troubleshoot a service.
Public property MaxItemsInObjectGraphGets or sets the maximum number of items allowed in a serialized object.
Public property TransactionIsolationLevelSpecifies the transaction isolation level.
Public property TransactionTimeoutGets or sets the period within which a transaction must complete.
Public property TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Public property Supported in .NET for Windows Store apps UseSynchronizationContextGets or sets a value that specifies whether to use the current synchronization context to choose the thread of execution.
Public property ValidateMustUnderstandGets or sets a value that specifies whether the system or the application enforces SOAP MustUnderstand header processing.
Top
Methods
  NameDescription
Public method Supported in .NET for Windows Store apps EqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Public method Supported in .NET for Windows Store apps GetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public method Supported in .NET for Windows Store apps GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public method MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Public method Supported in .NET for Windows Store apps ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method _AttributeGetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoRetrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeInvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)
Explicit interface implemetation Private method Supported in .NET for Windows Store apps IEndpointBehaviorAddBindingParametersConfigures the binding elements to support the callback behavior.
Explicit interface implemetation Private method Supported in .NET for Windows Store apps IEndpointBehaviorApplyClientBehaviorConfigures the client runtime to support the callback object.
Explicit interface implemetation Private method Supported in .NET for Windows Store apps IEndpointBehaviorApplyDispatchBehaviorImplementation of the ApplyDispatchBehavior method. This implementation has no effect.
Explicit interface implemetation Private method Supported in .NET for Windows Store apps IEndpointBehaviorValidateValidates the endpoint description prior to building the runtime.
Top
Remarks

Use the CallbackBehaviorAttribute attribute to configure or extend the execution behavior of a callback contract implementation in a client application. This attribute performs the same function for the callback class as the ServiceBehaviorAttribute attribute with the exception of instancing behavior and transaction settings.

The CallbackBehaviorAttribute must be applied to the class that implements the callback contract. If applied to a non-duplex contract implementation an InvalidOperationException exception is thrown at runtime.

NoteNote

You can also use the OperationBehaviorAttribute attribute for the callback operation implementations. However, if OperationBehaviorAttribute is used on a callback operation, the ReleaseInstanceMode property must be None or an InvalidOperationException exception is thrown at runtime.

The following properties are available:

  • The AutomaticSessionShutdown property automatically closes the session when the channel is closed and the callback has finished processing any remaining messages.

  • The ConcurrencyMode property controls the internal threading model, enabling support for reentrant or multithreaded callback objects.

  • The IgnoreExtensionDataObject property enables the runtime to ignore extra serialization information that is not required to process the message.

  • The IncludeExceptionDetailInFaults property specifies whether unhandled exceptions in a service are returned to the service as SOAP faults for debugging purposes.

  • The MaxItemsInObjectGraph property limits on the number of items in an object graph that are serialized.

  • The TransactionIsolationLevel property specifies the transaction isolation level that the contract supports.

  • The TransactionTimeout property specifies the time period within which a transaction must complete or it aborts.

  • The UseSynchronizationContext property indicates whether to synchronize inbound method calls automatically using the current SynchronizationContext object.

  • The ValidateMustUnderstand property informs the system whether it should confirm that SOAP headers marked as MustUnderstand have, in fact, been understood.

Examples

The following code example shows a CallbackBehaviorAttribute on a callback object that uses the SynchronizationContext object to determine which thread to marshal to, the ValidateMustUnderstand property to enforce message validation, and the IncludeExceptionDetailInFaults property to return exceptions as FaultException objects to the service for debugging purposes.

Imports Microsoft.VisualBasic
Imports System
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Threading

Namespace Microsoft.WCF.Documentation
  <CallbackBehaviorAttribute(IncludeExceptionDetailInFaults:= True, UseSynchronizationContext:=True, ValidateMustUnderstand:=True)> _
  Public Class Client
	  Implements SampleDuplexHelloCallback
	Private waitHandle As AutoResetEvent

	Public Sub New()
	  waitHandle = New AutoResetEvent(False)
	End Sub 

	Public Sub Run()
	  ' Picks up configuration from the configuration file. 
	  Dim wcfClient As New SampleDuplexHelloClient(New InstanceContext(Me), "WSDualHttpBinding_SampleDuplexHello")
	  Try
		Console.ForegroundColor = ConsoleColor.White
		Console.WriteLine("Enter a greeting to send and press ENTER: ")
		Console.Write(">>> ")
		Console.ForegroundColor = ConsoleColor.Green
		Dim greeting As String = Console.ReadLine()
		Console.ForegroundColor = ConsoleColor.White
		Console.WriteLine("Called service with: " & Constants.vbCrLf & Constants.vbTab & greeting)
		wcfClient.Hello(greeting)
		Console.WriteLine("Execution passes service call and moves to the WaitHandle.")
		Me.waitHandle.WaitOne()
		Console.ForegroundColor = ConsoleColor.Blue
		Console.WriteLine("Set was called.")
		Console.Write("Press ")
		Console.ForegroundColor = ConsoleColor.Red
		Console.Write("ENTER")
		Console.ForegroundColor = ConsoleColor.Blue
		Console.Write(" to exit...")
		Console.ReadLine()
	  Catch timeProblem As TimeoutException
		Console.WriteLine("The service operation timed out. " & timeProblem.Message)
		Console.ReadLine()
	  Catch commProblem As CommunicationException
		Console.WriteLine("There was a communication problem. " & commProblem.Message)
		Console.ReadLine()
	  End Try 
	End Sub 
	Public Shared Sub Main()
	  Dim client As New Client()
	  client.Run()
	End Sub 

	Public Sub Reply(ByVal response As String) Implements SampleDuplexHelloCallback.Reply
	  Console.WriteLine("Received output.")
	  Console.WriteLine(Constants.vbCrLf & Constants.vbTab & response)
	  Me.waitHandle.Set()
	End Sub 
  End Class 
End Namespace
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading;

namespace Microsoft.WCF.Documentation
{
  [CallbackBehaviorAttribute(
   IncludeExceptionDetailInFaults= true, 
    UseSynchronizationContext=true,
    ValidateMustUnderstand=true
  )]
  public class Client : SampleDuplexHelloCallback
  {
    AutoResetEvent waitHandle;

    public Client()
    {
      waitHandle = new AutoResetEvent(false);
    }

    public void Run()
    {
      // Picks up configuration from the configuration file.
      SampleDuplexHelloClient wcfClient
        = new SampleDuplexHelloClient(new InstanceContext(this), "WSDualHttpBinding_SampleDuplexHello");
      try
      {
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("Enter a greeting to send and press ENTER: ");
        Console.Write(">>> ");
        Console.ForegroundColor = ConsoleColor.Green;
        string greeting = Console.ReadLine();
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("Called service with: \r\n\t" + greeting);
        wcfClient.Hello(greeting);
        Console.WriteLine("Execution passes service call and moves to the WaitHandle.");
        this.waitHandle.WaitOne();
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.WriteLine("Set was called.");
        Console.Write("Press ");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write("ENTER");
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.Write(" to exit...");
        Console.ReadLine();
      }
      catch (TimeoutException timeProblem)
      {
        Console.WriteLine("The service operation timed out. " + timeProblem.Message);
        Console.ReadLine();
      }
      catch (CommunicationException commProblem)
      {
        Console.WriteLine("There was a communication problem. " + commProblem.Message);
        Console.ReadLine();
      }
    }
    public static void Main()
    {
      Client client = new Client();
      client.Run();
    }

    public void Reply(string response)
    {
      Console.WriteLine("Received output.");
      Console.WriteLine("\r\n\t" + response);
      this.waitHandle.Set();
    }
  }
}
Version Information

.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

.NET for Windows Store apps

Supported in: Windows 8
Platforms

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.

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