IOperationBehavior.ApplyClientBehavior 方法

定义

在操作范围内执行客户端的修改或扩展。

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

参数

operationDescription
OperationDescription

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

clientOperation
ClientOperation

公开 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

注解

实现 ApplyClientBehavior 方法可以在通过特定操作使用的所有消息范围内,查看、修改或添加对客户端运行时中的自定义扩展。 有关利用客户端运行时对象可进行的自定义的详细信息,请参见 ClientRuntimeClientOperation

如果该行为仅用于服务应用程序中,则建议 ApplyClientBehavior 方法引发 NotImplementedException

适用于