MessageBufferImpl.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // MessageBufferImpl.cs
  3. //
  4. // Author:
  5. // Duncan Mak ([email protected])
  6. //
  7. // Copyright (C) 2006 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Runtime.Serialization;
  30. using System.Xml;
  31. using System.Xml.XPath;
  32. namespace System.ServiceModel.Channels
  33. {
  34. internal class DefaultMessageBuffer : MessageBuffer
  35. {
  36. MessageHeaders headers;
  37. MessageProperties properties;
  38. BodyWriter body;
  39. bool closed, is_fault;
  40. internal DefaultMessageBuffer (MessageHeaders headers, MessageProperties properties)
  41. : this (headers, properties, null, false)
  42. {
  43. }
  44. internal DefaultMessageBuffer (MessageHeaders headers, MessageProperties properties, BodyWriter body, bool isFault)
  45. {
  46. this.headers = headers;
  47. this.body = body;
  48. this.closed = false;
  49. this.is_fault = isFault;
  50. this.properties = properties;
  51. }
  52. public override void Close ()
  53. {
  54. if (closed)
  55. return;
  56. headers = null;
  57. body = null;
  58. closed = true;
  59. }
  60. public override Message CreateMessage ()
  61. {
  62. if (closed)
  63. throw new ObjectDisposedException ("The message buffer has already been closed.");
  64. Message msg;
  65. if (body == null)
  66. msg = new EmptyMessage (headers.MessageVersion, headers.Action);
  67. else
  68. msg = new SimpleMessage (headers.MessageVersion, headers.Action, body, is_fault);
  69. msg.Properties.CopyProperties (properties);
  70. return msg;
  71. }
  72. public override int BufferSize {
  73. get { return 0; }
  74. }
  75. }
  76. #if !NET_2_1
  77. internal class XPathMessageBuffer : MessageBuffer
  78. {
  79. IXPathNavigable source;
  80. MessageVersion version;
  81. int max_header_size;
  82. MessageProperties properties;
  83. public XPathMessageBuffer (IXPathNavigable source, MessageVersion version, int maxSizeOfHeaders, MessageProperties properties)
  84. {
  85. this.source = source;
  86. this.version = version;
  87. this.max_header_size = maxSizeOfHeaders;
  88. this.properties = properties;
  89. }
  90. public override void Close ()
  91. {
  92. }
  93. public override Message CreateMessage ()
  94. {
  95. XmlDictionaryReader r = XmlDictionaryReader.CreateDictionaryReader (source.CreateNavigator ().ReadSubtree ());
  96. Message msg = new XmlReaderMessage (version, r, max_header_size);
  97. msg.Properties.CopyProperties (properties);
  98. return msg;
  99. }
  100. public override int BufferSize {
  101. // FIXME: implement
  102. get { return 0; }
  103. }
  104. }
  105. #endif
  106. }