Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.ServiceModel / System / ServiceModel / Dispatcher / OperationInvokerBehavior.cs
blob2bcb3ceaede7f0d18de8633ace19ff4b755fb449
1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //-----------------------------------------------------------------------------
5 namespace System.ServiceModel.Dispatcher
7 using System.Collections.Generic;
8 using System.ServiceModel.Channels;
9 using System.ServiceModel.Description;
11 class OperationInvokerBehavior : IOperationBehavior
13 public OperationInvokerBehavior()
17 void IOperationBehavior.Validate(OperationDescription description)
21 void IOperationBehavior.AddBindingParameters(OperationDescription description, BindingParameterCollection parameters)
25 void IOperationBehavior.ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch)
27 if (dispatch == null)
29 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dispatch");
31 if (description == null)
33 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
36 if (description.TaskMethod != null)
38 dispatch.Invoker = new TaskMethodInvoker(description.TaskMethod, description.TaskTResult);
40 else if (description.SyncMethod != null)
42 if (description.BeginMethod != null)
44 // both sync and async methods are present on the contract, check the preference
45 OperationBehaviorAttribute operationBehaviorAttribue = description.Behaviors.Find<OperationBehaviorAttribute>();
46 if ((operationBehaviorAttribue != null) && operationBehaviorAttribue.PreferAsyncInvocation)
48 dispatch.Invoker = new AsyncMethodInvoker(description.BeginMethod, description.EndMethod);
50 else
52 dispatch.Invoker = new SyncMethodInvoker(description.SyncMethod);
55 else
57 // only sync method is present on the contract
58 dispatch.Invoker = new SyncMethodInvoker(description.SyncMethod);
61 else
63 if (description.BeginMethod != null)
65 // only async method is present on the contract
66 dispatch.Invoker = new AsyncMethodInvoker(description.BeginMethod, description.EndMethod);
71 void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)