context: // 
  // System.Web.Services.Description.ServiceDescription.cs
  //
  // Author:
  //   Tim Coleman (tim@timcoleman.com)
  //   Lluis Sanchez Gual (lluis@ximian.com)
  //
  // Copyright (C) Tim Coleman, 2002
  //
  
  //
  // Permission is hereby granted, free of charge, to any person obtaining
  // a copy of this software and associated documentation files (the
  // "Software"), to deal in the Software without restriction, including
  // without limitation the rights to use, copy, modify, merge, publish,
  // distribute, sublicense, and/or sell copies of the Software, and to
  // permit persons to whom the Software is furnished to do so, subject to
  // the following conditions:
  // 
  // The above copyright notice and this permission notice shall be
  // included in all copies or substantial portions of the Software.
  // 
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  //
  
  using System.IO;
  using System.Collections;
  using System.Collections.Specialized;
  using System.Reflection;
  using System.Web.Services;
  using System.Web.Services.Configuration;
  using System.Xml;
  using System.Xml.Schema;
  using System.Xml.Serialization;
  
  using System.Collections.Generic;
  
  namespace System.Web.Services.Description
  {
  	[XmlFormatExtensionPoint ("Extensions")]
  	[XmlRoot ("definitions", Namespace = "http://schemas.xmlsoap.org/wsdl/")]
  	public sealed class ServiceDescription :
  		NamedItem
  	{
  		#region Fields
  
  		public const string Namespace = "http://schemas.xmlsoap.org/wsdl/";
  
  		BindingCollection bindings;
  		ServiceDescriptionFormatExtensionCollection extensions;
  		ImportCollection imports;
  		MessageCollection messages;
  		PortTypeCollection portTypes;
  		string retrievalUrl = String.Empty;
  		ServiceDescriptionCollection serviceDescriptions;
  		ServiceCollection services;
  		string targetNamespace;
  		Types types;
  		static ServiceDescriptionSerializer serializer;
  		StringCollection validationWarnings;
  
  		static XmlSchema schema;
  
  		#endregion // Fields
  
  		#region Constructors
  
  		static ServiceDescription ()
  		{
  			serializer = new ServiceDescriptionSerializer ();
  		}
  
  		public ServiceDescription ()
  		{
  			bindings = new BindingCollection (this);
  			extensions = new ServiceDescriptionFormatExtensionCollection (this);
  			imports = new ImportCollection (this);
  			messages = new MessageCollection (this);
  			portTypes = new PortTypeCollection (this);
  
  			serviceDescriptions = null;
  			services = new ServiceCollection (this);
  			targetNamespace = null;
  			types = new Types ();
  		}
  		
  		#endregion // Constructors
  
  		#region Properties
  
  		public static XmlSchema Schema {
  			get {
  				if (schema == null) {
  					schema = XmlSchema.Read (typeof (ServiceDescription).Assembly.GetManifestResourceStream ("wsdl-1.1.xsd"), null);
  				}
  				return schema;
  			}
  		}
  
  		[XmlElement ("import")]
  		public ImportCollection Imports {
  			get { return imports; }
  		}
  
  		[XmlElement ("types")]
  		public Types Types {
  			get { return types; }
  			set { types = value; }
  		}
  
  		[XmlElement ("message")]
  		public MessageCollection Messages {
  			get { return messages; }
  		}
  
  		[XmlElement ("portType")]	
  		public PortTypeCollection PortTypes {
  			get { return portTypes; }
  		}
  	
  		[XmlElement ("binding")]
  		public BindingCollection Bindings {
  			get { return bindings; }
  		}
  
  		[XmlIgnore]
  		public 
  		override
  		ServiceDescriptionFormatExtensionCollection Extensions { 	
  			get { return extensions; }
  		}
  
  
  		[XmlIgnore]	
  		public string RetrievalUrl {
  			get { return retrievalUrl; }
  			set { retrievalUrl = value; }
  		}
  	
  		[XmlIgnore]	
  		public static XmlSerializer Serializer {
  			get { return serializer; }
  		}
  
  		[XmlIgnore]
  		public ServiceDescriptionCollection ServiceDescriptions {
  			get { 
  				return serviceDescriptions; 
  			}
  		}
  
  		[XmlElement ("service")]
  		public ServiceCollection Services {
  			get { return services; }
  		}
  
  		[XmlAttribute ("targetNamespace")]
  		public string TargetNamespace {
  			get { return targetNamespace; }
  			set { targetNamespace = value; }
  		}
  
  		[XmlIgnore]
  		public StringCollection ValidationWarnings {
  			get { return validationWarnings; }
  		}
  
  		#endregion // Properties
  
  		#region Methods
  
  		public static bool CanRead (XmlReader reader)
  		{
  			reader.MoveToContent ();
  			return reader.LocalName == "definitions" && 
  				reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/";
  		}
  
  		public static ServiceDescription Read (string fileName, bool validate)
  		{
  			if (validate)
  				using (XmlReader reader = XmlReader.Create (fileName)) {
  					return Read (reader, true);
  				}
  			else
  				return Read (fileName);
  		}
  
  		public static ServiceDescription Read (Stream stream, bool validate)
  		{
  			if (validate)
  				return Read (XmlReader.Create (stream), true);
  			else
  				return Read (stream);
  		}
  
  		public static ServiceDescription Read (TextReader reader, bool validate)
  		{
  			if (validate)
  				return Read (XmlReader.Create (reader), true);
  			else
  				return Read (reader);
  		}
  
  		public static ServiceDescription Read (XmlReader reader, bool validate)
  		{
  			if (validate) {
  				StringCollection sc = new StringCollection ();
  				XmlReaderSettings s = new XmlReaderSettings ();
  				s.ValidationType = ValidationType.Schema;
  				s.Schemas.Add (Schema);
  				s.ValidationEventHandler += delegate (object o, ValidationEventArgs e) {
  					sc.Add (e.Message);
  				};
  
  				ServiceDescription ret = Read (XmlReader.Create (reader, s));
  				ret.validationWarnings = sc;
  				return ret;
  			}
  			else
  				return Read (reader);
  		}
  
  		public static ServiceDescription Read (Stream stream)
  		{
  			return (ServiceDescription) serializer.Deserialize (stream);
  		}
  
  		public static ServiceDescription Read (string fileName)
  		{
  			return Read (new FileStream (fileName, FileMode.Open, FileAccess.Read));
  		}
  
  		public static ServiceDescription Read (TextReader textReader)
  		{
  			return (ServiceDescription) serializer.Deserialize (textReader);
  		}
  
  		public static ServiceDescription Read (XmlReader reader)
  		{
  			return (ServiceDescription) serializer.Deserialize (reader);
  		}
  
  		public void Write (Stream stream)
  		{
  			serializer.Serialize (stream, this, GetNamespaceList ());
  		}
  
  		public void Write (string fileName)
  		{
  			Write (new FileStream (fileName, FileMode.Create));
  		}
  
  		public void Write (TextWriter writer)
  		{
  			serializer.Serialize (writer, this, GetNamespaceList ());
  		}
  
  		public void Write (XmlWriter writer)
  		{
  			serializer.Serialize (writer, this, GetNamespaceList ());
  		}
  
  		internal void SetParent (ServiceDescriptionCollection serviceDescriptions)
  		{
  			this.serviceDescriptions = serviceDescriptions; 
  		}
  		
  		XmlSerializerNamespaces GetNamespaceList ()
  		{
  			XmlSerializerNamespaces ns;
  			ns = new XmlSerializerNamespaces ();
  			ns.Add ("soap", SoapBinding.Namespace);
  			ns.Add ("soap12", Soap12Binding.Namespace);
  			ns.Add ("soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
  			ns.Add ("s", XmlSchema.Namespace);
  			ns.Add ("http", HttpBinding.Namespace);
  			ns.Add ("mime", MimeContentBinding.Namespace);
  
gt: 			ns.Add ("tm", MimeTextBinding.Namespace);