* DiscoveryClientProtocol.cs: In DiscoverAny, catch expection of type
authorLluis Sanchez <lluis@novell.com>
Thu, 10 Jun 2004 09:07:24 +0000 (09:07 -0000)
committerLluis Sanchez <lluis@novell.com>
Thu, 10 Jun 2004 09:07:24 +0000 (09:07 -0000)
  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

mcs/class/System.Web.Services/System.Web.Services.Discovery/ChangeLog
mcs/class/System.Web.Services/System.Web.Services.Discovery/ContractReference.cs
mcs/class/System.Web.Services/System.Web.Services.Discovery/DiscoveryClientProtocol.cs
mcs/class/System.Web.Services/System.Web.Services.Discovery/DiscoveryReference.cs

index 79a54ce4db534eef62af3ca74c5bb1f580e03715..76b0904ded59e2dccf6626e724606f0db6275579 100755 (executable)
@@ -1,3 +1,12 @@
+2004-06-10  Lluis Sanchez Gual  <lluis@ximian.com>
+
+       * 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 <drieseng@users.sourceforge.net>
 
        * DiscoveryReference.cs: Added missing XmlIgnore attribute.
index be4eba9c1d84bec43469e84727ea3264d74e1667..2e19fcb3d4a244d2ac150aaf31a73aae43c564cc 100755 (executable)
@@ -115,9 +115,8 @@ namespace System.Web.Services.Discovery {
                        foreach (Import import in wsdl.Imports)\r
                        {\r
                                // Make relative uris to absoulte\r
-                               \r
-                               Uri uri = new Uri (Url);\r
-                               uri = new Uri (uri, import.Location);\r
+\r
+                               Uri uri = new Uri (BaseUri, import.Location);\r
                                string url = uri.ToString ();\r
 \r
                                if (prot.Documents.Contains (url))      // Already resolved\r
index 6546ffa21a11f590087d9aad02f365bafc70932d..f49f2ec3bfd3cc76fed8068a1d691c57533cb797 100755 (executable)
@@ -76,75 +76,81 @@ namespace System.Web.Services.Discovery {
 \r
                public DiscoveryDocument DiscoverAny (string url)\r
                {\r
-                       string contentType = null;\r
-                       Stream stream = Download (ref url, ref contentType);\r
-\r
-                       if (contentType.IndexOf ("text/html") != -1)\r
+                       try\r
                        {\r
-                               // Look for an alternate url\r
-                               \r
-                               StreamReader sr = new StreamReader (stream);\r
-                               string str = sr.ReadToEnd ();\r
+                               string contentType = null;\r
+                               Stream stream = Download (ref url, ref contentType);\r
+       \r
+                               if (contentType.IndexOf ("text/html") != -1)\r
+                               {\r
+                                       // Look for an alternate url\r
+                                       \r
+                                       StreamReader sr = new StreamReader (stream);\r
+                                       string str = sr.ReadToEnd ();\r
+                                       \r
+                                       string rex = "link\\s*rel\\s*=\\s*[\"']?alternate[\"']?\\s*";\r
+                                       rex += "type\\s*=\\s*[\"']?text/xml[\"']?\\s*href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^']*)'|(?<1>\\S+))";\r
+                                       Regex rob = new Regex (rex, RegexOptions.IgnoreCase);\r
+                                       Match m = rob.Match (str);\r
+                                       if (!m.Success) \r
+                                               throw new InvalidOperationException ("The HTML document does not contain Web service discovery information");\r
+                                       \r
+                                       if (url.StartsWith ("/"))\r
+                                       {\r
+                                               Uri uri = new Uri (url);\r
+                                               url = uri.GetLeftPart (UriPartial.Authority) + m.Groups[1];\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               int i = url.LastIndexOf ('/');\r
+                                               if (i == -1)\r
+                                                       throw new InvalidOperationException ("The HTML document does not contain Web service discovery information");\r
+                                               url = url.Substring (0,i+1) + m.Groups[1];\r
+                                       }\r
+                                       stream = Download (ref url);\r
+                               }\r
                                \r
-                               string rex = "link\\s*rel\\s*=\\s*[\"']?alternate[\"']?\\s*";\r
-                               rex += "type\\s*=\\s*[\"']?text/xml[\"']?\\s*href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^']*)'|(?<1>\\S+))";\r
-                               Regex rob = new Regex (rex, RegexOptions.IgnoreCase);\r
-                               Match m = rob.Match (str);\r
-                               if (!m.Success) \r
-                                       throw new InvalidOperationException ("The HTML document does not contain Web service discovery information");\r
+                               XmlTextReader reader = new XmlTextReader (stream);\r
+                               reader.MoveToContent ();\r
+                               DiscoveryDocument doc;\r
+                               DiscoveryReference refe = null;\r
                                \r
-                               if (url.StartsWith ("/"))\r
+                               if (DiscoveryDocument.CanRead (reader))\r
+                               {\r
+                                       doc = DiscoveryDocument.Read (reader);\r
+                                       documents.Add (url, doc);\r
+                                       refe = new DiscoveryDocumentReference ();\r
+                                       AddDiscoReferences (doc);\r
+                               }\r
+                               else if (ServiceDescription.CanRead (reader))\r
                                {\r
-                                       Uri uri = new Uri (url);\r
-                                       url = uri.GetLeftPart (UriPartial.Authority) + m.Groups[1];\r
+                                       ServiceDescription wsdl = ServiceDescription.Read (reader);\r
+                                       documents.Add (url, wsdl);\r
+                                       doc = new DiscoveryDocument ();\r
+                                       refe = new ContractReference ();\r
+                                       doc.References.Add (refe);\r
+                                       refe.Url = url;\r
+                                       ((ContractReference)refe).ResolveInternal (this, wsdl);\r
                                }\r
                                else\r
                                {\r
-                                       int i = url.LastIndexOf ('/');\r
-                                       if (i == -1)\r
-                                               throw new InvalidOperationException ("The HTML document does not contain Web service discovery information");\r
-                                       url = url.Substring (0,i+1) + m.Groups[1];\r
+                                       XmlSchema schema = XmlSchema.Read (reader, null);\r
+                                       documents.Add (url, schema);\r
+                                       doc = new DiscoveryDocument ();\r
+                                       refe = new SchemaReference ();\r
+                                       doc.References.Add (refe);\r
                                }\r
-                               stream = Download (ref url);\r
-                       }\r
-                       \r
-                       XmlTextReader reader = new XmlTextReader (stream);\r
-                       reader.MoveToContent ();\r
-                       DiscoveryDocument doc;\r
-                       DiscoveryReference refe = null;\r
-                       \r
-                       if (DiscoveryDocument.CanRead (reader))\r
-                       {\r
-                               doc = DiscoveryDocument.Read (reader);\r
-                               documents.Add (url, doc);\r
-                               refe = new DiscoveryDocumentReference ();\r
-                               AddDiscoReferences (doc);\r
-                       }\r
-                       else if (ServiceDescription.CanRead (reader))\r
-                       {\r
-                               ServiceDescription wsdl = ServiceDescription.Read (reader);\r
-                               documents.Add (url, wsdl);\r
-                               doc = new DiscoveryDocument ();\r
-                               refe = new ContractReference ();\r
-                               doc.References.Add (refe);\r
+                               \r
+                               refe.ClientProtocol = this;\r
                                refe.Url = url;\r
-                               ((ContractReference)refe).ResolveInternal (this, wsdl);\r
+                               references.Add (url, refe);\r
+                                       \r
+                               reader.Close ();\r
+                               return doc;\r
                        }\r
-                       else\r
-                       {\r
-                               XmlSchema schema = XmlSchema.Read (reader, null);\r
-                               documents.Add (url, schema);\r
-                               doc = new DiscoveryDocument ();\r
-                               refe = new SchemaReference ();\r
-                               doc.References.Add (refe);\r
+                       catch (DiscoveryException ex) {\r
+                               throw ex.Exception;\r
                        }\r
-                       \r
-                       refe.ClientProtocol = this;\r
-                       refe.Url = url;\r
-                       references.Add (url, refe);\r
-                               \r
-                       reader.Close ();\r
-                       return doc;\r
                }\r
                \r
                void AddDiscoReferences (DiscoveryDocument doc)\r
index a5ab440db1913151727f4ad58c50d527231bff61..e8f0fa224337fd4ed34369282cf7951d4d82220e 100755 (executable)
@@ -49,6 +49,18 @@ namespace System.Web.Services.Discovery {
                        set;\r
                }\r
                \r
+               internal Uri BaseUri \r
+               {\r
+                       get\r
+                       {\r
+                               int i = Url.IndexOf ("://");\r
+                               if (i == -1 || !Uri.CheckSchemeName (Url.Substring (0,i)))\r
+                                       return new Uri ("file://" + Url);\r
+                               else\r
+                                       return new Uri (Url);\r
+                       }\r
+               }\r
+               \r
                #endregion // Properties\r
 \r
                #region Methods\r