ServiceDescription.cs 4.7 KB

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