IOperationBehavior.ApplyDispatchBehavior 方法

定义

在操作范围内执行服务的修改或扩展。

public:
 void ApplyDispatchBehavior(System::ServiceModel::Description::OperationDescription ^ operationDescription, System::ServiceModel::Dispatcher::DispatchOperation ^ dispatchOperation);
public void ApplyDispatchBehavior (System.ServiceModel.Description.OperationDescription operationDescription, System.ServiceModel.Dispatcher.DispatchOperation dispatchOperation);
abstract member ApplyDispatchBehavior : System.ServiceModel.Description.OperationDescription * System.ServiceModel.Dispatcher.DispatchOperation -> unit
Public Sub ApplyDispatchBehavior (operationDescription As OperationDescription, dispatchOperation As DispatchOperation)

参数

operationDescription
OperationDescription

正在检查的操作。 仅用于检查。 如果修改了操作说明,则结果将不确定。

dispatchOperation
DispatchOperation

公开 operationDescription 所描述的操作的自定义属性的运行时对象。

示例

下面的代码示例演示了 System.ServiceModel.Dispatcher.IParameterInspector 的实现,对操作调用该检查器时,该检查器对控制台进行了写入。 此自定义只能附加到 System.ServiceModel.Dispatcher.DispatchOperationSystem.ServiceModel.Dispatcher.ClientOperation,因此,此自定义通常由操作行为插入。

#region IParameterInspector Members
public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
{
  Console.WriteLine(
    "IParameterInspector.AfterCall called for {0} with return value {1}.",
    operationName,
    returnValue.ToString()
  );
}

public object BeforeCall(string operationName, object[] inputs)
{
  Console.WriteLine("IParameterInspector.BeforeCall called for {0}.", operationName);
  return null;
}
#Region "IParameterInspector Members"
    Public Sub AfterCall(ByVal operationName As String, ByVal outputs() As Object, ByVal returnValue As Object, _
                         ByVal correlationState As Object) Implements IParameterInspector.AfterCall
        Console.WriteLine("IParameterInspector.AfterCall called for {0} with return value {1}.", _
                          operationName, returnValue.ToString())
    End Sub

    Public Function BeforeCall(ByVal operationName As String, ByVal inputs() As Object) As Object Implements _
    IParameterInspector.BeforeCall
        Console.WriteLine("IParameterInspector.BeforeCall called for {0}.", operationName)
        Return Nothing
    End Function

下面的代码示例演示了操作行为是如何将参数检查器附加到运行时的。

#region IOperationBehavior Members
public void AddBindingParameters(
  OperationDescription operationDescription, BindingParameterCollection bindingParameters
)
{ return; }

public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
{
  clientOperation.ParameterInspectors.Add(new Inspector());
}

public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
  dispatchOperation.ParameterInspectors.Add(new Inspector());
}

public void Validate(OperationDescription operationDescription){ return; }
#Region "IOperationBehavior Members"
    Public Sub AddBindingParameters(ByVal operationDescription As OperationDescription, _
                                    ByVal bindingParameters As BindingParameterCollection) Implements _
                                    IOperationBehavior.AddBindingParameters
        Return
    End Sub

    Public Sub ApplyClientBehavior(ByVal operationDescription As OperationDescription, ByVal _
                                   clientOperation As ClientOperation) Implements IOperationBehavior.ApplyClientBehavior
        clientOperation.ParameterInspectors.Add(New Inspector())
    End Sub

    Public Sub ApplyDispatchBehavior(ByVal operationDescription As OperationDescription, ByVal dispatchOperation As  _
                                     DispatchOperation) Implements IOperationBehavior.ApplyDispatchBehavior
        dispatchOperation.ParameterInspectors.Add(New Inspector())
    End Sub

Public Sub Validate(ByVal operationDescription As OperationDescription) Implements IOperationBehavior.Validate
    Return
End Sub

注解

实现 ApplyDispatchBehavior 方法可以在所有消息范围内或针对某个特定操作,查看、修改或扩展服务运行时。 有关可在服务应用程序中进行的自定义的详细信息,请参见 System.ServiceModel.Dispatcher.DispatchRuntimeSystem.ServiceModel.Dispatcher.DispatchOperation

如果该行为仅用于客户端应用程序中,则建议 ApplyDispatchBehavior 方法引发 NotImplementedException 异常。

适用于