| | | 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 | | using System.Runtime.Serialization; |
| | | 7 | | using System.Xml; |
| | | 8 | | using CoreWCF.Channels; |
| | | 9 | | using CoreWCF.Description; |
| | | 10 | | using CoreWCF.Diagnostics; |
| | | 11 | | using CoreWCF.Runtime; |
| | | 12 | | |
| | | 13 | | namespace CoreWCF.Dispatcher |
| | | 14 | | { |
| | | 15 | | internal class PrimitiveOperationFormatter : IClientMessageFormatter, IDispatchMessageFormatter |
| | | 16 | | { |
| | | 17 | | internal const string NsXsi = "http://www.w3.org/2001/XMLSchema-instance"; |
| | | 18 | | private readonly OperationDescription _operation; |
| | | 19 | | private readonly MessageDescription _responseMessage; |
| | | 20 | | private readonly MessageDescription _requestMessage; |
| | | 21 | | private readonly XmlDictionaryString _action; |
| | | 22 | | private readonly XmlDictionaryString _replyAction; |
| | | 23 | | private ActionHeader _actionHeaderNone; |
| | | 24 | | private ActionHeader _actionHeader10; |
| | | 25 | | private ActionHeader _replyActionHeaderNone; |
| | | 26 | | private ActionHeader _replyActionHeader10; |
| | | 27 | | private ActionHeader _replyActionHeaderAugust2004; |
| | | 28 | | private readonly XmlDictionaryString _requestWrapperName; |
| | | 29 | | private readonly XmlDictionaryString _requestWrapperNamespace; |
| | | 30 | | private readonly XmlDictionaryString _responseWrapperName; |
| | | 31 | | private readonly XmlDictionaryString _responseWrapperNamespace; |
| | | 32 | | private readonly PartInfo[] _requestParts; |
| | | 33 | | private readonly PartInfo[] _responseParts; |
| | | 34 | | private readonly PartInfo _returnPart; |
| | | 35 | | private readonly XmlDictionaryString _xsiNilLocalName; |
| | | 36 | | private readonly XmlDictionaryString _xsiNilNamespace; |
| | | 37 | | |
| | 1972 | 38 | | public PrimitiveOperationFormatter(OperationDescription description, bool isRpc) |
| | | 39 | | { |
| | 1972 | 40 | | if (description == null) |
| | | 41 | | { |
| | 0 | 42 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(description)); |
| | | 43 | | } |
| | | 44 | | |
| | 1972 | 45 | | OperationFormatter.Validate(description, isRpc, false/*isEncoded*/); |
| | | 46 | | |
| | 1972 | 47 | | _operation = description; |
| | 1972 | 48 | | _requestMessage = description.Messages[0]; |
| | 1972 | 49 | | if (description.Messages.Count == 2) |
| | | 50 | | { |
| | 1662 | 51 | | _responseMessage = description.Messages[1]; |
| | | 52 | | } |
| | | 53 | | |
| | 1972 | 54 | | int stringCount = 3 + _requestMessage.Body.Parts.Count; |
| | 1972 | 55 | | if (_responseMessage != null) |
| | | 56 | | { |
| | 1662 | 57 | | stringCount += 2 + _responseMessage.Body.Parts.Count; |
| | | 58 | | } |
| | | 59 | | |
| | 1972 | 60 | | XmlDictionary dictionary = new XmlDictionary(stringCount * 2); |
| | | 61 | | |
| | 1972 | 62 | | _xsiNilLocalName = dictionary.Add("nil"); |
| | 1972 | 63 | | _xsiNilNamespace = dictionary.Add(NsXsi); |
| | | 64 | | |
| | 1972 | 65 | | OperationFormatter.GetActions(description, dictionary, out _action, out _replyAction); |
| | | 66 | | |
| | 1972 | 67 | | if (_requestMessage.Body.WrapperName != null) |
| | | 68 | | { |
| | 1972 | 69 | | _requestWrapperName = AddToDictionary(dictionary, _requestMessage.Body.WrapperName); |
| | 1972 | 70 | | _requestWrapperNamespace = AddToDictionary(dictionary, _requestMessage.Body.WrapperNamespace); |
| | | 71 | | } |
| | | 72 | | |
| | 1972 | 73 | | _requestParts = AddToDictionary(dictionary, _requestMessage.Body.Parts, isRpc); |
| | | 74 | | |
| | 1972 | 75 | | if (_responseMessage != null) |
| | | 76 | | { |
| | 1662 | 77 | | if (_responseMessage.Body.WrapperName != null) |
| | | 78 | | { |
| | 1662 | 79 | | _responseWrapperName = AddToDictionary(dictionary, _responseMessage.Body.WrapperName); |
| | 1662 | 80 | | _responseWrapperNamespace = AddToDictionary(dictionary, _responseMessage.Body.WrapperNamespace); |
| | | 81 | | } |
| | | 82 | | |
| | 1662 | 83 | | _responseParts = AddToDictionary(dictionary, _responseMessage.Body.Parts, isRpc); |
| | | 84 | | |
| | 1662 | 85 | | if (_responseMessage.Body.ReturnValue != null && _responseMessage.Body.ReturnValue.Type != typeof(void)) |
| | | 86 | | { |
| | 1513 | 87 | | _returnPart = AddToDictionary(dictionary, _responseMessage.Body.ReturnValue, isRpc); |
| | | 88 | | } |
| | | 89 | | } |
| | 1972 | 90 | | } |
| | | 91 | | |
| | | 92 | | private ActionHeader ActionHeaderNone |
| | | 93 | | { |
| | | 94 | | get |
| | | 95 | | { |
| | 0 | 96 | | if (_actionHeaderNone == null) |
| | | 97 | | { |
| | 0 | 98 | | _actionHeaderNone = |
| | 0 | 99 | | ActionHeader.Create(_action, AddressingVersion.None); |
| | | 100 | | } |
| | | 101 | | |
| | 0 | 102 | | return _actionHeaderNone; |
| | | 103 | | } |
| | | 104 | | } |
| | | 105 | | |
| | | 106 | | private ActionHeader ActionHeader10 |
| | | 107 | | { |
| | | 108 | | get |
| | | 109 | | { |
| | 1 | 110 | | if (_actionHeader10 == null) |
| | | 111 | | { |
| | 1 | 112 | | _actionHeader10 = |
| | 1 | 113 | | ActionHeader.Create(_action, AddressingVersion.WSAddressing10); |
| | | 114 | | } |
| | | 115 | | |
| | 1 | 116 | | return _actionHeader10; |
| | | 117 | | } |
| | | 118 | | } |
| | | 119 | | |
| | | 120 | | //ActionHeader ActionHeaderAugust2004 |
| | | 121 | | //{ |
| | | 122 | | // get |
| | | 123 | | // { |
| | | 124 | | // if (actionHeaderAugust2004 == null) |
| | | 125 | | // { |
| | | 126 | | // actionHeaderAugust2004 = |
| | | 127 | | // ActionHeader.Create(this.action, AddressingVersion.WSAddressingAugust2004); |
| | | 128 | | // } |
| | | 129 | | |
| | | 130 | | // return actionHeaderAugust2004; |
| | | 131 | | // } |
| | | 132 | | //} |
| | | 133 | | |
| | | 134 | | private ActionHeader ReplyActionHeaderNone |
| | | 135 | | { |
| | | 136 | | get |
| | | 137 | | { |
| | 141 | 138 | | if (_replyActionHeaderNone == null) |
| | | 139 | | { |
| | 136 | 140 | | _replyActionHeaderNone = |
| | 136 | 141 | | ActionHeader.Create(_replyAction, AddressingVersion.None); |
| | | 142 | | } |
| | | 143 | | |
| | 141 | 144 | | return _replyActionHeaderNone; |
| | | 145 | | } |
| | | 146 | | } |
| | | 147 | | |
| | | 148 | | private ActionHeader ReplyActionHeader10 |
| | | 149 | | { |
| | | 150 | | get |
| | | 151 | | { |
| | 244 | 152 | | if (_replyActionHeader10 == null) |
| | | 153 | | { |
| | 148 | 154 | | _replyActionHeader10 = |
| | 148 | 155 | | ActionHeader.Create(_replyAction, AddressingVersion.WSAddressing10); |
| | | 156 | | } |
| | | 157 | | |
| | 244 | 158 | | return _replyActionHeader10; |
| | | 159 | | } |
| | | 160 | | } |
| | | 161 | | |
| | | 162 | | ActionHeader ReplyActionHeaderAugust2004 |
| | | 163 | | { |
| | | 164 | | get |
| | | 165 | | { |
| | 15 | 166 | | if (_replyActionHeaderAugust2004 == null) |
| | | 167 | | { |
| | 15 | 168 | | _replyActionHeaderAugust2004 = |
| | 15 | 169 | | ActionHeader.Create(_replyAction, AddressingVersion.WSAddressingAugust2004); |
| | | 170 | | } |
| | | 171 | | |
| | 15 | 172 | | return _replyActionHeaderAugust2004; |
| | | 173 | | } |
| | | 174 | | } |
| | | 175 | | |
| | | 176 | | private static XmlDictionaryString AddToDictionary(XmlDictionary dictionary, string s) |
| | | 177 | | { |
| | 13248 | 178 | | if (!dictionary.TryLookup(s, out XmlDictionaryString dictionaryString)) |
| | | 179 | | { |
| | 8597 | 180 | | dictionaryString = dictionary.Add(s); |
| | | 181 | | } |
| | 13248 | 182 | | return dictionaryString; |
| | | 183 | | } |
| | | 184 | | |
| | | 185 | | private static PartInfo[] AddToDictionary(XmlDictionary dictionary, MessagePartDescriptionCollection parts, bool |
| | | 186 | | { |
| | 3634 | 187 | | PartInfo[] partInfos = new PartInfo[parts.Count]; |
| | 10218 | 188 | | for (int i = 0; i < parts.Count; i++) |
| | | 189 | | { |
| | 1475 | 190 | | partInfos[i] = AddToDictionary(dictionary, parts[i], isRpc); |
| | | 191 | | } |
| | 3634 | 192 | | return partInfos; |
| | | 193 | | } |
| | | 194 | | |
| | | 195 | | private ActionHeader GetActionHeader(AddressingVersion addressing) |
| | | 196 | | { |
| | 1 | 197 | | if (_action == null) |
| | | 198 | | { |
| | 0 | 199 | | return null; |
| | | 200 | | } |
| | | 201 | | |
| | | 202 | | //if (addressing == AddressingVersion.WSAddressingAugust2004) |
| | | 203 | | //{ |
| | | 204 | | // return ActionHeaderAugust2004; |
| | | 205 | | //} |
| | | 206 | | //else |
| | 1 | 207 | | if (addressing == AddressingVersion.WSAddressing10) |
| | | 208 | | { |
| | 1 | 209 | | return ActionHeader10; |
| | | 210 | | } |
| | 0 | 211 | | else if (addressing == AddressingVersion.None) |
| | | 212 | | { |
| | 0 | 213 | | return ActionHeaderNone; |
| | | 214 | | } |
| | | 215 | | else |
| | | 216 | | { |
| | 0 | 217 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 218 | | new InvalidOperationException(SR.Format(SR.AddressingVersionNotSupported, addressing))); |
| | | 219 | | } |
| | | 220 | | } |
| | | 221 | | |
| | | 222 | | private ActionHeader GetReplyActionHeader(AddressingVersion addressing) |
| | | 223 | | { |
| | 400 | 224 | | if (_replyAction == null) |
| | | 225 | | { |
| | 0 | 226 | | return null; |
| | | 227 | | } |
| | | 228 | | |
| | 400 | 229 | | if (addressing == AddressingVersion.WSAddressingAugust2004) |
| | | 230 | | { |
| | 15 | 231 | | return ReplyActionHeaderAugust2004; |
| | | 232 | | } |
| | 385 | 233 | | else if (addressing == AddressingVersion.WSAddressing10) |
| | | 234 | | { |
| | 244 | 235 | | return ReplyActionHeader10; |
| | | 236 | | } |
| | 141 | 237 | | else if (addressing == AddressingVersion.None) |
| | | 238 | | { |
| | 141 | 239 | | return ReplyActionHeaderNone; |
| | | 240 | | } |
| | | 241 | | else |
| | | 242 | | { |
| | 0 | 243 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 244 | | new InvalidOperationException(SR.Format(SR.AddressingVersionNotSupported, addressing))); |
| | | 245 | | } |
| | | 246 | | } |
| | | 247 | | |
| | | 248 | | private static string GetArrayItemName(Type type) |
| | | 249 | | { |
| | 2 | 250 | | switch (type.GetTypeCode()) |
| | | 251 | | { |
| | | 252 | | case TypeCode.Boolean: |
| | 0 | 253 | | return "boolean"; |
| | | 254 | | case TypeCode.DateTime: |
| | 0 | 255 | | return "dateTime"; |
| | | 256 | | case TypeCode.Decimal: |
| | 0 | 257 | | return "decimal"; |
| | | 258 | | case TypeCode.Int32: |
| | 1 | 259 | | return "int"; |
| | | 260 | | case TypeCode.Int64: |
| | 0 | 261 | | return "long"; |
| | | 262 | | case TypeCode.Single: |
| | 1 | 263 | | return "float"; |
| | | 264 | | case TypeCode.Double: |
| | 0 | 265 | | return "double"; |
| | | 266 | | default: |
| | 0 | 267 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxInvali |
| | | 268 | | } |
| | | 269 | | } |
| | | 270 | | |
| | | 271 | | private static PartInfo AddToDictionary(XmlDictionary dictionary, MessagePartDescription part, bool isRpc) |
| | | 272 | | { |
| | 2988 | 273 | | Type type = part.Type; |
| | 2988 | 274 | | XmlDictionaryString itemName = null; |
| | 2988 | 275 | | XmlDictionaryString itemNamespace = null; |
| | 2988 | 276 | | if (type.IsArray && type != typeof(byte[])) |
| | | 277 | | { |
| | | 278 | | const string ns = "http://schemas.microsoft.com/2003/10/Serialization/Arrays"; |
| | 2 | 279 | | string name = GetArrayItemName(type.GetElementType()); |
| | 2 | 280 | | itemName = AddToDictionary(dictionary, name); |
| | 2 | 281 | | itemNamespace = AddToDictionary(dictionary, ns); |
| | | 282 | | } |
| | 2988 | 283 | | return new PartInfo(part, |
| | 2988 | 284 | | AddToDictionary(dictionary, part.Name), |
| | 2988 | 285 | | AddToDictionary(dictionary, isRpc ? string.Empty : part.Namespace), |
| | 2988 | 286 | | itemName, itemNamespace); |
| | | 287 | | } |
| | | 288 | | |
| | | 289 | | public static bool IsContractSupported(OperationDescription description) |
| | | 290 | | { |
| | 2789 | 291 | | if (description == null) |
| | | 292 | | { |
| | 0 | 293 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(description)); |
| | | 294 | | } |
| | | 295 | | |
| | 2789 | 296 | | MessageDescription requestMessage = description.Messages[0]; |
| | 2789 | 297 | | MessageDescription responseMessage = null; |
| | 2789 | 298 | | if (description.Messages.Count == 2) |
| | | 299 | | { |
| | 2475 | 300 | | responseMessage = description.Messages[1]; |
| | | 301 | | } |
| | | 302 | | |
| | 2789 | 303 | | if (requestMessage.Headers.Count > 0) |
| | | 304 | | { |
| | 91 | 305 | | return false; |
| | | 306 | | } |
| | | 307 | | |
| | 2698 | 308 | | if (requestMessage.Properties.Count > 0) |
| | | 309 | | { |
| | 0 | 310 | | return false; |
| | | 311 | | } |
| | | 312 | | |
| | 2698 | 313 | | if (requestMessage.IsTypedMessage) |
| | | 314 | | { |
| | 5 | 315 | | return false; |
| | | 316 | | } |
| | | 317 | | |
| | 2693 | 318 | | if (responseMessage != null) |
| | | 319 | | { |
| | 2379 | 320 | | if (responseMessage.Headers.Count > 0) |
| | | 321 | | { |
| | 0 | 322 | | return false; |
| | | 323 | | } |
| | | 324 | | |
| | 2379 | 325 | | if (responseMessage.Properties.Count > 0) |
| | | 326 | | { |
| | 0 | 327 | | return false; |
| | | 328 | | } |
| | | 329 | | |
| | 2379 | 330 | | if (responseMessage.IsTypedMessage) |
| | | 331 | | { |
| | 0 | 332 | | return false; |
| | | 333 | | } |
| | | 334 | | } |
| | 2693 | 335 | | if (!AreTypesSupported(requestMessage.Body.Parts)) |
| | | 336 | | { |
| | 666 | 337 | | return false; |
| | | 338 | | } |
| | | 339 | | |
| | 2027 | 340 | | if (responseMessage != null) |
| | | 341 | | { |
| | 1717 | 342 | | if (!AreTypesSupported(responseMessage.Body.Parts)) |
| | | 343 | | { |
| | 1 | 344 | | return false; |
| | | 345 | | } |
| | | 346 | | |
| | 1716 | 347 | | if (responseMessage.Body.ReturnValue != null && !IsTypeSupported(responseMessage.Body.ReturnValue)) |
| | | 348 | | { |
| | 54 | 349 | | return false; |
| | | 350 | | } |
| | | 351 | | } |
| | 1972 | 352 | | return true; |
| | | 353 | | } |
| | | 354 | | |
| | | 355 | | private static bool AreTypesSupported(MessagePartDescriptionCollection bodyDescriptions) |
| | | 356 | | { |
| | 11784 | 357 | | for (int i = 0; i < bodyDescriptions.Count; i++) |
| | | 358 | | { |
| | 2149 | 359 | | if (!IsTypeSupported(bodyDescriptions[i])) |
| | | 360 | | { |
| | 667 | 361 | | return false; |
| | | 362 | | } |
| | | 363 | | } |
| | | 364 | | |
| | 3743 | 365 | | return true; |
| | | 366 | | } |
| | | 367 | | |
| | | 368 | | private static bool IsTypeSupported(MessagePartDescription bodyDescription) |
| | | 369 | | { |
| | | 370 | | Fx.Assert(bodyDescription != null, ""); |
| | 3865 | 371 | | Type type = bodyDescription.Type; |
| | 3865 | 372 | | if (type == null) |
| | | 373 | | { |
| | 0 | 374 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFx |
| | | 375 | | } |
| | | 376 | | |
| | 3865 | 377 | | if (bodyDescription.Multiple) |
| | | 378 | | { |
| | 0 | 379 | | return false; |
| | | 380 | | } |
| | | 381 | | |
| | 3865 | 382 | | if (type == typeof(void)) |
| | | 383 | | { |
| | 149 | 384 | | return true; |
| | | 385 | | } |
| | | 386 | | |
| | 3716 | 387 | | if (type.GetTypeInfo().IsEnum) |
| | | 388 | | { |
| | 1 | 389 | | return false; |
| | | 390 | | } |
| | | 391 | | |
| | 3715 | 392 | | switch (type.GetTypeCode()) |
| | | 393 | | { |
| | | 394 | | case TypeCode.Boolean: |
| | | 395 | | case TypeCode.DateTime: |
| | | 396 | | case TypeCode.Decimal: |
| | | 397 | | case TypeCode.Double: |
| | | 398 | | case TypeCode.Int32: |
| | | 399 | | case TypeCode.Int64: |
| | | 400 | | case TypeCode.Single: |
| | | 401 | | case TypeCode.String: |
| | 2940 | 402 | | return true; |
| | | 403 | | case TypeCode.Object: |
| | 762 | 404 | | if (type.IsArray && type.GetArrayRank() == 1 && IsArrayTypeSupported(type.GetElementType())) |
| | | 405 | | { |
| | 55 | 406 | | return true; |
| | | 407 | | } |
| | | 408 | | |
| | | 409 | | break; |
| | | 410 | | default: |
| | | 411 | | break; |
| | | 412 | | } |
| | 720 | 413 | | return false; |
| | | 414 | | } |
| | | 415 | | |
| | | 416 | | private static bool IsArrayTypeSupported(Type type) |
| | | 417 | | { |
| | 59 | 418 | | if (type.GetTypeInfo().IsEnum) |
| | | 419 | | { |
| | 0 | 420 | | return false; |
| | | 421 | | } |
| | | 422 | | |
| | 59 | 423 | | switch (type.GetTypeCode()) |
| | | 424 | | { |
| | | 425 | | case TypeCode.Byte: |
| | | 426 | | case TypeCode.Boolean: |
| | | 427 | | case TypeCode.DateTime: |
| | | 428 | | case TypeCode.Decimal: |
| | | 429 | | case TypeCode.Int32: |
| | | 430 | | case TypeCode.Int64: |
| | | 431 | | case TypeCode.Single: |
| | | 432 | | case TypeCode.Double: |
| | 55 | 433 | | return true; |
| | | 434 | | default: |
| | 4 | 435 | | return false; |
| | | 436 | | } |
| | | 437 | | } |
| | | 438 | | |
| | | 439 | | public Message SerializeRequest(MessageVersion messageVersion, object[] parameters) |
| | | 440 | | { |
| | 1 | 441 | | if (messageVersion == null) |
| | | 442 | | { |
| | 0 | 443 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(messageVersion)); |
| | | 444 | | } |
| | | 445 | | |
| | 1 | 446 | | if (parameters == null) |
| | | 447 | | { |
| | 0 | 448 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(parameters)); |
| | | 449 | | } |
| | | 450 | | |
| | 1 | 451 | | return Message.CreateMessage(messageVersion, GetActionHeader(messageVersion.Addressing), new PrimitiveReques |
| | | 452 | | } |
| | | 453 | | |
| | | 454 | | public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result) |
| | | 455 | | { |
| | 400 | 456 | | if (messageVersion == null) |
| | | 457 | | { |
| | 0 | 458 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(messageVersion)); |
| | | 459 | | } |
| | | 460 | | |
| | 400 | 461 | | if (parameters == null) |
| | | 462 | | { |
| | 0 | 463 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(parameters)); |
| | | 464 | | } |
| | | 465 | | |
| | 400 | 466 | | return Message.CreateMessage(messageVersion, GetReplyActionHeader(messageVersion.Addressing), new PrimitiveR |
| | | 467 | | } |
| | | 468 | | |
| | | 469 | | public object DeserializeReply(Message message, object[] parameters) |
| | | 470 | | { |
| | 1 | 471 | | if (message == null) |
| | | 472 | | { |
| | 0 | 473 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(message))); |
| | | 474 | | } |
| | | 475 | | |
| | 1 | 476 | | if (parameters == null) |
| | | 477 | | { |
| | 0 | 478 | | throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(parameters)), message); |
| | | 479 | | } |
| | | 480 | | |
| | | 481 | | try |
| | | 482 | | { |
| | 1 | 483 | | if (message.IsEmpty) |
| | | 484 | | { |
| | 0 | 485 | | if (_responseWrapperName == null) |
| | | 486 | | { |
| | 0 | 487 | | return null; |
| | | 488 | | } |
| | | 489 | | |
| | 0 | 490 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.SFxInvalidMe |
| | | 491 | | } |
| | | 492 | | |
| | 1 | 493 | | XmlDictionaryReader bodyReader = message.GetReaderAtBodyContents(); |
| | 1 | 494 | | using (bodyReader) |
| | | 495 | | { |
| | 1 | 496 | | object returnValue = DeserializeResponse(bodyReader, parameters); |
| | 1 | 497 | | message.ReadFromBodyContentsToEnd(bodyReader); |
| | 1 | 498 | | return returnValue; |
| | | 499 | | } |
| | | 500 | | } |
| | 0 | 501 | | catch (XmlException xe) |
| | | 502 | | { |
| | 0 | 503 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException( |
| | 0 | 504 | | SR.Format(SR.SFxErrorDeserializingReplyBodyMore, _operation.Name, xe.Message), xe)); |
| | | 505 | | } |
| | 0 | 506 | | catch (FormatException fe) |
| | | 507 | | { |
| | 0 | 508 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException( |
| | 0 | 509 | | SR.Format(SR.SFxErrorDeserializingReplyBodyMore, _operation.Name, fe.Message), fe)); |
| | | 510 | | } |
| | 0 | 511 | | catch (SerializationException se) |
| | | 512 | | { |
| | 0 | 513 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException( |
| | 0 | 514 | | SR.Format(SR.SFxErrorDeserializingReplyBodyMore, _operation.Name, se.Message), se)); |
| | | 515 | | } |
| | 1 | 516 | | } |
| | | 517 | | |
| | | 518 | | public void DeserializeRequest(Message message, object[] parameters) |
| | | 519 | | { |
| | 2263 | 520 | | if (message == null) |
| | | 521 | | { |
| | 0 | 522 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(message))); |
| | | 523 | | } |
| | | 524 | | |
| | 2263 | 525 | | if (parameters == null) |
| | | 526 | | { |
| | 0 | 527 | | throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(parameters)), message); |
| | | 528 | | } |
| | | 529 | | |
| | | 530 | | try |
| | | 531 | | { |
| | 2263 | 532 | | if (message.IsEmpty) |
| | | 533 | | { |
| | 0 | 534 | | if (_requestWrapperName == null) |
| | | 535 | | { |
| | 0 | 536 | | return; |
| | | 537 | | } |
| | | 538 | | |
| | 0 | 539 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.SFxInvalidMe |
| | | 540 | | } |
| | | 541 | | |
| | 2263 | 542 | | XmlDictionaryReader bodyReader = message.GetReaderAtBodyContents(); |
| | 2263 | 543 | | using (bodyReader) |
| | | 544 | | { |
| | 2263 | 545 | | DeserializeRequest(bodyReader, parameters); |
| | 2262 | 546 | | message.ReadFromBodyContentsToEnd(bodyReader); |
| | 2262 | 547 | | } |
| | 2262 | 548 | | } |
| | 0 | 549 | | catch (XmlException xe) |
| | | 550 | | { |
| | 0 | 551 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 552 | | NetDispatcherFaultException.CreateDeserializationFailedFault( |
| | 0 | 553 | | SR.Format(SR.SFxErrorDeserializingRequestBodyMore, _operation.Name, xe.Message), |
| | 0 | 554 | | xe)); |
| | | 555 | | } |
| | 0 | 556 | | catch (FormatException fe) |
| | | 557 | | { |
| | 0 | 558 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 559 | | NetDispatcherFaultException.CreateDeserializationFailedFault( |
| | 0 | 560 | | SR.Format(SR.SFxErrorDeserializingRequestBodyMore, _operation.Name, fe.Message), |
| | 0 | 561 | | fe)); |
| | | 562 | | } |
| | 1 | 563 | | catch (SerializationException se) |
| | | 564 | | { |
| | 1 | 565 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException( |
| | 1 | 566 | | SR.Format(SR.SFxErrorDeserializingRequestBodyMore, _operation.Name, se.Message), |
| | 1 | 567 | | se)); |
| | | 568 | | } |
| | 2262 | 569 | | } |
| | | 570 | | |
| | | 571 | | private void DeserializeRequest(XmlDictionaryReader reader, object[] parameters) |
| | | 572 | | { |
| | 2263 | 573 | | if (_requestWrapperName != null) |
| | | 574 | | { |
| | 2263 | 575 | | if (!reader.IsStartElement(_requestWrapperName, _requestWrapperNamespace)) |
| | | 576 | | { |
| | 1 | 577 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(SR.SF |
| | | 578 | | } |
| | | 579 | | |
| | 2262 | 580 | | bool isEmptyElement = reader.IsEmptyElement; |
| | 2262 | 581 | | reader.Read(); |
| | 2262 | 582 | | if (isEmptyElement) |
| | | 583 | | { |
| | 138 | 584 | | return; |
| | | 585 | | } |
| | | 586 | | } |
| | | 587 | | |
| | 2124 | 588 | | DeserializeParameters(reader, _requestParts, parameters); |
| | | 589 | | |
| | 2124 | 590 | | if (_requestWrapperName != null) |
| | | 591 | | { |
| | 2124 | 592 | | reader.ReadEndElement(); |
| | | 593 | | } |
| | 2124 | 594 | | } |
| | | 595 | | |
| | | 596 | | private object DeserializeResponse(XmlDictionaryReader reader, object[] parameters) |
| | | 597 | | { |
| | 1 | 598 | | if (_responseWrapperName != null) |
| | | 599 | | { |
| | 1 | 600 | | if (!reader.IsStartElement(_responseWrapperName, _responseWrapperNamespace)) |
| | | 601 | | { |
| | 0 | 602 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(SR.SF |
| | | 603 | | } |
| | | 604 | | |
| | 1 | 605 | | bool isEmptyElement = reader.IsEmptyElement; |
| | 1 | 606 | | reader.Read(); |
| | 1 | 607 | | if (isEmptyElement) |
| | | 608 | | { |
| | 0 | 609 | | return null; |
| | | 610 | | } |
| | | 611 | | } |
| | | 612 | | |
| | 1 | 613 | | object returnValue = null; |
| | 1 | 614 | | if (_returnPart != null) |
| | | 615 | | { |
| | 0 | 616 | | while (true) |
| | | 617 | | { |
| | 0 | 618 | | if (IsPartElement(reader, _returnPart)) |
| | | 619 | | { |
| | 0 | 620 | | returnValue = DeserializeParameter(reader, _returnPart); |
| | 0 | 621 | | break; |
| | | 622 | | } |
| | 0 | 623 | | if (!reader.IsStartElement()) |
| | | 624 | | { |
| | | 625 | | break; |
| | | 626 | | } |
| | | 627 | | |
| | 0 | 628 | | if (IsPartElements(reader, _responseParts)) |
| | | 629 | | { |
| | | 630 | | break; |
| | | 631 | | } |
| | | 632 | | |
| | 0 | 633 | | OperationFormatter.TraceAndSkipElement(reader); |
| | | 634 | | } |
| | | 635 | | } |
| | 1 | 636 | | DeserializeParameters(reader, _responseParts, parameters); |
| | | 637 | | |
| | 1 | 638 | | if (_responseWrapperName != null) |
| | | 639 | | { |
| | 1 | 640 | | reader.ReadEndElement(); |
| | | 641 | | } |
| | | 642 | | |
| | 1 | 643 | | return returnValue; |
| | | 644 | | } |
| | | 645 | | |
| | | 646 | | private void DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, object[] parameters) |
| | | 647 | | { |
| | 2125 | 648 | | if (parts.Length != parameters.Length) |
| | | 649 | | { |
| | 0 | 650 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 651 | | new ArgumentException(SR.Format(SR.SFxParameterCountMismatch, "parts", parts.Length, "parameters", p |
| | | 652 | | } |
| | | 653 | | |
| | 2125 | 654 | | int nextPartIndex = 0; |
| | 4196 | 655 | | while (reader.IsStartElement()) |
| | | 656 | | { |
| | 8322 | 657 | | for (int i = nextPartIndex; i < parts.Length; i++) |
| | | 658 | | { |
| | 2090 | 659 | | PartInfo part = parts[i]; |
| | 2090 | 660 | | if (IsPartElement(reader, part)) |
| | | 661 | | { |
| | 2086 | 662 | | parameters[part.Description.Index] = DeserializeParameter(reader, parts[i]); |
| | 2086 | 663 | | nextPartIndex = i + 1; |
| | | 664 | | } |
| | | 665 | | else |
| | | 666 | | { |
| | 4 | 667 | | parameters[part.Description.Index] = null; |
| | | 668 | | } |
| | | 669 | | } |
| | | 670 | | |
| | 2071 | 671 | | if (reader.IsStartElement()) |
| | | 672 | | { |
| | 4 | 673 | | OperationFormatter.TraceAndSkipElement(reader); |
| | | 674 | | } |
| | | 675 | | } |
| | 2125 | 676 | | } |
| | | 677 | | |
| | | 678 | | private bool IsPartElements(XmlDictionaryReader reader, PartInfo[] parts) |
| | | 679 | | { |
| | 0 | 680 | | foreach (PartInfo part in parts) |
| | | 681 | | { |
| | 0 | 682 | | if (IsPartElement(reader, part)) |
| | | 683 | | { |
| | 0 | 684 | | return true; |
| | | 685 | | } |
| | | 686 | | } |
| | | 687 | | |
| | 0 | 688 | | return false; |
| | | 689 | | } |
| | | 690 | | |
| | | 691 | | private bool IsPartElement(XmlDictionaryReader reader, PartInfo part) |
| | | 692 | | { |
| | 2090 | 693 | | return reader.IsStartElement(part.DictionaryName, part.DictionaryNamespace); |
| | | 694 | | } |
| | | 695 | | |
| | | 696 | | private object DeserializeParameter(XmlDictionaryReader reader, PartInfo part) |
| | | 697 | | { |
| | 2086 | 698 | | if (reader.AttributeCount > 0 && |
| | 2086 | 699 | | reader.MoveToAttribute(_xsiNilLocalName.Value, _xsiNilNamespace.Value) && |
| | 2086 | 700 | | reader.ReadContentAsBoolean()) |
| | | 701 | | { |
| | 0 | 702 | | reader.Skip(); |
| | 0 | 703 | | return null; |
| | | 704 | | } |
| | 2086 | 705 | | return part.ReadValue(reader); |
| | | 706 | | } |
| | | 707 | | |
| | | 708 | | private void SerializeParameter(XmlDictionaryWriter writer, PartInfo part, object graph) |
| | | 709 | | { |
| | 383 | 710 | | writer.WriteStartElement(part.DictionaryName, part.DictionaryNamespace); |
| | 383 | 711 | | if (graph == null) |
| | | 712 | | { |
| | 1 | 713 | | writer.WriteStartAttribute(_xsiNilLocalName, _xsiNilNamespace); |
| | 1 | 714 | | writer.WriteValue(true); |
| | 1 | 715 | | writer.WriteEndAttribute(); |
| | | 716 | | } |
| | | 717 | | else |
| | | 718 | | { |
| | 382 | 719 | | part.WriteValue(writer, graph); |
| | | 720 | | } |
| | | 721 | | |
| | 383 | 722 | | writer.WriteEndElement(); |
| | 383 | 723 | | } |
| | | 724 | | |
| | | 725 | | private void SerializeParameters(XmlDictionaryWriter writer, PartInfo[] parts, object[] parameters) |
| | | 726 | | { |
| | 401 | 727 | | if (parts.Length != parameters.Length) |
| | | 728 | | { |
| | 0 | 729 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 730 | | new ArgumentException(SR.Format(SR.SFxParameterCountMismatch, "parts", parts.Length, "parameters", p |
| | | 731 | | } |
| | | 732 | | |
| | 816 | 733 | | for (int i = 0; i < parts.Length; i++) |
| | | 734 | | { |
| | 7 | 735 | | PartInfo part = parts[i]; |
| | 7 | 736 | | SerializeParameter(writer, part, parameters[part.Description.Index]); |
| | | 737 | | } |
| | 401 | 738 | | } |
| | | 739 | | |
| | | 740 | | private void SerializeRequest(XmlDictionaryWriter writer, object[] parameters) |
| | | 741 | | { |
| | 1 | 742 | | if (_requestWrapperName != null) |
| | | 743 | | { |
| | 1 | 744 | | writer.WriteStartElement(_requestWrapperName, _requestWrapperNamespace); |
| | | 745 | | } |
| | | 746 | | |
| | 1 | 747 | | SerializeParameters(writer, _requestParts, parameters); |
| | | 748 | | |
| | 1 | 749 | | if (_requestWrapperName != null) |
| | | 750 | | { |
| | 1 | 751 | | writer.WriteEndElement(); |
| | | 752 | | } |
| | 1 | 753 | | } |
| | | 754 | | |
| | | 755 | | private void SerializeResponse(XmlDictionaryWriter writer, object returnValue, object[] parameters) |
| | | 756 | | { |
| | 400 | 757 | | if (_responseWrapperName != null) |
| | | 758 | | { |
| | 400 | 759 | | writer.WriteStartElement(_responseWrapperName, _responseWrapperNamespace); |
| | | 760 | | } |
| | | 761 | | |
| | 400 | 762 | | if (_returnPart != null) |
| | | 763 | | { |
| | 376 | 764 | | SerializeParameter(writer, _returnPart, returnValue); |
| | | 765 | | } |
| | | 766 | | |
| | 400 | 767 | | SerializeParameters(writer, _responseParts, parameters); |
| | | 768 | | |
| | 400 | 769 | | if (_responseWrapperName != null) |
| | | 770 | | { |
| | 400 | 771 | | writer.WriteEndElement(); |
| | | 772 | | } |
| | 400 | 773 | | } |
| | | 774 | | |
| | | 775 | | private class PartInfo |
| | | 776 | | { |
| | | 777 | | private readonly XmlDictionaryString _itemName; |
| | | 778 | | private readonly XmlDictionaryString _itemNamespace; |
| | | 779 | | private readonly TypeCode _typeCode; |
| | | 780 | | private readonly bool _isArray; |
| | | 781 | | |
| | 2988 | 782 | | public PartInfo(MessagePartDescription description, XmlDictionaryString dictionaryName, XmlDictionaryString |
| | | 783 | | { |
| | 2988 | 784 | | DictionaryName = dictionaryName; |
| | 2988 | 785 | | DictionaryNamespace = dictionaryNamespace; |
| | 2988 | 786 | | _itemName = itemName; |
| | 2988 | 787 | | _itemNamespace = itemNamespace; |
| | 2988 | 788 | | Description = description; |
| | 2988 | 789 | | if (description.Type.IsArray) |
| | | 790 | | { |
| | 55 | 791 | | _isArray = true; |
| | 55 | 792 | | _typeCode = description.Type.GetElementType().GetTypeCode(); |
| | | 793 | | } |
| | | 794 | | else |
| | | 795 | | { |
| | 2933 | 796 | | _isArray = false; |
| | 2933 | 797 | | _typeCode = description.Type.GetTypeCode(); |
| | | 798 | | } |
| | 2933 | 799 | | } |
| | | 800 | | |
| | 2097 | 801 | | public MessagePartDescription Description { get; } |
| | | 802 | | |
| | 2473 | 803 | | public XmlDictionaryString DictionaryName { get; } |
| | | 804 | | |
| | 2473 | 805 | | public XmlDictionaryString DictionaryNamespace { get; } |
| | | 806 | | |
| | | 807 | | public object ReadValue(XmlDictionaryReader reader) |
| | | 808 | | { |
| | | 809 | | object value; |
| | 2086 | 810 | | if (_isArray) |
| | | 811 | | { |
| | 30 | 812 | | switch (_typeCode) |
| | | 813 | | { |
| | | 814 | | case TypeCode.Byte: |
| | 26 | 815 | | value = reader.ReadElementContentAsBase64(); |
| | 26 | 816 | | break; |
| | | 817 | | case TypeCode.Boolean: |
| | 0 | 818 | | if (!reader.IsEmptyElement) |
| | | 819 | | { |
| | 0 | 820 | | reader.ReadStartElement(); |
| | 0 | 821 | | value = reader.ReadBooleanArray(_itemName, _itemNamespace); |
| | 0 | 822 | | reader.ReadEndElement(); |
| | | 823 | | } |
| | | 824 | | else |
| | | 825 | | { |
| | 0 | 826 | | reader.Read(); |
| | 0 | 827 | | value = Array.Empty<bool>(); |
| | | 828 | | } |
| | 0 | 829 | | break; |
| | | 830 | | case TypeCode.DateTime: |
| | 0 | 831 | | if (!reader.IsEmptyElement) |
| | | 832 | | { |
| | 0 | 833 | | reader.ReadStartElement(); |
| | 0 | 834 | | value = reader.ReadDateTimeArray(_itemName, _itemNamespace); |
| | 0 | 835 | | reader.ReadEndElement(); |
| | | 836 | | } |
| | | 837 | | else |
| | | 838 | | { |
| | 0 | 839 | | reader.Read(); |
| | 0 | 840 | | value = Array.Empty<DateTime>(); |
| | | 841 | | } |
| | 0 | 842 | | break; |
| | | 843 | | case TypeCode.Decimal: |
| | 0 | 844 | | if (!reader.IsEmptyElement) |
| | | 845 | | { |
| | 0 | 846 | | reader.ReadStartElement(); |
| | 0 | 847 | | value = reader.ReadDecimalArray(_itemName, _itemNamespace); |
| | 0 | 848 | | reader.ReadEndElement(); |
| | | 849 | | } |
| | | 850 | | else |
| | | 851 | | { |
| | 0 | 852 | | reader.Read(); |
| | 0 | 853 | | value = Array.Empty<decimal>(); |
| | | 854 | | } |
| | 0 | 855 | | break; |
| | | 856 | | case TypeCode.Int32: |
| | 4 | 857 | | if (!reader.IsEmptyElement) |
| | | 858 | | { |
| | 3 | 859 | | reader.ReadStartElement(); |
| | 3 | 860 | | value = reader.ReadInt32Array(_itemName, _itemNamespace); |
| | 3 | 861 | | reader.ReadEndElement(); |
| | | 862 | | } |
| | | 863 | | else |
| | | 864 | | { |
| | 1 | 865 | | reader.Read(); |
| | 1 | 866 | | value = Array.Empty<int>(); |
| | | 867 | | } |
| | 1 | 868 | | break; |
| | | 869 | | case TypeCode.Int64: |
| | 0 | 870 | | if (!reader.IsEmptyElement) |
| | | 871 | | { |
| | 0 | 872 | | reader.ReadStartElement(); |
| | 0 | 873 | | value = reader.ReadInt64Array(_itemName, _itemNamespace); |
| | 0 | 874 | | reader.ReadEndElement(); |
| | | 875 | | } |
| | | 876 | | else |
| | | 877 | | { |
| | 0 | 878 | | reader.Read(); |
| | 0 | 879 | | value = Array.Empty<long>(); |
| | | 880 | | } |
| | 0 | 881 | | break; |
| | | 882 | | case TypeCode.Single: |
| | 0 | 883 | | if (!reader.IsEmptyElement) |
| | | 884 | | { |
| | 0 | 885 | | reader.ReadStartElement(); |
| | 0 | 886 | | value = reader.ReadSingleArray(_itemName, _itemNamespace); |
| | 0 | 887 | | reader.ReadEndElement(); |
| | | 888 | | } |
| | | 889 | | else |
| | | 890 | | { |
| | 0 | 891 | | reader.Read(); |
| | 0 | 892 | | value = Array.Empty<float>(); |
| | | 893 | | } |
| | 0 | 894 | | break; |
| | | 895 | | case TypeCode.Double: |
| | 0 | 896 | | if (!reader.IsEmptyElement) |
| | | 897 | | { |
| | 0 | 898 | | reader.ReadStartElement(); |
| | 0 | 899 | | value = reader.ReadDoubleArray(_itemName, _itemNamespace); |
| | 0 | 900 | | reader.ReadEndElement(); |
| | | 901 | | } |
| | | 902 | | else |
| | | 903 | | { |
| | 0 | 904 | | reader.Read(); |
| | 0 | 905 | | value = Array.Empty<double>(); |
| | | 906 | | } |
| | 0 | 907 | | break; |
| | | 908 | | default: |
| | 0 | 909 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.S |
| | | 910 | | } |
| | | 911 | | } |
| | | 912 | | else |
| | | 913 | | { |
| | 2056 | 914 | | switch (_typeCode) |
| | | 915 | | { |
| | | 916 | | case TypeCode.Boolean: |
| | 4 | 917 | | value = reader.ReadElementContentAsBoolean(); |
| | 4 | 918 | | break; |
| | | 919 | | case TypeCode.DateTime: |
| | 0 | 920 | | value = reader.ReadElementContentAsDateTime(); |
| | 0 | 921 | | break; |
| | | 922 | | case TypeCode.Decimal: |
| | 0 | 923 | | value = reader.ReadElementContentAsDecimal(); |
| | 0 | 924 | | break; |
| | | 925 | | case TypeCode.Double: |
| | 0 | 926 | | value = reader.ReadElementContentAsDouble(); |
| | 0 | 927 | | break; |
| | | 928 | | case TypeCode.Int32: |
| | 24 | 929 | | value = reader.ReadElementContentAsInt(); |
| | 24 | 930 | | break; |
| | | 931 | | case TypeCode.Int64: |
| | 0 | 932 | | value = reader.ReadElementContentAsLong(); |
| | 0 | 933 | | break; |
| | | 934 | | case TypeCode.Single: |
| | 0 | 935 | | value = reader.ReadElementContentAsFloat(); |
| | 0 | 936 | | break; |
| | | 937 | | case TypeCode.String: |
| | 2028 | 938 | | return reader.ReadElementContentAsString(); |
| | | 939 | | default: |
| | 0 | 940 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.S |
| | | 941 | | } |
| | | 942 | | } |
| | 58 | 943 | | return value; |
| | | 944 | | } |
| | | 945 | | |
| | | 946 | | public void WriteValue(XmlDictionaryWriter writer, object value) |
| | | 947 | | { |
| | 382 | 948 | | if (_isArray) |
| | | 949 | | { |
| | 28 | 950 | | switch (_typeCode) |
| | | 951 | | { |
| | | 952 | | case TypeCode.Byte: |
| | | 953 | | { |
| | 27 | 954 | | byte[] arrayValue = (byte[])value; |
| | 27 | 955 | | writer.WriteBase64(arrayValue, 0, arrayValue.Length); |
| | | 956 | | } |
| | 27 | 957 | | break; |
| | | 958 | | case TypeCode.Boolean: |
| | | 959 | | { |
| | 0 | 960 | | bool[] arrayValue = (bool[])value; |
| | 0 | 961 | | writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length); |
| | | 962 | | } |
| | 0 | 963 | | break; |
| | | 964 | | case TypeCode.DateTime: |
| | | 965 | | { |
| | 0 | 966 | | DateTime[] arrayValue = (DateTime[])value; |
| | 0 | 967 | | writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length); |
| | | 968 | | } |
| | 0 | 969 | | break; |
| | | 970 | | case TypeCode.Decimal: |
| | | 971 | | { |
| | 0 | 972 | | decimal[] arrayValue = (decimal[])value; |
| | 0 | 973 | | writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length); |
| | | 974 | | } |
| | 0 | 975 | | break; |
| | | 976 | | case TypeCode.Int32: |
| | | 977 | | { |
| | 0 | 978 | | int[] arrayValue = (int[])value; |
| | 0 | 979 | | writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length); |
| | | 980 | | } |
| | 0 | 981 | | break; |
| | | 982 | | case TypeCode.Int64: |
| | | 983 | | { |
| | 0 | 984 | | long[] arrayValue = (long[])value; |
| | 0 | 985 | | writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length); |
| | | 986 | | } |
| | 0 | 987 | | break; |
| | | 988 | | case TypeCode.Single: |
| | | 989 | | { |
| | 1 | 990 | | float[] arrayValue = (float[])value; |
| | 1 | 991 | | writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length); |
| | | 992 | | } |
| | 1 | 993 | | break; |
| | | 994 | | case TypeCode.Double: |
| | | 995 | | { |
| | 0 | 996 | | double[] arrayValue = (double[])value; |
| | 0 | 997 | | writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length); |
| | | 998 | | } |
| | 0 | 999 | | break; |
| | | 1000 | | default: |
| | 0 | 1001 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.S |
| | | 1002 | | } |
| | | 1003 | | } |
| | | 1004 | | else |
| | | 1005 | | { |
| | 354 | 1006 | | switch (_typeCode) |
| | | 1007 | | { |
| | | 1008 | | case TypeCode.Boolean: |
| | 4 | 1009 | | writer.WriteValue((bool)value); |
| | 4 | 1010 | | break; |
| | | 1011 | | case TypeCode.DateTime: |
| | 1 | 1012 | | writer.WriteValue((DateTime)value); |
| | 1 | 1013 | | break; |
| | | 1014 | | case TypeCode.Decimal: |
| | 1 | 1015 | | writer.WriteValue((decimal)value); |
| | 1 | 1016 | | break; |
| | | 1017 | | case TypeCode.Double: |
| | 1 | 1018 | | writer.WriteValue((double)value); |
| | 1 | 1019 | | break; |
| | | 1020 | | case TypeCode.Int32: |
| | 17 | 1021 | | writer.WriteValue((int)value); |
| | 17 | 1022 | | break; |
| | | 1023 | | case TypeCode.Int64: |
| | 3 | 1024 | | writer.WriteValue((long)value); |
| | 3 | 1025 | | break; |
| | | 1026 | | case TypeCode.Single: |
| | 1 | 1027 | | writer.WriteValue((float)value); |
| | 1 | 1028 | | break; |
| | | 1029 | | case TypeCode.String: |
| | 326 | 1030 | | writer.WriteString((string)value); |
| | 326 | 1031 | | break; |
| | | 1032 | | default: |
| | 0 | 1033 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.S |
| | | 1034 | | } |
| | | 1035 | | } |
| | | 1036 | | } |
| | | 1037 | | } |
| | | 1038 | | |
| | | 1039 | | private class PrimitiveRequestBodyWriter : BodyWriter |
| | | 1040 | | { |
| | | 1041 | | private readonly object[] _parameters; |
| | | 1042 | | private readonly PrimitiveOperationFormatter _primitiveOperationFormatter; |
| | | 1043 | | |
| | | 1044 | | public PrimitiveRequestBodyWriter(object[] parameters, PrimitiveOperationFormatter primitiveOperationFormatt |
| | 1 | 1045 | | : base(true) |
| | | 1046 | | { |
| | 1 | 1047 | | _parameters = parameters; |
| | 1 | 1048 | | _primitiveOperationFormatter = primitiveOperationFormatter; |
| | 1 | 1049 | | } |
| | | 1050 | | |
| | | 1051 | | protected override void OnWriteBodyContents(XmlDictionaryWriter writer) |
| | | 1052 | | { |
| | 1 | 1053 | | _primitiveOperationFormatter.SerializeRequest(writer, _parameters); |
| | 1 | 1054 | | } |
| | | 1055 | | } |
| | | 1056 | | |
| | | 1057 | | private class PrimitiveResponseBodyWriter : BodyWriter |
| | | 1058 | | { |
| | | 1059 | | private readonly object[] _parameters; |
| | | 1060 | | private readonly object _returnValue; |
| | | 1061 | | private readonly PrimitiveOperationFormatter _primitiveOperationFormatter; |
| | | 1062 | | |
| | | 1063 | | public PrimitiveResponseBodyWriter(object[] parameters, object returnValue, |
| | | 1064 | | PrimitiveOperationFormatter primitiveOperationFormatter) |
| | 400 | 1065 | | : base(true) |
| | | 1066 | | { |
| | 400 | 1067 | | _parameters = parameters; |
| | 400 | 1068 | | _returnValue = returnValue; |
| | 400 | 1069 | | _primitiveOperationFormatter = primitiveOperationFormatter; |
| | 400 | 1070 | | } |
| | | 1071 | | |
| | | 1072 | | protected override void OnWriteBodyContents(XmlDictionaryWriter writer) |
| | | 1073 | | { |
| | 400 | 1074 | | _primitiveOperationFormatter.SerializeResponse(writer, _returnValue, _parameters); |
| | 400 | 1075 | | } |
| | | 1076 | | } |
| | | 1077 | | } |
| | | 1078 | | } |