| | | 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 CoreWCF.Channels; |
| | | 6 | | using CoreWCF.Diagnostics; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Dispatcher |
| | | 9 | | { |
| | | 10 | | internal sealed class MessageOperationFormatter : IClientMessageFormatter, IDispatchMessageFormatter |
| | | 11 | | { |
| | | 12 | | private static MessageOperationFormatter s_instance; |
| | | 13 | | |
| | | 14 | | internal static MessageOperationFormatter Instance |
| | | 15 | | { |
| | | 16 | | get |
| | | 17 | | { |
| | 664 | 18 | | if (s_instance == null) |
| | | 19 | | { |
| | 14 | 20 | | s_instance = new MessageOperationFormatter(); |
| | | 21 | | } |
| | | 22 | | |
| | 664 | 23 | | return s_instance; |
| | | 24 | | } |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | public object DeserializeReply(Message message, object[] parameters) |
| | | 28 | | { |
| | 0 | 29 | | if (message == null) |
| | | 30 | | { |
| | 0 | 31 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message)); |
| | | 32 | | } |
| | | 33 | | |
| | 0 | 34 | | if (parameters != null && parameters.Length > 0) |
| | | 35 | | { |
| | 0 | 36 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.SFxParametersMustBeEmpty); |
| | | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | return message; |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | public void DeserializeRequest(Message message, object[] parameters) |
| | | 43 | | { |
| | 10 | 44 | | if (message == null) |
| | | 45 | | { |
| | 0 | 46 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message)); |
| | | 47 | | } |
| | | 48 | | |
| | 10 | 49 | | if (parameters == null) |
| | | 50 | | { |
| | 0 | 51 | | throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(parameters)), message); |
| | | 52 | | } |
| | | 53 | | |
| | 10 | 54 | | if (parameters.Length != 1) |
| | | 55 | | { |
| | 0 | 56 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.SFxParameterMustBeArrayOfOneElement); |
| | | 57 | | } |
| | | 58 | | |
| | 10 | 59 | | parameters[0] = message; |
| | 10 | 60 | | } |
| | | 61 | | |
| | | 62 | | public bool IsFault(string operation, Exception error) |
| | | 63 | | { |
| | 0 | 64 | | return false; |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | public MessageFault SerializeFault(Exception error) |
| | | 68 | | { |
| | 0 | 69 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxMessageOperati |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result) |
| | | 73 | | { |
| | 10 | 74 | | if (!(result is Message)) |
| | | 75 | | { |
| | 0 | 76 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.SFxResultMustBeMessage); |
| | | 77 | | } |
| | | 78 | | |
| | 10 | 79 | | if (parameters != null && parameters.Length > 0) |
| | | 80 | | { |
| | 0 | 81 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.SFxParametersMustBeEmpty); |
| | | 82 | | } |
| | | 83 | | |
| | 10 | 84 | | return (Message)result; |
| | | 85 | | } |
| | | 86 | | |
| | | 87 | | public Message SerializeRequest(MessageVersion messageVersion, object[] parameters) |
| | | 88 | | { |
| | 0 | 89 | | if (parameters == null) |
| | | 90 | | { |
| | 0 | 91 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(parameters)); |
| | | 92 | | } |
| | | 93 | | |
| | 0 | 94 | | if (parameters.Length != 1 || !(parameters[0] is Message)) |
| | | 95 | | { |
| | 0 | 96 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.SFxParameterMustBeMessage); |
| | | 97 | | } |
| | | 98 | | |
| | 0 | 99 | | return (Message)parameters[0]; |
| | | 100 | | } |
| | | 101 | | } |
| | | 102 | | } |