CallbackBehaviorAttribute CallbackBehaviorAttribute CallbackBehaviorAttribute CallbackBehaviorAttribute Class

定义

在客户端应用程序中配置回调服务实现。Configures a callback service implementation in a client application.

public ref class CallbackBehaviorAttribute sealed : Attribute, System::ServiceModel::Description::IEndpointBehavior
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class CallbackBehaviorAttribute : Attribute, System.ServiceModel.Description.IEndpointBehavior
type CallbackBehaviorAttribute = class
    inherit Attribute
    interface IEndpointBehavior
Public NotInheritable Class CallbackBehaviorAttribute
Inherits Attribute
Implements IEndpointBehavior
继承
CallbackBehaviorAttributeCallbackBehaviorAttributeCallbackBehaviorAttributeCallbackBehaviorAttribute
属性
实现

示例

下面的代码示例演示了回调对象上的 CallbackBehaviorAttribute,它使用 SynchronizationContext 对象确定要封送到的线程,使用 ValidateMustUnderstand 属性强制执行消息验证,并使用 IncludeExceptionDetailInFaults 属性将异常作为 FaultException 对象返回给服务以便进行调试。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();
    }
  }
}

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

注解

使用 CallbackBehaviorAttribute 属性可以配置或扩展客户端应用程序中回调协定实现的执行行为。Use the CallbackBehaviorAttribute attribute to configure or extend the execution behavior of a callback contract implementation in a client application. 针对回调类,此属性与 ServiceBehaviorAttribute 属性执行的功能相同,不同之处在于实例化行为和事务设置。This attribute performs the same function for the callback class as the ServiceBehaviorAttribute attribute with the exception of instancing behavior and transaction settings.

必须将 CallbackBehaviorAttribute 应用到实现回调协定的类。The CallbackBehaviorAttribute must be applied to the class that implements the callback contract. 如果将其应用于非双工协定实现,则会在运行时引发 InvalidOperationException 异常。If applied to a non-duplex contract implementation an InvalidOperationException exception is thrown at runtime.

备注

此外,还可以使用 OperationBehaviorAttribute 属性来进行回调操作实现。You can also use the OperationBehaviorAttribute attribute for the callback operation implementations. 但是,如果对回调操作使用 OperationBehaviorAttribute,则 ReleaseInstanceMode 属性必须为 None,否则会在运行时引发 InvalidOperationException 异常。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:

构造函数

CallbackBehaviorAttribute() CallbackBehaviorAttribute() CallbackBehaviorAttribute() CallbackBehaviorAttribute()

初始化 CallbackBehaviorAttribute 类的新实例。Initializes a new instance of the CallbackBehaviorAttribute class.

属性

AutomaticSessionShutdown AutomaticSessionShutdown AutomaticSessionShutdown AutomaticSessionShutdown

指定是否在服务关闭双工会话时自动关闭会话。Specifies whether to automatically close a session when a service closes a duplex session.

ConcurrencyMode ConcurrencyMode ConcurrencyMode ConcurrencyMode

获取或设置一个值,该值指示服务是支持单线程、多线程还是支持可重入调用。Gets or sets whether a service supports one thread, multiple threads, or reentrant calls.

IgnoreExtensionDataObject IgnoreExtensionDataObject IgnoreExtensionDataObject IgnoreExtensionDataObject

获取或设置一个值,该值指定是否将未知序列化数据发送到网络上。Gets or sets a value that specifies whether to send unknown serialization data onto the wire.

IncludeExceptionDetailInFaults IncludeExceptionDetailInFaults IncludeExceptionDetailInFaults IncludeExceptionDetailInFaults

获取或设置一个值,该值指定是否要将常规未处理执行异常转换为 FaultException<TDetail> 类型的 String 并将其作为错误消息发送。Gets or sets a value that specifies that general unhandled execution exceptions are to be converted into a FaultException<TDetail> of type String and sent as a fault message. 仅在开发阶段将其设置为 true 以便对服务进行故障排除。Set this to true only during development to troubleshoot a service.

MaxItemsInObjectGraph MaxItemsInObjectGraph MaxItemsInObjectGraph MaxItemsInObjectGraph

获取或设置序列化对象中允许的最大项数。Gets or sets the maximum number of items allowed in a serialized object.

TransactionIsolationLevel TransactionIsolationLevel TransactionIsolationLevel TransactionIsolationLevel

指定事务的隔离级别。Specifies the transaction isolation level.

TransactionTimeout TransactionTimeout TransactionTimeout TransactionTimeout

获取或设置事务必须在此期间完成的时间段。Gets or sets the period within which a transaction must complete.

TypeId TypeId TypeId TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)
UseSynchronizationContext UseSynchronizationContext UseSynchronizationContext UseSynchronizationContext

获取或设置一个值,该值指定是否使用当前同步上下文来选择执行的线程。Gets or sets a value that specifies whether to use the current synchronization context to choose the thread of execution.

ValidateMustUnderstand ValidateMustUnderstand ValidateMustUnderstand ValidateMustUnderstand

获取或设置一个值,该值指定是由系统还是由应用程序强制执行 SOAP MustUnderstand 标头处理。Gets or sets a value that specifies whether the system or the application enforces SOAP MustUnderstand header processing.

显式界面实现

IEndpointBehavior.AddBindingParameters(ServiceEndpoint, BindingParameterCollection) IEndpointBehavior.AddBindingParameters(ServiceEndpoint, BindingParameterCollection) IEndpointBehavior.AddBindingParameters(ServiceEndpoint, BindingParameterCollection) IEndpointBehavior.AddBindingParameters(ServiceEndpoint, BindingParameterCollection)

将绑定元素配置为支持回调行为。Configures the binding elements to support the callback behavior.

IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint, ClientRuntime) IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint, ClientRuntime) IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint, ClientRuntime) IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint, ClientRuntime)

将客户端运行库配置为支持回调对象。Configures the client runtime to support the callback object.

IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher) IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher) IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher) IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher)

ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher) 方法的实现。Implementation of the ApplyDispatchBehavior(ServiceEndpoint, EndpointDispatcher) method. 此实现无效。This implementation has no effect.

IEndpointBehavior.Validate(ServiceEndpoint) IEndpointBehavior.Validate(ServiceEndpoint) IEndpointBehavior.Validate(ServiceEndpoint) IEndpointBehavior.Validate(ServiceEndpoint)

在生成运行时之前验证终结点说明。Validates the endpoint description prior to building the runtime.

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于