(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web.Services / System.Web.Services.Description / ServiceDescription.cs
blob66729c338ab7dccfc43d4f12f03793533a8aac6a
1 //
2 // System.Web.Services.Description.ServiceDescription.cs
3 //
4 // Author:
5 // Tim Coleman (tim@timcoleman.com)
6 // Lluis Sanchez Gual (lluis@ximian.com)
7 //
8 // Copyright (C) Tim Coleman, 2002
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.IO;
33 using System.Collections;
34 using System.Reflection;
35 using System.Web.Services;
36 using System.Web.Services.Configuration;
37 using System.Xml;
38 using System.Xml.Schema;
39 using System.Xml.Serialization;
41 namespace System.Web.Services.Description
43 [XmlFormatExtensionPoint ("Extensions")]
44 [XmlRoot ("definitions", Namespace = "http://schemas.xmlsoap.org/wsdl/")]
45 public sealed class ServiceDescription :
46 #if NET_2_0
47 NamedItem
48 #else
49 DocumentableItem
50 #endif
52 #region Fields
54 public const string Namespace = "http://schemas.xmlsoap.org/wsdl/";
56 BindingCollection bindings;
57 ServiceDescriptionFormatExtensionCollection extensions;
58 ImportCollection imports;
59 MessageCollection messages;
60 #if !NET_2_0
61 string name;
62 #endif
63 PortTypeCollection portTypes;
64 string retrievalUrl;
65 ServiceDescriptionCollection serviceDescriptions;
66 ServiceCollection services;
67 string targetNamespace;
68 Types types;
69 static ServiceDescriptionSerializer serializer;
71 #endregion // Fields
73 #region Constructors
75 static ServiceDescription ()
77 serializer = new ServiceDescriptionSerializer ();
80 public ServiceDescription ()
82 bindings = new BindingCollection (this);
83 extensions = new ServiceDescriptionFormatExtensionCollection (this);
84 imports = new ImportCollection (this);
85 messages = new MessageCollection (this);
86 #if !NET_2_0
87 name = String.Empty;
88 #endif
89 portTypes = new PortTypeCollection (this);
91 serviceDescriptions = null;
92 services = new ServiceCollection (this);
93 targetNamespace = String.Empty;
94 types = null;
97 #endregion // Constructors
99 #region Properties
101 [XmlElement ("import")]
102 public ImportCollection Imports {
103 get { return imports; }
106 [XmlElement ("types")]
107 public Types Types {
108 get { return types; }
109 set { types = value; }
112 [XmlElement ("message")]
113 public MessageCollection Messages {
114 get { return messages; }
117 [XmlElement ("portType")]
118 public PortTypeCollection PortTypes {
119 get { return portTypes; }
122 [XmlElement ("binding")]
123 public BindingCollection Bindings {
124 get { return bindings; }
127 [XmlIgnore]
128 public ServiceDescriptionFormatExtensionCollection Extensions {
129 get { return extensions; }
132 #if !NET_2_0
133 [XmlAttribute ("name", DataType = "NMTOKEN")]
134 public string Name {
135 get { return name; }
136 set { name = value; }
138 #endif
140 [XmlIgnore]
141 public string RetrievalUrl {
142 get { return retrievalUrl; }
143 set { retrievalUrl = value; }
146 [XmlIgnore]
147 public static XmlSerializer Serializer {
148 get { return serializer; }
151 [XmlIgnore]
152 public ServiceDescriptionCollection ServiceDescriptions {
153 get {
154 if (serviceDescriptions == null)
155 throw new NullReferenceException ();
156 return serviceDescriptions;
160 [XmlElement ("service")]
161 public ServiceCollection Services {
162 get { return services; }
165 [XmlAttribute ("targetNamespace")]
166 public string TargetNamespace {
167 get { return targetNamespace; }
168 set { targetNamespace = value; }
171 #endregion // Properties
173 #region Methods
175 public static bool CanRead (XmlReader reader)
177 reader.MoveToContent ();
178 return reader.LocalName == "definitions" &&
179 reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/";
182 public static ServiceDescription Read (Stream stream)
184 return (ServiceDescription) serializer.Deserialize (stream);
187 public static ServiceDescription Read (string fileName)
189 return Read (new FileStream (fileName, FileMode.Open));
192 public static ServiceDescription Read (TextReader textReader)
194 return (ServiceDescription) serializer.Deserialize (textReader);
197 public static ServiceDescription Read (XmlReader reader)
199 return (ServiceDescription) serializer.Deserialize (reader);
202 public void Write (Stream stream)
204 serializer.Serialize (stream, this, GetNamespaceList ());
207 public void Write (string fileName)
209 Write (new FileStream (fileName, FileMode.Create));
212 public void Write (TextWriter writer)
214 serializer.Serialize (writer, this, GetNamespaceList ());
217 public void Write (XmlWriter writer)
219 serializer.Serialize (writer, this, GetNamespaceList ());
222 internal void SetParent (ServiceDescriptionCollection serviceDescriptions)
224 this.serviceDescriptions = serviceDescriptions;
227 XmlSerializerNamespaces GetNamespaceList ()
229 XmlSerializerNamespaces ns;
230 ns = new XmlSerializerNamespaces ();
231 ns.Add ("soap", SoapBinding.Namespace);
232 ns.Add ("soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
233 ns.Add ("s", XmlSchema.Namespace);
234 ns.Add ("http", HttpBinding.Namespace);
235 ns.Add ("mime", MimeContentBinding.Namespace);
236 ns.Add ("tm", MimeTextBinding.Namespace);
237 ns.Add ("s0", TargetNamespace);
239 AddExtensionNamespaces (ns, Extensions);
241 if (Types != null) AddExtensionNamespaces (ns, Types.Extensions);
243 foreach (Service ser in Services)
244 foreach (Port port in ser.Ports)
245 AddExtensionNamespaces (ns, port.Extensions);
247 foreach (Binding bin in Bindings)
249 AddExtensionNamespaces (ns, bin.Extensions);
250 foreach (OperationBinding op in bin.Operations)
252 AddExtensionNamespaces (ns, op.Extensions);
253 if (op.Input != null) AddExtensionNamespaces (ns, op.Input.Extensions);
254 if (op.Output != null) AddExtensionNamespaces (ns, op.Output.Extensions);
257 return ns;
260 void AddExtensionNamespaces (XmlSerializerNamespaces ns, ServiceDescriptionFormatExtensionCollection extensions)
262 foreach (ServiceDescriptionFormatExtension ext in extensions)
264 ExtensionInfo einf = ExtensionManager.GetFormatExtensionInfo (ext.GetType ());
265 foreach (XmlQualifiedName qname in einf.NamespaceDeclarations)
266 ns.Add (qname.Name, qname.Namespace);
270 internal static void WriteExtensions (XmlWriter writer, object ob)
272 ServiceDescriptionFormatExtensionCollection extensions = ExtensionManager.GetExtensionPoint (ob);
273 if (extensions != null)
275 foreach (ServiceDescriptionFormatExtension ext in extensions)
276 WriteExtension (writer, ext);
280 static void WriteExtension (XmlWriter writer, ServiceDescriptionFormatExtension ext)
282 Type type = ext.GetType ();
283 ExtensionInfo info = ExtensionManager.GetFormatExtensionInfo (type);
285 // if (prefix != null && prefix != "")
286 // Writer.WriteStartElement (prefix, info.ElementName, info.Namespace);
287 // else
288 // WriteStartElement (info.ElementName, info.Namespace, false);
290 XmlSerializerNamespaces ns = new XmlSerializerNamespaces ();
291 ns.Add ("","");
292 info.Serializer.Serialize (writer, ext, ns);
295 internal static void ReadExtension (XmlReader reader, object ob)
297 ServiceDescriptionFormatExtensionCollection extensions = ExtensionManager.GetExtensionPoint (ob);
298 if (extensions != null)
300 ExtensionInfo info = ExtensionManager.GetFormatExtensionInfo (reader.LocalName, reader.NamespaceURI);
301 if (info != null)
303 object extension = info.Serializer.Deserialize (reader);
304 extensions.Add ((ServiceDescriptionFormatExtension)extension);
305 return;
308 reader.Skip ();
312 #endregion
314 internal class ServiceDescriptionSerializer : XmlSerializer
316 protected override void Serialize (object o, XmlSerializationWriter writer)
318 ServiceDescriptionWriterBase xsWriter = writer as ServiceDescriptionWriterBase;
319 xsWriter.WriteTree ((ServiceDescription)o);
322 protected override object Deserialize (XmlSerializationReader reader)
324 ServiceDescriptionReaderBase xsReader = reader as ServiceDescriptionReaderBase;
325 return xsReader.ReadTree ();
328 protected override XmlSerializationWriter CreateWriter ()
330 return new ServiceDescriptionWriterBase ();
333 protected override XmlSerializationReader CreateReader ()
335 return new ServiceDescriptionReaderBase ();