1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.ServiceModel.Activities.Description
{
using System.Runtime;
using System.ServiceModel.Activities.Dispatcher;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
class ControlOperationBehavior : IOperationBehavior
{
bool isWrappedMode;
//There are two modes of operation.
// 1) IWorkflowControlServiceOperations :: Implemented completley by the ControlOperationInvoker.
// 2) Infrastructure endpoints(Delay/Compensation/OCS) where we wrap their invoker over ControlOperationInvoker.
public ControlOperationBehavior(bool isWrappedMode)
{
this.isWrappedMode = isWrappedMode;
}
public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
{
}
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
ServiceHostBase serviceHost = dispatchOperation.Parent.ChannelDispatcher.Host;
if (!(serviceHost is WorkflowServiceHost))
{
throw FxTrace.Exception.AsError(
new InvalidOperationException(SR.WorkflowBehaviorWithNonWorkflowHost(typeof(ControlOperationBehavior).Name)));
}
ServiceEndpoint endpoint = null;
foreach (ServiceEndpoint endpointToMatch in serviceHost.Description.Endpoints)
{
if (endpointToMatch.Id == dispatchOperation.Parent.EndpointDispatcher.Id)
{
endpoint = endpointToMatch;
break;
}
}
if (this.isWrappedMode)
{
CorrelationKeyCalculator keyCalculator = null;
if (endpoint != null)
{
CorrelationQueryBehavior endpointQueryBehavior = endpoint.Behaviors.Find<CorrelationQueryBehavior>();
if (endpointQueryBehavior != null)
{
keyCalculator = endpointQueryBehavior.GetKeyCalculator();
}
}
//This will be the case for infrastructure endpoints like Compensation/Interop OCS endpoints.
dispatchOperation.Invoker = new ControlOperationInvoker(
operationDescription,
endpoint,
keyCalculator,
dispatchOperation.Invoker,
serviceHost);
}
else
{
//This will be for IWorkflowInstanceManagement endpoint operation.
dispatchOperation.Invoker = new ControlOperationInvoker(
operationDescription,
endpoint,
null,
serviceHost);
}
}
public void Validate(OperationDescription operationDescription)
{
}
}
}
|