ServiceDescription.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // System.Web.Services.Description.ServiceDescription.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2002
  8. //
  9. using System.IO;
  10. using System.Web.Services;
  11. using System.Web.Services.Configuration;
  12. using System.Xml;
  13. using System.Xml.Serialization;
  14. namespace System.Web.Services.Description {
  15. [XmlFormatExtensionPoint ("Extensions")]
  16. [XmlRoot ("definitions", Namespace = "http://schemas.xmlsoap.org/wsdl/")]
  17. public sealed class ServiceDescription : DocumentableItem {
  18. #region Fields
  19. public const string Namespace = "http://schemas.xmlsoap.org/wsdl/";
  20. BindingCollection bindings;
  21. ServiceDescriptionFormatExtensionCollection extensions;
  22. ImportCollection imports;
  23. MessageCollection messages;
  24. string name;
  25. PortTypeCollection portTypes;
  26. string retrievalUrl;
  27. ServiceDescriptionCollection serviceDescriptions;
  28. ServiceCollection services;
  29. string targetNamespace;
  30. Types types;
  31. static XmlSerializer serializer;
  32. #endregion // Fields
  33. #region Constructors
  34. static ServiceDescription ()
  35. {
  36. serializer = new XmlSerializer (typeof (ServiceDescription), Namespace);
  37. }
  38. public ServiceDescription ()
  39. {
  40. bindings = new BindingCollection (this);
  41. extensions = new ServiceDescriptionFormatExtensionCollection (this);
  42. imports = new ImportCollection (this);
  43. messages = new MessageCollection (this);
  44. name = String.Empty;
  45. portTypes = new PortTypeCollection (this);
  46. retrievalUrl = String.Empty;
  47. serviceDescriptions = null;
  48. services = new ServiceCollection (this);
  49. targetNamespace = String.Empty;
  50. types = null;
  51. }
  52. #endregion // Constructors
  53. #region Properties
  54. [XmlElement ("binding")]
  55. public BindingCollection Bindings {
  56. get { return bindings; }
  57. }
  58. [XmlIgnore]
  59. public ServiceDescriptionFormatExtensionCollection Extensions {
  60. get { return extensions; }
  61. }
  62. [XmlElement ("import")]
  63. public ImportCollection Imports {
  64. get { return imports; }
  65. }
  66. [XmlElement ("message")]
  67. public MessageCollection Messages {
  68. get { return messages; }
  69. }
  70. [XmlAttribute ("name", DataType = "NMTOKEN")]
  71. public string Name {
  72. get { return name; }
  73. set { name = value; }
  74. }
  75. [XmlElement ("portType")]
  76. public PortTypeCollection PortTypes {
  77. get { return portTypes; }
  78. }
  79. [XmlIgnore]
  80. public string RetrievalUrl {
  81. get { return retrievalUrl; }
  82. set { retrievalUrl = value; }
  83. }
  84. [XmlIgnore]
  85. public static XmlSerializer Serializer {
  86. get { return serializer; }
  87. }
  88. [XmlIgnore]
  89. public ServiceDescriptionCollection ServiceDescriptions {
  90. get {
  91. if (serviceDescriptions == null)
  92. throw new NullReferenceException ();
  93. return serviceDescriptions;
  94. }
  95. }
  96. [XmlElement ("service")]
  97. public ServiceCollection Services {
  98. get { return services; }
  99. }
  100. [XmlAttribute ("targetNamespace")]
  101. public string TargetNamespace {
  102. get { return targetNamespace; }
  103. set { targetNamespace = value; }
  104. }
  105. [XmlElement ("type")]
  106. public Types Types {
  107. get { return types; }
  108. set { types = value; }
  109. }
  110. #endregion // Properties
  111. #region Methods
  112. public static bool CanRead (XmlReader reader)
  113. {
  114. return serializer.CanDeserialize (reader);
  115. }
  116. public static ServiceDescription Read (Stream stream)
  117. {
  118. return (ServiceDescription) serializer.Deserialize (stream);
  119. }
  120. public static ServiceDescription Read (string fileName)
  121. {
  122. return Read (new FileStream (fileName, FileMode.Open));
  123. }
  124. public static ServiceDescription Read (TextReader textReader)
  125. {
  126. return (ServiceDescription) serializer.Deserialize (textReader);
  127. }
  128. public static ServiceDescription Read (XmlReader reader)
  129. {
  130. return (ServiceDescription) serializer.Deserialize (reader);
  131. }
  132. public void Write (Stream stream)
  133. {
  134. serializer.Serialize (stream, this);
  135. }
  136. public void Write (string fileName)
  137. {
  138. Write (new FileStream (fileName, FileMode.Create));
  139. }
  140. public void Write (TextWriter writer)
  141. {
  142. serializer.Serialize (writer, this);
  143. }
  144. public void Write (XmlWriter writer)
  145. {
  146. serializer.Serialize (writer, this);
  147. }
  148. internal void SetParent (ServiceDescriptionCollection serviceDescriptions)
  149. {
  150. this.serviceDescriptions = serviceDescriptions;
  151. }
  152. #endregion
  153. }
  154. }