| | | 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 | | |
| | | 6 | | namespace CoreWCF.Channels.Framing |
| | | 7 | | { |
| | | 8 | | /* |
| | | 9 | | Message Framing BNF: |
| | | 10 | | |
| | | 11 | | protocol-stream-a = (singleton-unsized-stream-a | duplex-stream-a | simplex-stream-a | singleton-sized-stream-a) |
| | | 12 | | protocol-stream-b = (singleton-unsized-stream-b | duplex-stream-b)+ |
| | | 13 | | |
| | | 14 | | singleton-unsized-stream-a = version-record mode-record-type singleton-unsized-mode via-record encoding-record u |
| | | 15 | | duplex-stream-a = version-record mode-record-type duplex-mode via-record encoding-record upgrade-request* preamb |
| | | 16 | | simplex-stream-a = version-record mode-record-type simplex-mode via-record encoding-record simplex-message* end- |
| | | 17 | | singleton-sized-stream-a = version-record mode-record-type singleton-sized-mode via-record encoding-record octet |
| | | 18 | | |
| | | 19 | | singleton-unsized-stream-b = upgrade-response* preamble-response singleton-message? end-record-type |
| | | 20 | | duplex-stream-b = upgrade-response* preamble-response duplex-message* (fault-message | end-record-type) |
| | | 21 | | |
| | | 22 | | singleton-message = unsized-message |
| | | 23 | | duplex-message = sized-message |
| | | 24 | | simplex-message = sized-message |
| | | 25 | | fault-message = fault-record-type mbint utf8-octets |
| | | 26 | | sized-message = sized-envelope-record-type mbint octets |
| | | 27 | | unsized-message = unsized-envelope-record-type (mbint octets)* octet(0x0) |
| | | 28 | | |
| | | 29 | | preamble-response = preamble-ack-record-type | fault-message |
| | | 30 | | |
| | | 31 | | upgrade-request = upgrade-request-record-type mbint utf8-octets octets |
| | | 32 | | upgrade-response = upgrade-response-record-type octets |
| | | 33 | | |
| | | 34 | | version-record = version-record-type major-version-number minor-version-number |
| | | 35 | | major-version-number = octet(0x1) |
| | | 36 | | minor-version-number = octet(0x0) |
| | | 37 | | |
| | | 38 | | encoding-record = known-encoding-record | extensible-encoding-record |
| | | 39 | | known-encoding-record = known-encoding-record-type known-encoding-type |
| | | 40 | | extensible-encoding-record = extensible-encoding-record-type mbint utf8-octets |
| | | 41 | | |
| | | 42 | | via-record = via-record-type mbint utf8-octets |
| | | 43 | | |
| | | 44 | | singleton-unsized-mode = octet(0x1) |
| | | 45 | | duplex-mode = octet(0x2) |
| | | 46 | | simplex-mode = octet(0x3) |
| | | 47 | | singleton-sized-mode = octet(0x4) |
| | | 48 | | |
| | | 49 | | known-encoding-type = text-encoding | binary-encoding | mtom-encoding |
| | | 50 | | binary-encoding = binary-sessionless-encoding | binary-session-encoding |
| | | 51 | | text-encoding = soap11-text-encoding | soap12-text-encoding |
| | | 52 | | soap11-text-encoding = soap11-utf8-encoding | soap11-utf16-encoding | soap11-unicodeFFFE-encoding |
| | | 53 | | soap12-text-encoding = soap12-utf8-encoding | soap12-utf16-encoding | soap12-unicodeFFFE-encoding |
| | | 54 | | |
| | | 55 | | soap11-utf8-encoding = octet(0x0) |
| | | 56 | | soap11-utf16-encoding = octet(0x1) |
| | | 57 | | soap11-unicodeFFFE-encoding = octet(0x2) |
| | | 58 | | soap12-utf8-encoding = octet(0x3) |
| | | 59 | | soap12-utf16-encoding = octet(0x4) |
| | | 60 | | soap12-unicodeFFFE-encoding = octet(0x5) |
| | | 61 | | mtom-encoding = octet(0x6) |
| | | 62 | | binary-sessionless-encoding = octet(0x7) |
| | | 63 | | binary-session-encoding = octet(0x8) |
| | | 64 | | |
| | | 65 | | version-record-type = octet(0x0) |
| | | 66 | | mode-record-type = octet(0x1) |
| | | 67 | | via-record-type = octet(0x2) |
| | | 68 | | known-encoding-record-type = octet(0x3) |
| | | 69 | | extensible-encoding-record-type = octet(0x4) |
| | | 70 | | unsized-envelope-record-type = octet(0x5) |
| | | 71 | | sized-envelope-record-type = octet(0x6) |
| | | 72 | | end-record-type = octet(0x7) |
| | | 73 | | fault-record-type = octet(0x8) |
| | | 74 | | upgrade-request-record-type = octet(0x9) |
| | | 75 | | upgrade-response-record-type = octet(0xA) |
| | | 76 | | preamble-ack-record-type = octet (0xB) |
| | | 77 | | preamble-end-record-type = octet (0xC) |
| | | 78 | | */ |
| | | 79 | | |
| | | 80 | | internal enum FramingRecordType |
| | | 81 | | { |
| | | 82 | | Version = 0x0, |
| | | 83 | | Mode = 0x1, |
| | | 84 | | Via = 0x2, |
| | | 85 | | KnownEncoding = 0x3, |
| | | 86 | | ExtensibleEncoding = 0x4, |
| | | 87 | | UnsizedEnvelope = 0x5, |
| | | 88 | | SizedEnvelope = 0x6, |
| | | 89 | | End = 0x7, |
| | | 90 | | Fault = 0x8, |
| | | 91 | | UpgradeRequest = 0x9, |
| | | 92 | | UpgradeResponse = 0xA, |
| | | 93 | | PreambleAck = 0xB, |
| | | 94 | | PreambleEnd = 0xC, |
| | | 95 | | } |
| | | 96 | | |
| | | 97 | | internal enum FramingMode |
| | | 98 | | { |
| | | 99 | | Singleton = 0x1, |
| | | 100 | | Duplex = 0x2, |
| | | 101 | | Simplex = 0x3, |
| | | 102 | | SingletonSized = 0x4, |
| | | 103 | | } |
| | | 104 | | |
| | | 105 | | internal static class FramingUpgradeString |
| | | 106 | | { |
| | | 107 | | public const string SslOrTls = "application/ssl-tls"; |
| | | 108 | | public const string Negotiate = "application/negotiate"; |
| | | 109 | | } |
| | | 110 | | |
| | | 111 | | internal enum FramingEncodingType |
| | | 112 | | { |
| | | 113 | | Soap11Utf8 = 0x0, |
| | | 114 | | Soap11Utf16 = 0x1, |
| | | 115 | | Soap11Utf16FFFE = 0x2, |
| | | 116 | | Soap12Utf8 = 0x3, |
| | | 117 | | Soap12Utf16 = 0x4, |
| | | 118 | | Soap12Utf16FFFE = 0x5, |
| | | 119 | | MTOM = 0x6, |
| | | 120 | | Binary = 0x7, |
| | | 121 | | BinarySession = 0x8, |
| | | 122 | | ExtendedBinaryGZip = 0x9, |
| | | 123 | | ExtendedBinarySessionGZip = 0xA, |
| | | 124 | | ExtendedBinaryDeflate = 0xB, |
| | | 125 | | ExtendedBinarySessionDeflate = 0xC |
| | | 126 | | } |
| | | 127 | | |
| | | 128 | | internal static class FramingEncodingString |
| | | 129 | | { |
| | | 130 | | public const string Soap11Utf8 = "text/xml; charset=utf-8"; |
| | | 131 | | public const string Soap11Utf16 = "text/xml; charset=utf16"; |
| | | 132 | | public const string Soap11Utf16FFFE = "text/xml; charset=unicodeFFFE"; |
| | | 133 | | public const string Soap12Utf8 = "application/soap+xml; charset=utf-8"; |
| | | 134 | | public const string Soap12Utf16 = "application/soap+xml; charset=utf16"; |
| | | 135 | | public const string Soap12Utf16FFFE = "application/soap+xml; charset=unicodeFFFE"; |
| | | 136 | | public const string MTOM = "multipart/related"; |
| | | 137 | | public const string Binary = "application/soap+msbin1"; |
| | | 138 | | public const string BinarySession = "application/soap+msbinsession1"; |
| | | 139 | | public const string ExtendedBinaryGZip = Binary + "+gzip"; |
| | | 140 | | public const string ExtendedBinarySessionGZip = BinarySession + "+gzip"; |
| | | 141 | | public const string ExtendedBinaryDeflate = Binary + "+deflate"; |
| | | 142 | | public const string ExtendedBinarySessionDeflate = BinarySession + "+deflate"; |
| | | 143 | | public const string NamespaceUri = "http://schemas.microsoft.com/ws/2006/05/framing"; |
| | | 144 | | private const string FaultBaseUri = NamespaceUri + "/faults/"; |
| | | 145 | | public const string ContentTypeInvalidFault = FaultBaseUri + "ContentTypeInvalid"; |
| | | 146 | | public const string ContentTypeTooLongFault = FaultBaseUri + "ContentTypeTooLong"; |
| | | 147 | | public const string ConnectionDispatchFailedFault = FaultBaseUri + "ConnectionDispatchFailed"; |
| | | 148 | | public const string EndpointNotFoundFault = FaultBaseUri + "EndpointNotFound"; |
| | | 149 | | public const string EndpointUnavailableFault = FaultBaseUri + "EndpointUnavailable"; |
| | | 150 | | public const string MaxMessageSizeExceededFault = FaultBaseUri + "MaxMessageSizeExceededFault"; |
| | | 151 | | public const string ServerTooBusyFault = FaultBaseUri + "ServerTooBusy"; |
| | | 152 | | public const string ServiceActivationFailedFault = FaultBaseUri + "ServiceActivationFailed"; |
| | | 153 | | public const string UnsupportedModeFault = FaultBaseUri + "UnsupportedMode"; |
| | | 154 | | public const string UnsupportedVersionFault = FaultBaseUri + "UnsupportedVersion"; |
| | | 155 | | public const string UpgradeInvalidFault = FaultBaseUri + "UpgradeInvalid"; |
| | | 156 | | public const string ViaTooLongFault = FaultBaseUri + "ViaTooLong"; |
| | | 157 | | private const string ExceptionKey = "FramingEncodingString"; |
| | | 158 | | public static bool TryGetFaultString(Exception exception, out string framingFault) |
| | | 159 | | { |
| | 0 | 160 | | framingFault = null; |
| | 0 | 161 | | if (exception.Data.Contains(ExceptionKey)) |
| | | 162 | | { |
| | 0 | 163 | | framingFault = exception.Data[ExceptionKey] as string; |
| | 0 | 164 | | if (framingFault != null) |
| | | 165 | | { |
| | 0 | 166 | | return true; |
| | | 167 | | } |
| | | 168 | | } |
| | | 169 | | |
| | 0 | 170 | | return false; |
| | | 171 | | } |
| | | 172 | | |
| | | 173 | | public static void AddFaultString(Exception exception, string framingFault) |
| | | 174 | | { |
| | 0 | 175 | | exception.Data[ExceptionKey] = framingFault; |
| | 0 | 176 | | } |
| | | 177 | | } |
| | | 178 | | |
| | | 179 | | internal static class FramingVersion |
| | | 180 | | { |
| | | 181 | | public const int Major = 0x1; |
| | | 182 | | public const int Minor = 0x0; |
| | | 183 | | } |
| | | 184 | | } |