| | | 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.Globalization; |
| | | 6 | | using CoreWCF.Runtime; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | public sealed class MessageVersion |
| | | 11 | | { |
| | 84 | 12 | | private MessageVersion(EnvelopeVersion envelopeVersion, AddressingVersion addressingVersion) |
| | | 13 | | { |
| | 84 | 14 | | Envelope = envelopeVersion; |
| | 84 | 15 | | Addressing = addressingVersion; |
| | 84 | 16 | | } |
| | | 17 | | |
| | 229115 | 18 | | public AddressingVersion Addressing { get; } |
| | 225753 | 19 | | public EnvelopeVersion Envelope { get; } |
| | | 20 | | |
| | 1412 | 21 | | public static MessageVersion Default => Soap12WSAddressing10; |
| | 2302 | 22 | | public static MessageVersion None { get; } = new MessageVersion(EnvelopeVersion.None, AddressingVersion.None); |
| | 743 | 23 | | public static MessageVersion Soap11 { get; } = new MessageVersion(EnvelopeVersion.Soap11, AddressingVersion.None |
| | 17 | 24 | | public static MessageVersion Soap12 { get; } = new MessageVersion(EnvelopeVersion.Soap12, AddressingVersion.None |
| | 15 | 25 | | public static MessageVersion Soap11WSAddressing10 { get; } = new MessageVersion(EnvelopeVersion.Soap11, Addressi |
| | 2371 | 26 | | public static MessageVersion Soap12WSAddressing10 { get; } = new MessageVersion(EnvelopeVersion.Soap12, Addressi |
| | 14 | 27 | | public static MessageVersion Soap11WSAddressingAugust2004 { get; } = new MessageVersion(EnvelopeVersion.Soap11, |
| | 53 | 28 | | public static MessageVersion Soap12WSAddressingAugust2004 { get; } = new MessageVersion(EnvelopeVersion.Soap12, |
| | | 29 | | |
| | | 30 | | public static MessageVersion CreateVersion(EnvelopeVersion envelopeVersion) |
| | | 31 | | { |
| | 440 | 32 | | return CreateVersion(envelopeVersion, AddressingVersion.WSAddressing10); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public static MessageVersion CreateVersion(EnvelopeVersion envelopeVersion, AddressingVersion addressingVersion) |
| | | 36 | | { |
| | 577 | 37 | | if (envelopeVersion == null) |
| | | 38 | | { |
| | 0 | 39 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(envelopeVersion)); |
| | | 40 | | } |
| | | 41 | | |
| | 577 | 42 | | if (addressingVersion == null) |
| | | 43 | | { |
| | 0 | 44 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion)); |
| | | 45 | | } |
| | | 46 | | |
| | 577 | 47 | | if (envelopeVersion == EnvelopeVersion.Soap12) |
| | | 48 | | { |
| | 576 | 49 | | if (addressingVersion == AddressingVersion.WSAddressing10) |
| | | 50 | | { |
| | 563 | 51 | | return Soap12WSAddressing10; |
| | | 52 | | } |
| | 13 | 53 | | else if (addressingVersion == AddressingVersion.WSAddressingAugust2004) |
| | | 54 | | { |
| | 13 | 55 | | return Soap12WSAddressingAugust2004; |
| | | 56 | | } |
| | 0 | 57 | | else if (addressingVersion == AddressingVersion.None) |
| | | 58 | | { |
| | 0 | 59 | | return Soap12; |
| | | 60 | | } |
| | | 61 | | else |
| | | 62 | | { |
| | 0 | 63 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(addressingVersion), |
| | 0 | 64 | | SR.Format(SR.AddressingVersionNotSupported, addressingVersion)); |
| | | 65 | | } |
| | | 66 | | } |
| | 1 | 67 | | else if (envelopeVersion == EnvelopeVersion.Soap11) |
| | | 68 | | { |
| | 1 | 69 | | if (addressingVersion == AddressingVersion.WSAddressing10) |
| | | 70 | | { |
| | 0 | 71 | | return Soap11WSAddressing10; |
| | | 72 | | } |
| | 1 | 73 | | else if (addressingVersion == AddressingVersion.WSAddressingAugust2004) |
| | | 74 | | { |
| | 0 | 75 | | return Soap11WSAddressingAugust2004; |
| | | 76 | | } |
| | 1 | 77 | | else if (addressingVersion == AddressingVersion.None) |
| | | 78 | | { |
| | 1 | 79 | | return Soap11; |
| | | 80 | | } |
| | | 81 | | else |
| | | 82 | | { |
| | 0 | 83 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(addressingVersion), |
| | 0 | 84 | | SR.Format(SR.AddressingVersionNotSupported, addressingVersion)); |
| | | 85 | | } |
| | | 86 | | } |
| | 0 | 87 | | else if (envelopeVersion == EnvelopeVersion.None) |
| | | 88 | | { |
| | 0 | 89 | | if (addressingVersion == AddressingVersion.None) |
| | | 90 | | { |
| | 0 | 91 | | return None; |
| | | 92 | | } |
| | | 93 | | else |
| | | 94 | | { |
| | 0 | 95 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(addressingVersion), |
| | 0 | 96 | | SR.Format(SR.AddressingVersionNotSupported, addressingVersion)); |
| | | 97 | | } |
| | | 98 | | } |
| | | 99 | | else |
| | | 100 | | { |
| | 0 | 101 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(envelopeVersion), |
| | 0 | 102 | | SR.Format(SR.EnvelopeVersionNotSupported, envelopeVersion)); |
| | | 103 | | } |
| | | 104 | | } |
| | | 105 | | |
| | | 106 | | public override bool Equals(object obj) |
| | | 107 | | { |
| | 0 | 108 | | return this == obj; |
| | | 109 | | } |
| | | 110 | | |
| | | 111 | | public override int GetHashCode() |
| | | 112 | | { |
| | 0 | 113 | | int code = 0; |
| | 0 | 114 | | if (Envelope == EnvelopeVersion.Soap11) |
| | | 115 | | { |
| | 0 | 116 | | code += 1; |
| | | 117 | | } |
| | | 118 | | |
| | 0 | 119 | | return code; |
| | | 120 | | } |
| | | 121 | | |
| | | 122 | | public override string ToString() |
| | | 123 | | { |
| | 34 | 124 | | return SR.Format(SR.MessageVersionToStringFormat, Envelope.ToString(), Addressing.ToString()); |
| | | 125 | | } |
| | | 126 | | |
| | | 127 | | internal bool IsMatch(MessageVersion messageVersion) |
| | | 128 | | { |
| | 1 | 129 | | if (messageVersion == null) |
| | | 130 | | { |
| | | 131 | | Fx.Assert("Invalid (null) messageVersion value"); |
| | 0 | 132 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(messageVersion)); |
| | | 133 | | } |
| | 1 | 134 | | if (Addressing == null) |
| | | 135 | | { |
| | | 136 | | Fx.Assert("Invalid (null) addressing value"); |
| | 0 | 137 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(Cu |
| | | 138 | | } |
| | | 139 | | |
| | 1 | 140 | | if (Envelope != messageVersion.Envelope) |
| | | 141 | | { |
| | 0 | 142 | | return false; |
| | | 143 | | } |
| | | 144 | | |
| | 1 | 145 | | if (Addressing.Namespace != messageVersion.Addressing.Namespace) |
| | | 146 | | { |
| | 0 | 147 | | return false; |
| | | 148 | | } |
| | | 149 | | |
| | 1 | 150 | | return true; |
| | | 151 | | } |
| | | 152 | | } |
| | | 153 | | } |