\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