| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.Reflection; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | using CoreWCF.Description; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Dispatcher |
| | | 10 | | { |
| | | 11 | | internal class OperationSelectorBehavior : IContractBehavior |
| | | 12 | | { |
| | | 13 | | void IContractBehavior.Validate(ContractDescription description, ServiceEndpoint endpoint) |
| | | 14 | | { |
| | 641 | 15 | | } |
| | | 16 | | |
| | | 17 | | void IContractBehavior.AddBindingParameters(ContractDescription description, ServiceEndpoint endpoint, BindingPa |
| | | 18 | | { |
| | 673 | 19 | | } |
| | | 20 | | |
| | | 21 | | void IContractBehavior.ApplyDispatchBehavior(ContractDescription description, ServiceEndpoint endpoint, Dispatch |
| | | 22 | | { |
| | 641 | 23 | | if (dispatch.ClientRuntime != null) |
| | | 24 | | { |
| | 2 | 25 | | dispatch.ClientRuntime.OperationSelector = new MethodInfoOperationSelector(description, MessageDirection |
| | | 26 | | } |
| | 641 | 27 | | } |
| | | 28 | | |
| | | 29 | | void IContractBehavior.ApplyClientBehavior(ContractDescription description, ServiceEndpoint endpoint, ClientRunt |
| | | 30 | | { |
| | 0 | 31 | | proxy.OperationSelector = new MethodInfoOperationSelector(description, MessageDirection.Input); |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | internal class MethodInfoOperationSelector : IClientOperationSelector |
| | | 35 | | { |
| | | 36 | | private readonly Dictionary<object, string> _operationMap; |
| | | 37 | | |
| | 2 | 38 | | internal MethodInfoOperationSelector(ContractDescription description, MessageDirection directionThatRequires |
| | | 39 | | { |
| | 2 | 40 | | _operationMap = new Dictionary<object, string>(); |
| | | 41 | | |
| | 16 | 42 | | for (int i = 0; i < description.Operations.Count; i++) |
| | | 43 | | { |
| | 6 | 44 | | OperationDescription operation = description.Operations[i]; |
| | 6 | 45 | | if (operation.Messages[0].Direction == directionThatRequiresClientOpSelection) |
| | | 46 | | { |
| | 2 | 47 | | if (operation.SyncMethod != null) |
| | | 48 | | { |
| | 2 | 49 | | if (!_operationMap.ContainsKey(operation.SyncMethod)) |
| | | 50 | | { |
| | 2 | 51 | | _operationMap.Add(operation.SyncMethod, operation.Name); |
| | | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | 2 | 55 | | if (operation.BeginMethod != null) |
| | | 56 | | { |
| | 0 | 57 | | if (!_operationMap.ContainsKey(operation.BeginMethod)) |
| | | 58 | | { |
| | 0 | 59 | | _operationMap.Add(operation.BeginMethod, operation.Name); |
| | 0 | 60 | | _operationMap.Add(operation.EndMethod, operation.Name); |
| | | 61 | | } |
| | | 62 | | } |
| | | 63 | | |
| | 2 | 64 | | if (operation.TaskMethod != null) |
| | | 65 | | { |
| | 0 | 66 | | if (!_operationMap.ContainsKey(operation.TaskMethod)) |
| | | 67 | | { |
| | 0 | 68 | | _operationMap.Add(operation.TaskMethod, operation.Name); |
| | | 69 | | } |
| | | 70 | | } |
| | | 71 | | } |
| | | 72 | | } |
| | 2 | 73 | | } |
| | | 74 | | |
| | | 75 | | public bool AreParametersRequiredForSelection |
| | | 76 | | { |
| | 1 | 77 | | get { return false; } |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | public string SelectOperation(MethodBase method, object[] parameters) |
| | | 81 | | { |
| | 1 | 82 | | if (_operationMap.ContainsKey(method)) |
| | | 83 | | { |
| | 1 | 84 | | return _operationMap[method]; |
| | | 85 | | } |
| | | 86 | | else |
| | | 87 | | { |
| | 0 | 88 | | return null; |
| | | 89 | | } |
| | | 90 | | } |
| | | 91 | | } |
| | | 92 | | } |
| | | 93 | | } |