共用方式為


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 例外狀況。

適用於