2 // System.Web.Services.Discovery.ContractReference.cs
\r
5 // Dave Bettin (javabettin@yahoo.com)
\r
6 // Lluis Sanchez Gual (lluis@ximian.com)
\r
8 // Copyright (C) Dave Bettin, 2002
\r
12 using System.Web.Services.Description;
\r
13 using System.Xml.Serialization;
\r
15 using System.Xml.Schema;
\r
17 namespace System.Web.Services.Discovery {
\r
19 [XmlRootAttribute("contractRef", Namespace="http://schemas.xmlsoap.org/disco/scl/", IsNullable=true)]
\r
20 public class ContractReference : DiscoveryReference {
\r
24 public const string Namespace = "http://schemas.xmlsoap.org/disco/scl/";
\r
26 private ServiceDescription contract;
\r
27 private string defaultFilename;
\r
28 private string docRef;
\r
29 private string href;
\r
31 #endregion // Fields
\r
33 #region Constructors
\r
35 public ContractReference ()
\r
39 public ContractReference (string href) : this()
\r
44 public ContractReference (string href, string docRef)
\r
47 this.docRef = docRef;
\r
50 #endregion // Constructors
\r
55 public ServiceDescription Contract {
\r
57 if (ClientProtocol == null)
\r
58 throw new InvalidOperationException ("The ClientProtocol property is a null reference");
\r
60 ServiceDescription desc = ClientProtocol.Documents [Url] as ServiceDescription;
\r
62 throw new Exception ("The Documents property of ClientProtocol does not contain a WSDL document with the url " + Url);
\r
69 public override string DefaultFilename {
\r
70 get { return FilenameFromUrl (Url) + ".wsdl"; }
\r
73 [XmlAttribute("docRef")]
\r
74 public string DocRef {
\r
75 get { return docRef; }
\r
76 set { docRef = value; }
\r
79 [XmlAttribute("ref")]
\r
81 get { return href; }
\r
82 set { href = value; }
\r
86 public override string Url {
\r
87 get { return href;}
\r
88 set { href = value; }
\r
91 #endregion // Properties
\r
95 public override object ReadDocument (Stream stream)
\r
97 return ServiceDescription.Read (stream);
\r
100 protected internal override void Resolve (string contentType, Stream stream)
\r
102 ServiceDescription wsdl = ServiceDescription.Read (stream);
\r
104 if (!ClientProtocol.References.Contains (Url))
\r
105 ClientProtocol.References.Add (this);
\r
107 ClientProtocol.Documents.Add (Url, wsdl);
\r
108 ResolveInternal (ClientProtocol, wsdl);
\r
111 internal void ResolveInternal (DiscoveryClientProtocol prot, ServiceDescription wsdl)
\r
113 if (wsdl.Imports == null) return;
\r
115 foreach (Import import in wsdl.Imports)
\r
117 if (prot.Documents.Contains (import.Location)) // Already resolved
\r
120 string url = import.Location;
\r
121 string contentType = null;
\r
122 Stream stream = prot.Download (ref url, ref contentType);
\r
123 XmlTextReader reader = new XmlTextReader (stream);
\r
124 reader.MoveToContent ();
\r
126 DiscoveryReference refe;
\r
127 if (ServiceDescription.CanRead (reader))
\r
129 ServiceDescription refWsdl = ServiceDescription.Read (reader);
\r
130 refe = new ContractReference ();
\r
131 refe.ClientProtocol = prot;
\r
133 ((ContractReference)refe).ResolveInternal (prot, refWsdl);
\r
134 prot.Documents.Add (url, refWsdl);
\r
138 XmlSchema schema = XmlSchema.Read (reader, null);
\r
139 refe = new SchemaReference ();
\r
140 refe.ClientProtocol = prot;
\r
142 prot.Documents.Add (url, schema);
\r
145 if (!prot.References.Contains (url))
\r
146 prot.References.Add (refe);
\r
152 public override void WriteDocument (object document, Stream stream)
\r
154 ((ServiceDescription)document).Write (stream);
\r
157 #endregion // Methods
\r