CreateSequenceResponse.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Channels
  5. {
  6. using System.Runtime;
  7. using System.Xml;
  8. sealed class CreateSequenceResponse : BodyWriter
  9. {
  10. EndpointAddress acceptAcksTo;
  11. AddressingVersion addressingVersion;
  12. Nullable<TimeSpan> expires;
  13. UniqueId identifier;
  14. bool ordered;
  15. ReliableMessagingVersion reliableMessagingVersion;
  16. CreateSequenceResponse()
  17. : base(true)
  18. {
  19. }
  20. public CreateSequenceResponse(AddressingVersion addressingVersion,
  21. ReliableMessagingVersion reliableMessagingVersion)
  22. : base(true)
  23. {
  24. this.addressingVersion = addressingVersion;
  25. this.reliableMessagingVersion = reliableMessagingVersion;
  26. }
  27. public EndpointAddress AcceptAcksTo
  28. {
  29. get
  30. {
  31. return this.acceptAcksTo;
  32. }
  33. set
  34. {
  35. this.acceptAcksTo = value;
  36. }
  37. }
  38. public Nullable<TimeSpan> Expires
  39. {
  40. get
  41. {
  42. return this.expires;
  43. }
  44. set
  45. {
  46. this.expires = value;
  47. }
  48. }
  49. public UniqueId Identifier
  50. {
  51. get
  52. {
  53. return this.identifier;
  54. }
  55. set
  56. {
  57. this.identifier = value;
  58. }
  59. }
  60. public bool Ordered
  61. {
  62. get
  63. {
  64. return this.ordered;
  65. }
  66. set
  67. {
  68. this.ordered = value;
  69. }
  70. }
  71. public static CreateSequenceResponseInfo Create(AddressingVersion addressingVersion,
  72. ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader)
  73. {
  74. if (reader == null)
  75. {
  76. Fx.Assert("Argument reader cannot be null.");
  77. }
  78. CreateSequenceResponseInfo createSequenceResponse = new CreateSequenceResponseInfo();
  79. WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
  80. XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(reliableMessagingVersion);
  81. reader.ReadStartElement(wsrmFeb2005Dictionary.CreateSequenceResponse, wsrmNs);
  82. reader.ReadStartElement(wsrmFeb2005Dictionary.Identifier, wsrmNs);
  83. createSequenceResponse.Identifier = reader.ReadContentAsUniqueId();
  84. reader.ReadEndElement();
  85. if (reader.IsStartElement(wsrmFeb2005Dictionary.Expires, wsrmNs))
  86. {
  87. reader.ReadElementContentAsTimeSpan();
  88. }
  89. if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
  90. {
  91. if (reader.IsStartElement(DXD.Wsrm11Dictionary.IncompleteSequenceBehavior, wsrmNs))
  92. {
  93. string incompleteSequenceBehavior = reader.ReadElementContentAsString();
  94. if ((incompleteSequenceBehavior != Wsrm11Strings.DiscardEntireSequence)
  95. && (incompleteSequenceBehavior != Wsrm11Strings.DiscardFollowingFirstGap)
  96. && (incompleteSequenceBehavior != Wsrm11Strings.NoDiscard))
  97. {
  98. string reason = SR.GetString(SR.CSResponseWithInvalidIncompleteSequenceBehavior);
  99. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(reason));
  100. }
  101. // Otherwise ignore the value.
  102. }
  103. }
  104. if (reader.IsStartElement(wsrmFeb2005Dictionary.Accept, wsrmNs))
  105. {
  106. reader.ReadStartElement();
  107. createSequenceResponse.AcceptAcksTo = EndpointAddress.ReadFrom(addressingVersion, reader,
  108. wsrmFeb2005Dictionary.AcksTo, wsrmNs);
  109. while (reader.IsStartElement())
  110. {
  111. reader.Skip();
  112. }
  113. reader.ReadEndElement();
  114. }
  115. while (reader.IsStartElement())
  116. {
  117. reader.Skip();
  118. }
  119. reader.ReadEndElement();
  120. return createSequenceResponse;
  121. }
  122. protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
  123. {
  124. WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
  125. XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(this.reliableMessagingVersion);
  126. writer.WriteStartElement(wsrmFeb2005Dictionary.CreateSequenceResponse, wsrmNs);
  127. writer.WriteStartElement(wsrmFeb2005Dictionary.Identifier, wsrmNs);
  128. writer.WriteValue(this.identifier);
  129. writer.WriteEndElement();
  130. if (this.expires.HasValue)
  131. {
  132. writer.WriteStartElement(wsrmFeb2005Dictionary.Expires, wsrmNs);
  133. writer.WriteValue(this.expires.Value);
  134. writer.WriteEndElement();
  135. }
  136. if (this.reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
  137. {
  138. Wsrm11Dictionary wsrm11Dictionary = DXD.Wsrm11Dictionary;
  139. writer.WriteStartElement(wsrm11Dictionary.IncompleteSequenceBehavior, wsrmNs);
  140. writer.WriteValue(
  141. this.ordered ? wsrm11Dictionary.DiscardFollowingFirstGap : wsrm11Dictionary.NoDiscard);
  142. writer.WriteEndElement();
  143. }
  144. if (this.acceptAcksTo != null)
  145. {
  146. writer.WriteStartElement(wsrmFeb2005Dictionary.Accept, wsrmNs);
  147. this.acceptAcksTo.WriteTo(this.addressingVersion, writer, wsrmFeb2005Dictionary.AcksTo, wsrmNs);
  148. writer.WriteEndElement();
  149. }
  150. writer.WriteEndElement();
  151. }
  152. }
  153. }