| | | 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.Xml; |
| | | 5 | | using CoreWCF.Diagnostics; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Channels |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Base class for non-SOAP messages |
| | | 11 | | /// </summary> |
| | | 12 | | internal abstract class ContentOnlyMessage : Message |
| | | 13 | | { |
| | | 14 | | private readonly MessageHeaders _headers; |
| | | 15 | | private MessageProperties _properties; |
| | | 16 | | |
| | | 17 | | protected ContentOnlyMessage() |
| | | 18 | | { |
| | | 19 | | _headers = new MessageHeaders(MessageVersion.None); |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | public override MessageHeaders Headers |
| | | 23 | | { |
| | | 24 | | get |
| | | 25 | | { |
| | | 26 | | if (IsDisposed) |
| | | 27 | | { |
| | | 28 | | throw TraceUtility.ThrowHelperError(CreateMessageDisposedException(), this); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | return _headers; |
| | | 32 | | } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public override MessageProperties Properties |
| | | 36 | | { |
| | | 37 | | get |
| | | 38 | | { |
| | | 39 | | if (IsDisposed) |
| | | 40 | | { |
| | | 41 | | throw TraceUtility.ThrowHelperError(CreateMessageDisposedException(), this); |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | if (_properties == null) |
| | | 45 | | { |
| | | 46 | | _properties = new MessageProperties(); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | return _properties; |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | public override MessageVersion Version |
| | | 54 | | { |
| | | 55 | | get |
| | | 56 | | { |
| | | 57 | | return _headers.MessageVersion; |
| | | 58 | | } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | protected override void OnBodyToString(XmlDictionaryWriter writer) |
| | | 62 | | { |
| | | 63 | | OnWriteBodyContents(writer); |
| | | 64 | | } |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | internal class StringMessage : ContentOnlyMessage |
| | | 68 | | { |
| | | 69 | | private readonly string _data; |
| | | 70 | | |
| | | 71 | | public StringMessage(string data) |
| | | 72 | | : base() |
| | | 73 | | { |
| | | 74 | | _data = data; |
| | | 75 | | } |
| | | 76 | | |
| | | 77 | | public override bool IsEmpty |
| | | 78 | | { |
| | | 79 | | get |
| | | 80 | | { |
| | | 81 | | return string.IsNullOrEmpty(_data); |
| | | 82 | | } |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | protected override void OnWriteBodyContents(XmlDictionaryWriter writer) |
| | | 86 | | { |
| | | 87 | | if (_data != null && _data.Length > 0) |
| | | 88 | | { |
| | | 89 | | writer.WriteElementString("BODY", _data); |
| | | 90 | | } |
| | | 91 | | } |
| | | 92 | | } |
| | | 93 | | |
| | | 94 | | internal class NullMessage : StringMessage |
| | | 95 | | { |
| | | 96 | | public NullMessage() |
| | 0 | 97 | | : base(string.Empty) |
| | | 98 | | { |
| | 0 | 99 | | } |
| | | 100 | | } |
| | | 101 | | } |