ServiceDescription.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 ServiceDescriptionSerializer serializer;
  33. XmlSerializerNamespaces ns;
  34. #endregion // Fields
  35. #region Constructors
  36. static ServiceDescription ()
  37. {
  38. serializer = new ServiceDescriptionSerializer ();
  39. }
  40. [MonoTODO ("Move namespaces to subtype, use ServiceDescriptionSerializer")]
  41. public ServiceDescription ()
  42. {
  43. bindings = new BindingCollection (this);
  44. extensions = new ServiceDescriptionFormatExtensionCollection (this);
  45. imports = new ImportCollection (this);
  46. messages = new MessageCollection (this);
  47. name = String.Empty;
  48. portTypes = new PortTypeCollection (this);
  49. serviceDescriptions = null;
  50. services = new ServiceCollection (this);
  51. targetNamespace = String.Empty;
  52. types = null;
  53. ns = new XmlSerializerNamespaces ();
  54. ns.Add ("soap", SoapBinding.Namespace);
  55. ns.Add ("s", XmlSchema.Namespace);
  56. ns.Add ("http", HttpBinding.Namespace);
  57. ns.Add ("mime", MimeContentBinding.Namespace);
  58. ns.Add ("tm", MimeTextBinding.Namespace);
  59. }
  60. #endregion // Constructors
  61. #region Properties
  62. [XmlElement ("binding")]
  63. public BindingCollection Bindings {
  64. get { return bindings; }
  65. }
  66. [XmlIgnore]
  67. public ServiceDescriptionFormatExtensionCollection Extensions {
  68. get { return extensions; }
  69. }
  70. [XmlElement ("import")]
  71. public ImportCollection Imports {
  72. get { return imports; }
  73. }
  74. [XmlElement ("message")]
  75. public MessageCollection Messages {
  76. get { return messages; }
  77. }
  78. [XmlAttribute ("name", DataType = "NMTOKEN")]
  79. public string Name {
  80. get { return name; }
  81. set { name = value; }
  82. }
  83. [XmlElement ("portType")]
  84. public PortTypeCollection PortTypes {
  85. get { return portTypes; }
  86. }
  87. [XmlIgnore]
  88. public string RetrievalUrl {
  89. get { return retrievalUrl; }
  90. set { retrievalUrl = value; }
  91. }
  92. [XmlIgnore]
  93. public static XmlSerializer Serializer {
  94. get { return serializer; }
  95. }
  96. [XmlIgnore]
  97. public ServiceDescriptionCollection ServiceDescriptions {
  98. get {
  99. if (serviceDescriptions == null)
  100. throw new NullReferenceException ();
  101. return serviceDescriptions;
  102. }
  103. }
  104. [XmlElement ("service")]
  105. public ServiceCollection Services {
  106. get { return services; }
  107. }
  108. [XmlAttribute ("targetNamespace")]
  109. public string TargetNamespace {
  110. get { return targetNamespace; }
  111. set { targetNamespace = value; }
  112. }
  113. [XmlElement ("types")]
  114. public Types Types {
  115. get { return types; }
  116. set { types = value; }
  117. }
  118. #endregion // Properties
  119. #region Methods
  120. public static bool CanRead (XmlReader reader)
  121. {
  122. return serializer.CanDeserialize (reader);
  123. }
  124. public static ServiceDescription Read (Stream stream)
  125. {
  126. return (ServiceDescription) serializer.Deserialize (stream);
  127. }
  128. public static ServiceDescription Read (string fileName)
  129. {
  130. return Read (new FileStream (fileName, FileMode.Open));
  131. }
  132. public static ServiceDescription Read (TextReader textReader)
  133. {
  134. return (ServiceDescription) serializer.Deserialize (textReader);
  135. }
  136. public static ServiceDescription Read (XmlReader reader)
  137. {
  138. return (ServiceDescription) serializer.Deserialize (reader);
  139. }
  140. public void Write (Stream stream)
  141. {
  142. serializer.Serialize (stream, this, ns);
  143. }
  144. public void Write (string fileName)
  145. {
  146. Write (new FileStream (fileName, FileMode.Create));
  147. }
  148. public void Write (TextWriter writer)
  149. {
  150. serializer.Serialize (writer, this, ns);
  151. }
  152. public void Write (XmlWriter writer)
  153. {
  154. serializer.Serialize (writer, this, ns);
  155. }
  156. internal void SetParent (ServiceDescriptionCollection serviceDescriptions)
  157. {
  158. this.serviceDescriptions = serviceDescriptions;
  159. }
  160. #endregion
  161. internal class ServiceDescriptionSerializer : XmlSerializer {
  162. #region Fields
  163. XmlSerializerNamespaces ns;
  164. #endregion
  165. #region Constructors
  166. [MonoTODO]
  167. public ServiceDescriptionSerializer ()
  168. : base (typeof (ServiceDescription), ServiceDescription.Namespace)
  169. {
  170. ns = new XmlSerializerNamespaces ();
  171. ns.Add ("soap", SoapBinding.Namespace);
  172. ns.Add ("s", XmlSchema.Namespace);
  173. ns.Add ("http", HttpBinding.Namespace);
  174. ns.Add ("mime", MimeContentBinding.Namespace);
  175. ns.Add ("tm", MimeTextBinding.Namespace);
  176. }
  177. #endregion // Constructors
  178. #region Methods
  179. #endregion // Methods
  180. }
  181. }
  182. }