Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CallbackBehaviorAttribute Class

Configures a callback service implementation in a client application.

Namespace: System.ServiceModel
Assembly: System.ServiceModel (in system.servicemodel.dll)

[AttributeUsageAttribute(AttributeTargets::Class)] 
public ref class CallbackBehaviorAttribute sealed : public Attribute, IEndpointBehavior
/** @attribute AttributeUsageAttribute(AttributeTargets.Class) */ 
public final class CallbackBehaviorAttribute extends Attribute implements IEndpointBehavior
AttributeUsageAttribute(AttributeTargets.Class) 
public final class CallbackBehaviorAttribute extends Attribute implements IEndpointBehavior
Not applicable.

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 a InvalidOperationException exception is thrown at run time.

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 run time.

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 run-time 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.

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.

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();
    }
  }
}

System.Object
   System.Attribute
    System.ServiceModel.CallbackBehaviorAttribute
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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.