| | | 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; |
| | | 5 | | using System.Reflection; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Description |
| | | 8 | | { |
| | | 9 | | internal static class TaskOperationDescriptionValidator |
| | | 10 | | { |
| | | 11 | | internal static void Validate(OperationDescription operationDescription, bool isForService) |
| | | 12 | | { |
| | 2645 | 13 | | MethodInfo taskMethod = operationDescription.TaskMethod; |
| | 2645 | 14 | | if (taskMethod != null) |
| | | 15 | | { |
| | 329 | 16 | | if (isForService) |
| | | 17 | | { |
| | | 18 | | // no other method (sync, async) is allowed to co-exist with a task-based method on the server-side. |
| | 329 | 19 | | EnsureNoSyncMethod(operationDescription); |
| | 329 | 20 | | EnsureNoBeginEndMethod(operationDescription); |
| | | 21 | | } |
| | | 22 | | else |
| | | 23 | | { |
| | | 24 | | // no out/ref parameter is allowed on the client-side. |
| | 0 | 25 | | EnsureNoOutputParameters(taskMethod); |
| | | 26 | | } |
| | | 27 | | |
| | 329 | 28 | | EnsureParametersAreSupported(taskMethod); |
| | | 29 | | } |
| | 2645 | 30 | | } |
| | | 31 | | |
| | | 32 | | private static void EnsureNoSyncMethod(OperationDescription operation) |
| | | 33 | | { |
| | 329 | 34 | | if (operation.SyncMethod != null) |
| | | 35 | | { |
| | 0 | 36 | | string method1Name = operation.TaskMethod.Name; |
| | 0 | 37 | | string method2Name = operation.SyncMethod.Name; |
| | 0 | 38 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Can |
| | | 39 | | } |
| | 329 | 40 | | } |
| | | 41 | | |
| | | 42 | | private static void EnsureNoBeginEndMethod(OperationDescription operation) |
| | | 43 | | { |
| | 329 | 44 | | if (operation.BeginMethod != null) |
| | | 45 | | { |
| | 0 | 46 | | string method1Name = operation.TaskMethod.Name; |
| | 0 | 47 | | string method2Name = operation.BeginMethod.Name; |
| | 0 | 48 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Can |
| | | 49 | | } |
| | 329 | 50 | | } |
| | | 51 | | |
| | | 52 | | private static void EnsureParametersAreSupported(MethodInfo method) |
| | | 53 | | { |
| | 1220 | 54 | | foreach (ParameterInfo parameter in method.GetParameters()) |
| | | 55 | | { |
| | 281 | 56 | | Type parameterType = parameter.ParameterType; |
| | 281 | 57 | | if ((parameterType == ServiceReflector.CancellationTokenType) || |
| | 281 | 58 | | (parameterType.GetTypeInfo().IsGenericType && parameterType.GetGenericTypeDefinition() == ServiceRef |
| | | 59 | | { |
| | 0 | 60 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.Tas |
| | | 61 | | } |
| | | 62 | | } |
| | 329 | 63 | | } |
| | | 64 | | |
| | | 65 | | private static void EnsureNoOutputParameters(MethodInfo method) |
| | | 66 | | { |
| | 0 | 67 | | if (ServiceReflector.HasOutputParameters(method, false)) |
| | | 68 | | { |
| | 0 | 69 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.TaskMethodMus |
| | | 70 | | } |
| | 0 | 71 | | } |
| | | 72 | | } |
| | | 73 | | } |