Parcourir la source

* DiscoveryClientProtocol.cs: In DiscoverAny, catch expection of type
DiscoveryException and rethrow the included Exception instead.
* DiscoveryReference.cs: Added BaseUri property, that returns an uri
for the reference, supporting file uris.
* ContractReference.cs: Use the new property BaseUri to build the import
uri.

svn path=/trunk/mcs/; revision=29174

Lluis Sanchez il y a 21 ans
Parent
commit
e627ca7cb6

+ 9 - 0
mcs/class/System.Web.Services/System.Web.Services.Discovery/ChangeLog

@@ -1,3 +1,12 @@
+2004-06-10  Lluis Sanchez Gual  <[email protected]>
+
+	* DiscoveryClientProtocol.cs: In DiscoverAny, catch expection of type
+	  DiscoveryException and rethrow the included Exception instead.
+	* DiscoveryReference.cs: Added BaseUri property, that returns an uri
+	  for the reference, supporting file uris.
+	* ContractReference.cs: Use the new property BaseUri to build the import
+	  uri.
+
 2004-06-01  Gert Driesen <[email protected]>
 
 	* DiscoveryReference.cs: Added missing XmlIgnore attribute.

+ 2 - 3
mcs/class/System.Web.Services/System.Web.Services.Discovery/ContractReference.cs

