DiscoveryDocument.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //
  2. // System.Web.Services.Protocols.DiscoveryDocument.cs
  3. //
  4. // Author:
  5. // Dave Bettin ([email protected])
  6. // Tim Coleman ([email protected])
  7. // Lluis Sanchez Gual ([email protected])
  8. //
  9. // Copyright (C) Dave Bettin, 2002
  10. // Copyright (C) Tim Coleman, 2002
  11. //
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System.Collections;
  33. using System.IO;
  34. using System.Xml;
  35. using System.Xml.Serialization;
  36. namespace System.Web.Services.Discovery {
  37. [XmlRoot ("discovery", Namespace = "http://schemas.xmlsoap.org/disco/")]
  38. public sealed class DiscoveryDocument {
  39. #region Fields
  40. public const string Namespace = "http://schemas.xmlsoap.org/disco/";
  41. [XmlElement(typeof(ContractReference), Namespace="http://schemas.xmlsoap.org/disco/scl/")]
  42. [XmlElement(typeof(DiscoveryDocumentReference))]
  43. [XmlElement(typeof(SchemaReference))]
  44. internal ArrayList references = new ArrayList();
  45. [XmlElement(typeof(SoapBinding), ElementName="soap", Namespace="http://schemas/xmlsoap.org/disco/schema/soap/")]
  46. internal ArrayList additionalInfo = new ArrayList();
  47. #endregion // Fields
  48. #region Constructors
  49. public DiscoveryDocument ()
  50. {
  51. }
  52. #endregion // Constructors
  53. #region Properties
  54. [XmlIgnore]
  55. public IList References {
  56. get { return references; }
  57. }
  58. [XmlIgnore]
  59. internal IList AdditionalInfo {
  60. get { return additionalInfo; }
  61. }
  62. #endregion // Properties
  63. #region Methods
  64. public static bool CanRead (XmlReader xmlReader)
  65. {
  66. xmlReader.MoveToContent ();
  67. return xmlReader.NodeType == XmlNodeType.Element &&
  68. xmlReader.LocalName == "discovery" &&
  69. xmlReader.NamespaceURI == Namespace;
  70. }
  71. public static DiscoveryDocument Read (Stream stream)
  72. {
  73. return Read (new XmlTextReader (stream));
  74. }
  75. public static DiscoveryDocument Read (TextReader textReader)
  76. {
  77. return Read (new XmlTextReader (textReader));
  78. }
  79. public static DiscoveryDocument Read (XmlReader xmlReader)
  80. {
  81. DiscoveryDocumentSerializer ser = new DiscoveryDocumentSerializer();
  82. return (DiscoveryDocument) ser.Deserialize (xmlReader);
  83. }
  84. public void Write (Stream stream)
  85. {
  86. DiscoveryDocumentSerializer ser = new DiscoveryDocumentSerializer();
  87. ser.Serialize (stream, this, GetNamespaceList());
  88. }
  89. public void Write (TextWriter textWriter)
  90. {
  91. DiscoveryDocumentSerializer ser = new DiscoveryDocumentSerializer();
  92. ser.Serialize (textWriter, this, GetNamespaceList());
  93. }
  94. public void Write (XmlWriter xmlWriter)
  95. {
  96. DiscoveryDocumentSerializer ser = new DiscoveryDocumentSerializer();
  97. ser.Serialize (xmlWriter, this, GetNamespaceList());
  98. }
  99. XmlSerializerNamespaces GetNamespaceList ()
  100. {
  101. XmlSerializerNamespaces ns = new XmlSerializerNamespaces ();
  102. ns.Add ("scl", ContractReference.Namespace);
  103. return ns;
  104. }
  105. #endregion // Methods
  106. }
  107. internal class DiscoveryDocumentSerializer : XmlSerializer
  108. {
  109. protected override void Serialize (object o, XmlSerializationWriter writer)
  110. {
  111. DiscoveryDocumentWriter xsWriter = writer as DiscoveryDocumentWriter;
  112. xsWriter.WriteRoot_DiscoveryDocument (o);
  113. }
  114. protected override object Deserialize (XmlSerializationReader reader)
  115. {
  116. DiscoveryDocumentReader xsReader = reader as DiscoveryDocumentReader;
  117. return xsReader.ReadRoot_DiscoveryDocument ();
  118. }
  119. protected override XmlSerializationWriter CreateWriter ()
  120. {
  121. return new DiscoveryDocumentWriter ();
  122. }
  123. protected override XmlSerializationReader CreateReader ()
  124. {
  125. return new DiscoveryDocumentReader ();
  126. }
  127. }
  128. }