IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation) IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation) IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation) Method

Определение

Реализует изменение или расширение службы во всей операции.Implements a modification or extension of the service across an operation.

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

Параметры

operationDescription
OperationDescription OperationDescription OperationDescription

Проверяемая операция.The operation being examined. Использовать только для проверки.Use for examination only. Если изменяется описание операции, то результаты будут не определены.If the operation description is modified, the results are undefined.

dispatchOperation
DispatchOperation DispatchOperation DispatchOperation

Объект времени выполнения, предоставляющий свойства настройки для операции, описываемой объектом operationDescription.The run-time object that exposes customization properties for the operation described by operationDescription.

Примеры

В следующем примере кода показана реализация интерфейса System.ServiceModel.Dispatcher.IParameterInspector, который осуществляет запись в консоль при вызове инспектора в операции.The following code example shows an implementation of System.ServiceModel.Dispatcher.IParameterInspector that writes to the console when the inspector is invoked on an operation. Эта настройка может быть присоединена только к объекту System.ServiceModel.Dispatcher.DispatchOperation или объекту System.ServiceModel.Dispatcher.ClientOperation, и поэтому обычно вставляется поведением операции.This customization can only be attached to the System.ServiceModel.Dispatcher.DispatchOperation or System.ServiceModel.Dispatcher.ClientOperation and is therefore usually inserted by an operation behavior.

#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

В следующем примере показано, как поведение операции присоединяет инспектор параметров к среде выполнения.The following code example shows how the operation behavior attaches the parameter inspector to the runtime.

#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 реализуется для просмотра, изменения или расширения среды выполнения службы для всех сообщений или для конкретной операции.Implement the ApplyDispatchBehavior method to view, modify, or extend the service runtime across all messages or for a specific operation. Сведения о том, какие настройки можно выполнить в приложении службы, см. в разделах System.ServiceModel.Dispatcher.DispatchRuntime и System.ServiceModel.Dispatcher.DispatchOperation.For details about what customizations you can do in a service application, see System.ServiceModel.Dispatcher.DispatchRuntime and System.ServiceModel.Dispatcher.DispatchOperation.

Рекомендуется, чтобы метод ApplyDispatchBehavior вызвал исключение NotImplementedException, если поведение предназначено для использования только в клиентском приложении.It is recommended that the ApplyDispatchBehavior method throw a NotImplementedException exception if the behavior is only intended for use in a client application.

Применяется к