@@ -115,9 +115,8 @@ namespace System.Web.Services.Discovery {
 			foreach (Import import in wsdl.Imports)
 			{
 				// Make relative uris to absoulte
-				
-				Uri uri = new Uri (Url);
-				uri = new Uri (uri, import.Location);
+
+				Uri uri = new Uri (BaseUri, import.Location);
 				string url = uri.ToString ();
 
 				if (prot.Documents.Contains (url)) 	// Already resolved

+ 64 - 58
mcs/class/System.Web.Services/System.Web.Services.Discovery/DiscoveryClientProtocol.cs

@@ -76,75 +76,81 @@ namespace System.Web.Services.Discovery {
 
 		public DiscoveryDocument DiscoverAny (string url)
 		{
-			string contentType = null;
-			Stream stream = Download (ref url, ref contentType);
-
-			if (contentType.IndexOf ("text/html") != -1)
+			try
 			{
-				// Look for an alternate url
-				
-				StreamReader sr = new StreamReader (stream);
-				string str = sr.ReadToEnd ();
+				string contentType = null;
+				Stream stream = Download (ref url, ref contentType);
+	
+				if (contentType.IndexOf ("text/html") != -1)
+				{
+					// Look for an alternate url
+					
+					StreamReader sr = new StreamReader (stream);
+					string str = sr.ReadToEnd ();
+					
+					string rex = "link\\s*rel\\s*=\\s*[\"']?alternate[\"']?\\s*";
+					rex += "type\\s*=\\s*[\"']?text/xml[\"']?\\s*href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^']*)'|(?<1>\\S+))";
+					Regex rob = new Regex (rex, RegexOptions.IgnoreCase);
+					Match m = rob.Match (str);
+					if (!m.Success) 
+						throw new InvalidOperationException ("The HTML document does not contain Web service discovery information");
+					
+					if (url.StartsWith ("/"))
+					{
+						Uri uri = new Uri (url);
+						url = uri.GetLeftPart (UriPartial.Authority) + m.Groups[1];
+					}
+					else
+					{
+						int i = url.LastIndexOf ('/');
+						if (i == -1)
+							throw new InvalidOperationException ("The HTML document does not contain Web service discovery information");
+						url = url.Substring (0,i+1) + m.Groups[1];
+					}
+					stream = Download (ref url);
+				}
 				
-				string rex = "link\\s*rel\\s*=\\s*[\"']?alternate[\"']?\\s*";
-				rex += "type\\s*=\\s*[\"']?text/xml[\"']?\\s*href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^']*)'|(?<1>\\S+))";
-				Regex rob = new Regex (rex, RegexOptions.IgnoreCase);
-				Match m = rob.Match (str);
-				if (!m.Success) 
-					throw new InvalidOperationException ("The HTML document does not contain Web service discovery information");
+				XmlTextReader reader = new XmlTextReader (stream);
+				reader.MoveToContent ();
+				DiscoveryDocument doc;
+				DiscoveryReference refe = null;
 				
-				if (url.StartsWith ("/"))
+				if (DiscoveryDocument.CanRead (reader))
+				{
+					doc = DiscoveryDocument.Read (reader);
+					documents.Add (url, doc);
+					refe = new DiscoveryDocumentReference ();
+					AddDiscoReferences (doc);
+				}
+				else if (ServiceDescription.CanRead (reader))
 				{
-					Uri uri = new Uri (url);
-					url = uri.GetLeftPart (UriPartial.Authority) + m.Groups[1];
+					ServiceDescription wsdl = ServiceDescription.Read (reader);
+					documents.Add (url, wsdl);
+					doc = new DiscoveryDocument ();
+					refe = new ContractReference ();
+					doc.References.Add (refe);
+					refe.Url = url;
+					((ContractReference)refe).ResolveInternal (this, wsdl);
 				}
 				else
 				{
-					int i = url.LastIndexOf ('/');
-					if (i == -1)
-						throw new InvalidOperationException ("The HTML document does not contain Web service discovery information");
-					url = url.Substring (0,i+1) + m.Groups[1];
+					XmlSchema schema = XmlSchema.Read (reader, null);
+					documents.Add (url, schema);
+					doc = new DiscoveryDocument ();
+					refe = new SchemaReference ();
+					doc.References.Add (refe);
 				}
-				stream = Download (ref url);
-			}
-			
-			XmlTextReader reader = new XmlTextReader (stream);
-			reader.MoveToContent ();
-			DiscoveryDocument doc;
-			DiscoveryReference refe = null;
-			
-			if (DiscoveryDocument.CanRead (reader))
-			{
-				doc = DiscoveryDocument.Read (reader);
-				documents.Add (url, doc);
-				refe = new DiscoveryDocumentReference ();
-				AddDiscoReferences (doc);
-			}
-			else if (ServiceDescription.CanRead (reader))
-			{
-				ServiceDescription wsdl = ServiceDescription.Read (reader);
-				documents.Add (url, wsdl);
-				doc = new DiscoveryDocument ();
-				refe = new ContractReference ();
-				doc.References.Add (refe);
+				
+				refe.ClientProtocol = this;
 				refe.Url = url;
-				((ContractReference)refe).ResolveInternal (this, wsdl);
+				references.Add (url, refe);
+					
+				reader.Close ();
+				return doc;
 			}
-			else
-			{
-				XmlSchema schema = XmlSchema.Read (reader, null);
-				documents.Add (url, schema);
-				doc = new DiscoveryDocument ();
-				refe = new SchemaReference ();
-				doc.References.Add (refe);
+			catch (DiscoveryException ex) {
+				throw ex.Exception;
 			}
-			
-			refe.ClientProtocol = this;
-			refe.Url = url;
-			references.Add (url, refe);
-				
-			reader.Close ();
-			return doc;
 		}
 		
 		void AddDiscoReferences (DiscoveryDocument doc)

+ 12 - 0
mcs/class/System.Web.Services/System.Web.Services.Discovery/DiscoveryReference.cs

@@ -49,6 +49,18 @@ namespace System.Web.Services.Discovery {
 			set;
 		}
 		
+		internal Uri BaseUri 
+		{
+			get
+			{
+				int i = Url.IndexOf ("://");
+				if (i == -1 || !Uri.CheckSchemeName (Url.Substring (0,i)))
+					return new Uri ("file://" + Url);
+				else
+					return new Uri (Url);
+			}
+		}
+		
 		#endregion // Properties
 
 		#region Methods