void GetFiles (string baseUrl, string relPath, string path, DiscoveryDocument doc, DynamicDiscoveryDocument ddoc) { string url = baseUrl + relPath; if (!url.EndsWith ("/")) url += "/"; string[] files = Directory.GetFiles (path); foreach (string file in files) { string ext = Path.GetExtension (file).ToLower(); if (ext == ".asmx") { ContractReference cref = new ContractReference (); cref.DocRef = url + Path.GetFileName (file); cref.Ref = cref.DocRef + "?wsdl"; doc.References.Add (cref); } else if (ext == ".disco") { DiscoveryDocumentReference dref = new DiscoveryDocumentReference (); dref.Ref = url + Path.GetFileName (file); doc.References.Add (dref); } } string[] dirs = Directory.GetDirectories (path); foreach (string dir in dirs) { string rel = Path.Combine (relPath, Path.GetFileName(dir)); if (!ddoc.IsExcluded (rel)) GetFiles (baseUrl, rel, Path.Combine (path, dir), doc, ddoc); } }
/// <summary>Generate a text description for the a DiscoverDocument.</summary> /// <param name="discovery">A DiscoveryDocument containing the details for the disco services.</param> /// <returns>An XmlDocument containing the generated xml for the specified discovery document.</returns> public static void GenerateDiscoXml (StringBuilder text, DiscoveryDocument doc) { text.Append ("<big><b>" + GettextCatalog.GetString ("Web Service References") + "</b></big>\n\n"); foreach (object oref in doc.References) { DiscoveryReference dref = oref as DiscoveryReference; if (dref == null) continue; if (dref is ContractReference) { text.AppendFormat ("<b>Service: {0}</b>\n<span size='small'>{1}</span>", System.IO.Path.GetFileNameWithoutExtension (dref.DefaultFilename), dref.Url); } else if (dref is DiscoveryDocumentReference) { text.AppendFormat ("<b>Discovery document</b>\n<small>{0}</small>", dref.Url); } text.Append ("\n\n"); } }
public void ProcessRequest (HttpContext context) { string path = context.Request.PhysicalPath; FileStream fs = new FileStream (path, FileMode.Open); DynamicDiscoveryDocument ddoc = DynamicDiscoveryDocument.Load (fs); fs.Close (); string url = context.Request.Url.ToString(); int i = url.LastIndexOf ('/'); if (i != -1) url = url.Substring (0,i+1); DiscoveryDocument doc = new DiscoveryDocument (); GetFiles (url, "", Path.GetDirectoryName(path), doc, ddoc); context.Response.ContentType = "text/xml; charset=utf-8"; doc.Write (context.Response.OutputStream); }
public DiscoveryDocument Discover(string url) { Stream stream = Download(ref url); XmlTextReader reader = new XmlTextReader(url, stream); reader.XmlResolver = null; if (!DiscoveryDocument.CanRead(reader)) { throw new InvalidOperationException("The url '" + url + "' does not point to a valid discovery document"); } DiscoveryDocument doc = DiscoveryDocument.Read(reader); reader.Close(); documents.Add(url, doc); AddDiscoReferences(doc); return(doc); }
public DiscoveryDocument Discover(string url) { DiscoveryDocument doc = Documents[url] as DiscoveryDocument; if (doc != null) { return(doc); } DiscoveryDocumentReference docRef = new DiscoveryDocumentReference(url); docRef.ClientProtocol = this; References[url] = docRef; Errors.Clear(); // this will auto-resolve and place the document in the Documents hashtable. return(docRef.Document); }
internal DiscoveryServerType(Type type, string uri) : base(typeof(DiscoveryServerProtocol)) { this.schemaTable = new Hashtable(); this.wsdlTable = new Hashtable(); uri = new Uri(uri, true).GetLeftPart(UriPartial.Path); this.methodInfo = new LogicalMethodInfo(typeof(DiscoveryServerProtocol).GetMethod("Discover", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)); ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(); reflector.Reflect(type, uri); XmlSchemas schemas = reflector.Schemas; this.description = reflector.ServiceDescription; XmlSerializer serializer = ServiceDescription.Serializer; this.AddSchemaImports(schemas, uri, reflector.ServiceDescriptions); for (int i = 1; i < reflector.ServiceDescriptions.Count; i++) { ServiceDescription description = reflector.ServiceDescriptions[i]; Import import = new Import { Namespace = description.TargetNamespace }; string key = "wsdl" + i.ToString(CultureInfo.InvariantCulture); import.Location = uri + "?wsdl=" + key; reflector.ServiceDescription.Imports.Add(import); this.wsdlTable.Add(key, description); } this.discoDoc = new DiscoveryDocument(); this.discoDoc.References.Add(new ContractReference(uri + "?wsdl", uri)); foreach (Service service in reflector.ServiceDescription.Services) { foreach (Port port in service.Ports) { SoapAddressBinding binding = (SoapAddressBinding) port.Extensions.Find(typeof(SoapAddressBinding)); if (binding != null) { System.Web.Services.Discovery.SoapBinding binding2 = new System.Web.Services.Discovery.SoapBinding { Binding = port.Binding, Address = binding.Location }; this.discoDoc.References.Add(binding2); } } } }
void GetFiles(string baseUrl, string relPath, string path, DiscoveryDocument doc, DynamicDiscoveryDocument ddoc) { string url = baseUrl + relPath; if (!url.EndsWith("/")) { url += "/"; } string[] files = Directory.GetFiles(path); foreach (string file in files) { string ext = Path.GetExtension(file).ToLower(); if (ext == ".asmx") { ContractReference cref = new ContractReference(); cref.DocRef = url + Path.GetFileName(file); cref.Ref = cref.DocRef + "?wsdl"; doc.References.Add(cref); } else if (ext == ".disco") { DiscoveryDocumentReference dref = new DiscoveryDocumentReference(); dref.Ref = url + Path.GetFileName(file); doc.References.Add(dref); } } string[] dirs = Directory.GetDirectories(path); foreach (string dir in dirs) { string rel = Path.Combine(relPath, Path.GetFileName(dir)); if (!ddoc.IsExcluded(rel)) { GetFiles(baseUrl, rel, Path.Combine(path, dir), doc, ddoc); } } }
public void ProcessRequest(HttpContext context) { string path = context.Request.PhysicalPath; FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); DynamicDiscoveryDocument ddoc = DynamicDiscoveryDocument.Load(fs); fs.Close(); string url = context.Request.Url.ToString(); int i = url.LastIndexOf('/'); if (i != -1) { url = url.Substring(0, i + 1); } DiscoveryDocument doc = new DiscoveryDocument(); GetFiles(url, "", Path.GetDirectoryName(path), doc, ddoc); context.Response.ContentType = "text/xml; charset=utf-8"; doc.Write(context.Response.OutputStream); }
internal MetadataContent(Discovery.DiscoveryDocument discoveryDocument) { m_MetadataDiscoveryDocument = discoveryDocument; m_TargetNamespace = String.Empty; }
/// <include file='doc\DiscoveryDocumentReference.uex' path='docs/doc[@for="DiscoveryDocumentReference.Resolve"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> protected internal override void Resolve(string contentType, Stream stream) { DiscoveryDocument document = null; if (ContentType.IsHtml(contentType)) { string newRef = LinkGrep.SearchForLink(stream); if (newRef != null) { string newUrl = UriToString(Url, newRef); document = GetDocumentNoParse(ref newUrl, ClientProtocol); Url = newUrl; } else { throw new InvalidContentTypeException(Res.GetString(Res.WebInvalidContentType, contentType), contentType); } } if (document == null) // probably xml... { XmlTextReader reader = new XmlTextReader(new StreamReader(stream, RequestResponseUtils.GetEncoding(contentType))); reader.XmlResolver = null; reader.WhitespaceHandling = WhitespaceHandling.Significant; reader.DtdProcessing = DtdProcessing.Prohibit; if (DiscoveryDocument.CanRead(reader)) { // it's a discovery document, so just read it. document = DiscoveryDocument.Read(reader); } else { // check out the processing instructions before the first tag. if any of them // match the form specified in the DISCO spec, save the href. stream.Position = 0; XmlTextReader newReader = new XmlTextReader(new StreamReader(stream, RequestResponseUtils.GetEncoding(contentType))); newReader.XmlResolver = null; newReader.DtdProcessing = DtdProcessing.Prohibit; while (newReader.NodeType != XmlNodeType.Element) { if (newReader.NodeType == XmlNodeType.ProcessingInstruction) { // manually parse the PI contents since XmlTextReader won't automatically do it StringBuilder sb = new StringBuilder("<pi "); sb.Append(newReader.Value); sb.Append("/>"); XmlTextReader piReader = new XmlTextReader(new StringReader(sb.ToString())); piReader.XmlResolver = null; piReader.DtdProcessing = DtdProcessing.Prohibit; piReader.Read(); string type = piReader["type"]; string alternate = piReader["alternate"]; string href = piReader["href"]; if (type != null && ContentType.MatchesBase(type, ContentType.TextXml) && alternate != null && string.Compare(alternate, "yes", StringComparison.OrdinalIgnoreCase) == 0 && href != null) { // we got a PI with the right attributes // there is a link to a discovery document. follow it after fully qualifying it. string newUrl = UriToString(Url, href); document = GetDocumentNoParse(ref newUrl, ClientProtocol); Url = newUrl; break; } } newReader.Read(); } } } if (document == null) { // there is no discovery document at this location Exception exception; if (ContentType.IsXml(contentType)) { exception = new ArgumentException(Res.GetString(Res.WebInvalidFormat)); } else { exception = new InvalidContentTypeException(Res.GetString(Res.WebInvalidContentType, contentType), contentType); } throw new InvalidOperationException(Res.GetString(Res.WebMissingDocument, Url), exception); } ClientProtocol.References[Url] = this; ClientProtocol.Documents[Url] = document; foreach (object o in document.References) { if (o is DiscoveryReference) { DiscoveryReference r = (DiscoveryReference)o; if (r.Url.Length == 0) { throw new InvalidOperationException(Res.GetString(Res.WebEmptyRef, r.GetType().FullName, Url)); } r.Url = UriToString(Url, r.Url); //All inheritors of DiscoveryReference that got URIs relative //to Ref property should adjust them like ContractReference does here. ContractReference cr = r as ContractReference; if ((cr != null) && (cr.DocRef != null)) { cr.DocRef = UriToString(Url, cr.DocRef); } r.ClientProtocol = ClientProtocol; ClientProtocol.References[r.Url] = r; } else { ClientProtocol.AdditionalInformation.Add(o); } } return; }
protected internal override void Resolve(string contentType, Stream stream) { DiscoveryDocument documentNoParse = null; if (ContentType.IsHtml(contentType)) { string relUrl = LinkGrep.SearchForLink(stream); if (relUrl == null) { throw new InvalidContentTypeException(System.Web.Services.Res.GetString("WebInvalidContentType", new object[] { contentType }), contentType); } string url = DiscoveryReference.UriToString(this.Url, relUrl); documentNoParse = GetDocumentNoParse(ref url, base.ClientProtocol); this.Url = url; } if (documentNoParse == null) { XmlTextReader xmlReader = new XmlTextReader(new StreamReader(stream, RequestResponseUtils.GetEncoding(contentType))) { XmlResolver = null, WhitespaceHandling = WhitespaceHandling.Significant, DtdProcessing = DtdProcessing.Prohibit }; if (DiscoveryDocument.CanRead(xmlReader)) { documentNoParse = DiscoveryDocument.Read(xmlReader); } else { stream.Position = 0L; XmlTextReader reader2 = new XmlTextReader(new StreamReader(stream, RequestResponseUtils.GetEncoding(contentType))) { XmlResolver = null, DtdProcessing = DtdProcessing.Prohibit }; while (reader2.NodeType != XmlNodeType.Element) { if (reader2.NodeType == XmlNodeType.ProcessingInstruction) { StringBuilder builder = new StringBuilder("<pi "); builder.Append(reader2.Value); builder.Append("/>"); XmlTextReader reader3 = new XmlTextReader(new StringReader(builder.ToString())) { XmlResolver = null, DtdProcessing = DtdProcessing.Prohibit }; reader3.Read(); string str3 = reader3["type"]; string strA = reader3["alternate"]; string str5 = reader3["href"]; if ((((str3 != null) && ContentType.MatchesBase(str3, "text/xml")) && ((strA != null) && (string.Compare(strA, "yes", StringComparison.OrdinalIgnoreCase) == 0))) && (str5 != null)) { string str6 = DiscoveryReference.UriToString(this.Url, str5); documentNoParse = GetDocumentNoParse(ref str6, base.ClientProtocol); this.Url = str6; break; } } reader2.Read(); } } } if (documentNoParse == null) { Exception exception; if (ContentType.IsXml(contentType)) { exception = new ArgumentException(System.Web.Services.Res.GetString("WebInvalidFormat")); } else { exception = new InvalidContentTypeException(System.Web.Services.Res.GetString("WebInvalidContentType", new object[] { contentType }), contentType); } throw new InvalidOperationException(System.Web.Services.Res.GetString("WebMissingDocument", new object[] { this.Url }), exception); } base.ClientProtocol.References[this.Url] = this; base.ClientProtocol.Documents[this.Url] = documentNoParse; foreach (object obj2 in documentNoParse.References) { if (obj2 is DiscoveryReference) { DiscoveryReference reference = (DiscoveryReference)obj2; if (reference.Url.Length == 0) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebEmptyRef", new object[] { reference.GetType().FullName, this.Url })); } reference.Url = DiscoveryReference.UriToString(this.Url, reference.Url); ContractReference reference2 = reference as ContractReference; if ((reference2 != null) && (reference2.DocRef != null)) { reference2.DocRef = DiscoveryReference.UriToString(this.Url, reference2.DocRef); } reference.ClientProtocol = base.ClientProtocol; base.ClientProtocol.References[reference.Url] = reference; } else { base.ClientProtocol.AdditionalInformation.Add(obj2); } } }
public DiscoveryDocument DiscoverAny (string url) { try { 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"); Uri tmp = new Uri (url); tmp = new Uri (tmp, m.Groups [1].ToString ()); url = tmp.ToString (); } stream = Download (ref url); } XmlTextReader reader = new XmlTextReader (url, stream); reader.XmlResolver = null; reader.MoveToContent (); DiscoveryDocument doc; DiscoveryReference refe = null; if (DiscoveryDocument.CanRead (reader)) { doc = DiscoveryDocument.Read (reader); documents.Add (url, doc); refe = new DiscoveryDocumentReference (); AddDiscoReferences (doc); } #if !MONOTOUCH 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.Url = url; ((ContractReference)refe).ResolveInternal (this, wsdl); } #endif else { XmlSchema schema = XmlSchema.Read (reader, null); documents.Add (url, schema); doc = new DiscoveryDocument (); refe = new SchemaReference (); refe.Url = url; ((SchemaReference)refe).ResolveInternal (this, schema); doc.References.Add (refe); } refe.ClientProtocol = this; refe.Url = url; references.Add (url, refe); reader.Close (); return doc; } catch (DiscoveryException ex) { throw ex.Exception; } }
public DiscoveryDocument DiscoverAny(string url) { Type[] refTypes = WebServicesSection.Current.DiscoveryReferenceTypes; DiscoveryReference discoRef = null; string contentType = null; Stream stream = Download(ref url, ref contentType); Errors.Clear(); bool allErrorsAreHtmlContentType = true; Exception errorInValidDocument = null; ArrayList specialErrorMessages = new ArrayList(); foreach (Type type in refTypes) { if (!typeof(DiscoveryReference).IsAssignableFrom(type)) continue; discoRef = (DiscoveryReference) Activator.CreateInstance(type); discoRef.Url = url; discoRef.ClientProtocol = this; stream.Position = 0; Exception e = discoRef.AttemptResolve(contentType, stream); if (e == null) break; Errors[type.FullName] = e; discoRef = null; InvalidContentTypeException e2 = e as InvalidContentTypeException; if (e2 == null || !ContentType.MatchesBase(e2.ContentType, "text/html")) allErrorsAreHtmlContentType = false; InvalidDocumentContentsException e3 = e as InvalidDocumentContentsException; if (e3 != null) { errorInValidDocument = e; break; } if (e.InnerException != null && e.InnerException.InnerException == null) specialErrorMessages.Add(e.InnerException.Message); } if (discoRef == null) { if (errorInValidDocument != null) { StringBuilder errorMessage = new StringBuilder(Res.GetString(Res.TheDocumentWasUnderstoodButContainsErrors)); while (errorInValidDocument != null) { errorMessage.Append("\n - ").Append(errorInValidDocument.Message); errorInValidDocument = errorInValidDocument.InnerException; } throw new InvalidOperationException(errorMessage.ToString()); } else if (allErrorsAreHtmlContentType) { throw new InvalidOperationException(Res.GetString(Res.TheHTMLDocumentDoesNotContainDiscoveryInformation)); } else { bool same = specialErrorMessages.Count == Errors.Count && Errors.Count > 0; for (int i = 1; same && i < specialErrorMessages.Count; i++) { if ((string) specialErrorMessages[i - 1] != (string) specialErrorMessages[i]) same = false; } if (same) throw new InvalidOperationException(Res.GetString(Res.TheDocumentWasNotRecognizedAsAKnownDocumentType, specialErrorMessages[0])); else { Exception e; StringBuilder errorMessage = new StringBuilder(Res.GetString(Res.WebMissingResource, url)); foreach (DictionaryEntry entry in Errors) { e = (Exception)(entry.Value); string refType = (string)(entry.Key); if (0 == string.Compare(refType, typeof(ContractReference).FullName, StringComparison.Ordinal)) { refType = Res.GetString(Res.WebContractReferenceName); } else if (0 == string.Compare(refType, typeof(SchemaReference).FullName, StringComparison.Ordinal)) { refType = Res.GetString(Res.WebShemaReferenceName); } else if (0 == string.Compare(refType, typeof(DiscoveryDocumentReference).FullName, StringComparison.Ordinal)) { refType = Res.GetString(Res.WebDiscoveryDocumentReferenceName); } errorMessage.Append("\n- ").Append(Res.GetString(Res.WebDiscoRefReport, refType, e.Message)); while (e.InnerException != null) { errorMessage.Append("\n - ").Append(e.InnerException.Message); e = e.InnerException; } } throw new InvalidOperationException(errorMessage.ToString()); } } } if (discoRef is DiscoveryDocumentReference) return ((DiscoveryDocumentReference) discoRef).Document; References[discoRef.Url] = discoRef; DiscoveryDocument doc = new DiscoveryDocument(); doc.References.Add(discoRef); return doc; }
/// <include file='doc\DiscoveryRequestHandler.uex' path='docs/doc[@for="DiscoveryRequestHandler.ProcessRequest"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void ProcessRequest(HttpContext context) { TraceMethod method = Tracing.On ? new TraceMethod(this, "ProcessRequest") : null; if (Tracing.On) { Tracing.Enter("IHttpHandler.ProcessRequest", method, Tracing.Details(context.Request)); } new PermissionSet(PermissionState.Unrestricted).Demand(); // string cacheKey; string physicalPath = context.Request.PhysicalPath; if (CompModSwitches.DynamicDiscoverySearcher.TraceVerbose) { Debug.WriteLine("DiscoveryRequestHandle: handling " + physicalPath); } // Check to see if file exists locally. if (File.Exists(physicalPath)) { DynamicDiscoveryDocument dynDisco = null; FileStream stream = null; try { stream = new FileStream(physicalPath, FileMode.Open, FileAccess.Read); XmlTextReader xmlReader = new XmlTextReader(stream); xmlReader.WhitespaceHandling = WhitespaceHandling.Significant; xmlReader.XmlResolver = null; xmlReader.DtdProcessing = DtdProcessing.Prohibit; if (xmlReader.IsStartElement("dynamicDiscovery", DynamicDiscoveryDocument.Namespace)) { stream.Position = 0; dynDisco = DynamicDiscoveryDocument.Load(stream); } } finally { if (stream != null) { stream.Close(); } } if (dynDisco != null) { string[] excludeList = new string[dynDisco.ExcludePaths.Length]; string discoFileDirectory = Path.GetDirectoryName(physicalPath); string discoFileName = Path.GetFileName(physicalPath); for (int i = 0; i < excludeList.Length; i++) { // Exclude list now consists of relative paths, so this transformation not needed. // excludeList[i] = Path.Combine(discoFileDirectory, dynDisco.ExcludePaths[i].Path); excludeList[i] = dynDisco.ExcludePaths[i].Path; } // Determine start url path for search DynamicDiscoSearcher searcher; Uri searchStartUrl = context.Request.Url; string escapedUri = RuntimeUtils.EscapeUri(searchStartUrl); string searchStartUrlDir = GetDirPartOfPath(escapedUri); // URL path without file name string strLocalPath = GetDirPartOfPath(searchStartUrl.LocalPath); if (strLocalPath.Length == 0 || // no subdir present, host only CompModSwitches.DynamicDiscoveryVirtualSearch.Enabled // virtual search forced (for test suites). ) { discoFileName = GetFilePartOfPath(escapedUri); searcher = new DynamicVirtualDiscoSearcher(discoFileDirectory, excludeList, searchStartUrlDir); } else { searcher = new DynamicPhysicalDiscoSearcher(discoFileDirectory, excludeList, searchStartUrlDir); } if (CompModSwitches.DynamicDiscoverySearcher.TraceVerbose) { Debug.WriteLine("*** DiscoveryRequestHandler.ProcessRequest() - startDir: " + searchStartUrlDir + " discoFileName :" + discoFileName); } searcher.Search(discoFileName); DiscoveryDocument discoFile = searcher.DiscoveryDocument; MemoryStream memStream = new MemoryStream(1024); StreamWriter writer = new StreamWriter(memStream, new UTF8Encoding(false)); discoFile.Write(writer); memStream.Position = 0; byte[] data = new byte[(int)memStream.Length]; int bytesRead = memStream.Read(data, 0, data.Length); context.Response.ContentType = ContentType.Compose("text/xml", Encoding.UTF8); context.Response.OutputStream.Write(data, 0, bytesRead); } else { // Else, just return the disco file context.Response.ContentType = "text/xml"; context.Response.WriteFile(physicalPath); } if (Tracing.On) { Tracing.Exit("IHttpHandler.ProcessRequest", method); } return; } if (Tracing.On) { Tracing.Exit("IHttpHandler.ProcessRequest", method); } // Else, file is not found throw new HttpException(404, Res.GetString(Res.WebPathNotFound, context.Request.Path)); }
public DiscoveryDocument DiscoverAny(string url) { Type[] discoveryReferenceTypes = WebServicesSection.Current.DiscoveryReferenceTypes; DiscoveryReference reference = null; string contentType = null; Stream stream = this.Download(ref url, ref contentType); this.Errors.Clear(); bool flag = true; Exception innerException = null; ArrayList list = new ArrayList(); foreach (Type type in discoveryReferenceTypes) { if (typeof(DiscoveryReference).IsAssignableFrom(type)) { reference = (DiscoveryReference) Activator.CreateInstance(type); reference.Url = url; reference.ClientProtocol = this; stream.Position = 0L; Exception exception2 = reference.AttemptResolve(contentType, stream); if (exception2 == null) { break; } this.Errors[type.FullName] = exception2; reference = null; InvalidContentTypeException exception3 = exception2 as InvalidContentTypeException; if ((exception3 == null) || !ContentType.MatchesBase(exception3.ContentType, "text/html")) { flag = false; } if (exception2 is InvalidDocumentContentsException) { innerException = exception2; break; } if ((exception2.InnerException != null) && (exception2.InnerException.InnerException == null)) { list.Add(exception2.InnerException.Message); } } } if (reference == null) { if (innerException != null) { StringBuilder builder = new StringBuilder(Res.GetString("TheDocumentWasUnderstoodButContainsErrors")); while (innerException != null) { builder.Append("\n - ").Append(innerException.Message); innerException = innerException.InnerException; } throw new InvalidOperationException(builder.ToString()); } if (flag) { throw new InvalidOperationException(Res.GetString("TheHTMLDocumentDoesNotContainDiscoveryInformation")); } bool flag2 = (list.Count == this.Errors.Count) && (this.Errors.Count > 0); for (int i = 1; flag2 && (i < list.Count); i++) { if (((string) list[i - 1]) != ((string) list[i])) { flag2 = false; } } if (flag2) { throw new InvalidOperationException(Res.GetString("TheDocumentWasNotRecognizedAsAKnownDocumentType", new object[] { list[0] })); } StringBuilder builder2 = new StringBuilder(Res.GetString("WebMissingResource", new object[] { url })); foreach (DictionaryEntry entry in this.Errors) { Exception exception5 = (Exception) entry.Value; string key = (string) entry.Key; if (string.Compare(key, typeof(ContractReference).FullName, StringComparison.Ordinal) == 0) { key = Res.GetString("WebContractReferenceName"); } else if (string.Compare(key, typeof(SchemaReference).FullName, StringComparison.Ordinal) == 0) { key = Res.GetString("WebShemaReferenceName"); } else if (string.Compare(key, typeof(DiscoveryDocumentReference).FullName, StringComparison.Ordinal) == 0) { key = Res.GetString("WebDiscoveryDocumentReferenceName"); } builder2.Append("\n- ").Append(Res.GetString("WebDiscoRefReport", new object[] { key, exception5.Message })); while (exception5.InnerException != null) { builder2.Append("\n - ").Append(exception5.InnerException.Message); exception5 = exception5.InnerException; } } throw new InvalidOperationException(builder2.ToString()); } if (reference is DiscoveryDocumentReference) { return ((DiscoveryDocumentReference) reference).Document; } this.References[reference.Url] = reference; DiscoveryDocument document = new DiscoveryDocument(); document.References.Add(reference); return document; }
// See comment on the ServerProtocol.IsCacheUnderPressure method for explanation of the excludeSchemeHostPortFromCachingKey logic. internal DiscoveryServerType(Type type, string uri, bool excludeSchemeHostPortFromCachingKey) : base(typeof(DiscoveryServerProtocol)) { if (excludeSchemeHostPortFromCachingKey) { this.UriFixups = new List<Action<Uri>>(); } // // parse the uri from a string into a Uri object // Uri uriObject = new Uri(uri, true); // // and get rid of the query string if there's one // uri = uriObject.GetLeftPart(UriPartial.Path); methodInfo = new LogicalMethodInfo(typeof(DiscoveryServerProtocol).GetMethod("Discover", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)); ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(this.UriFixups); reflector.Reflect(type, uri); XmlSchemas schemas = reflector.Schemas; this.description = reflector.ServiceDescription; // We need to force initialization of ServiceDescription's XmlSerializer since we // won't necessarily have the permissions to do it when we actually need it XmlSerializer serializer = ServiceDescription.Serializer; // add imports to the external schemas AddSchemaImports(schemas, uri, reflector.ServiceDescriptions); // add imports to the other service descriptions for (int i = 1; i < reflector.ServiceDescriptions.Count; i++) { ServiceDescription description = reflector.ServiceDescriptions[i]; Import import = new Import(); import.Namespace = description.TargetNamespace; // string id = "wsdl" + i.ToString(CultureInfo.InvariantCulture); import.Location = uri + "?wsdl=" + id; this.AddUriFixup(delegate(Uri current) { import.Location = CombineUris(current, import.Location); }); reflector.ServiceDescription.Imports.Add(import); wsdlTable.Add(id, description); } discoDoc = new DiscoveryDocument(); ContractReference contractReference = new ContractReference(uri + "?wsdl", uri); this.AddUriFixup(delegate(Uri current) { contractReference.Ref = CombineUris(current, contractReference.Ref); contractReference.DocRef = CombineUris(current, contractReference.DocRef); }); discoDoc.References.Add(contractReference); foreach (Service service in reflector.ServiceDescription.Services) { foreach (Port port in service.Ports) { SoapAddressBinding soapAddress = (SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding)); if (soapAddress != null) { System.Web.Services.Discovery.SoapBinding binding = new System.Web.Services.Discovery.SoapBinding(); binding.Binding = port.Binding; binding.Address = soapAddress.Location; this.AddUriFixup(delegate(Uri current) { binding.Address = CombineUris(current, binding.Address); }); discoDoc.References.Add(binding); } } } }
public DiscoveryDocument DiscoverAny(string url) { try { 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"); } Uri tmp = new Uri(url); tmp = new Uri(tmp, m.Groups [1].ToString()); url = tmp.ToString(); } stream = Download(ref url); } XmlTextReader reader = new XmlTextReader(url, stream); reader.XmlResolver = null; reader.MoveToContent(); DiscoveryDocument doc; DiscoveryReference refe = null; if (DiscoveryDocument.CanRead(reader)) { doc = DiscoveryDocument.Read(reader); documents.Add(url, doc); refe = new DiscoveryDocumentReference(); AddDiscoReferences(doc); } #if !MOBILE 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.Url = url; ((ContractReference)refe).ResolveInternal(this, wsdl); } #endif else { XmlSchema schema = XmlSchema.Read(reader, null); documents.Add(url, schema); doc = new DiscoveryDocument(); refe = new SchemaReference(); refe.Url = url; ((SchemaReference)refe).ResolveInternal(this, schema); doc.References.Add(refe); } refe.ClientProtocol = this; refe.Url = url; references.Add(url, refe); reader.Close(); return(doc); } catch (DiscoveryException ex) { throw ex.Exception; } }
public DiscoveryDocument DiscoverAny(string url) { Type[] refTypes = WebServicesSection.Current.DiscoveryReferenceTypes; DiscoveryReference discoRef = null; string contentType = null; Stream stream = Download(ref url, ref contentType); Errors.Clear(); bool allErrorsAreHtmlContentType = true; Exception errorInValidDocument = null; ArrayList specialErrorMessages = new ArrayList(); foreach (Type type in refTypes) { if (!typeof(DiscoveryReference).IsAssignableFrom(type)) { continue; } discoRef = (DiscoveryReference)Activator.CreateInstance(type); discoRef.Url = url; discoRef.ClientProtocol = this; stream.Position = 0; Exception e = discoRef.AttemptResolve(contentType, stream); if (e == null) { break; } Errors[type.FullName] = e; discoRef = null; InvalidContentTypeException e2 = e as InvalidContentTypeException; if (e2 == null || !ContentType.MatchesBase(e2.ContentType, "text/html")) { allErrorsAreHtmlContentType = false; } InvalidDocumentContentsException e3 = e as InvalidDocumentContentsException; if (e3 != null) { errorInValidDocument = e; break; } if (e.InnerException != null && e.InnerException.InnerException == null) { specialErrorMessages.Add(e.InnerException.Message); } } if (discoRef == null) { if (errorInValidDocument != null) { StringBuilder errorMessage = new StringBuilder(Res.GetString(Res.TheDocumentWasUnderstoodButContainsErrors)); while (errorInValidDocument != null) { errorMessage.Append("\n - ").Append(errorInValidDocument.Message); errorInValidDocument = errorInValidDocument.InnerException; } throw new InvalidOperationException(errorMessage.ToString()); } else if (allErrorsAreHtmlContentType) { throw new InvalidOperationException(Res.GetString(Res.TheHTMLDocumentDoesNotContainDiscoveryInformation)); } else { bool same = specialErrorMessages.Count == Errors.Count && Errors.Count > 0; for (int i = 1; same && i < specialErrorMessages.Count; i++) { if ((string)specialErrorMessages[i - 1] != (string)specialErrorMessages[i]) { same = false; } } if (same) { throw new InvalidOperationException(Res.GetString(Res.TheDocumentWasNotRecognizedAsAKnownDocumentType, specialErrorMessages[0])); } else { Exception e; StringBuilder errorMessage = new StringBuilder(Res.GetString(Res.WebMissingResource, url)); foreach (DictionaryEntry entry in Errors) { e = (Exception)(entry.Value); string refType = (string)(entry.Key); if (0 == string.Compare(refType, typeof(ContractReference).FullName, StringComparison.Ordinal)) { refType = Res.GetString(Res.WebContractReferenceName); } else if (0 == string.Compare(refType, typeof(SchemaReference).FullName, StringComparison.Ordinal)) { refType = Res.GetString(Res.WebShemaReferenceName); } else if (0 == string.Compare(refType, typeof(DiscoveryDocumentReference).FullName, StringComparison.Ordinal)) { refType = Res.GetString(Res.WebDiscoveryDocumentReferenceName); } errorMessage.Append("\n- ").Append(Res.GetString(Res.WebDiscoRefReport, refType, e.Message)); while (e.InnerException != null) { errorMessage.Append("\n - ").Append(e.InnerException.Message); e = e.InnerException; } } throw new InvalidOperationException(errorMessage.ToString()); } } } if (discoRef is DiscoveryDocumentReference) { return(((DiscoveryDocumentReference)discoRef).Document); } References[discoRef.Url] = discoRef; DiscoveryDocument doc = new DiscoveryDocument(); doc.References.Add(discoRef); return(doc); }
void GenerateDiscoDocument (HttpContext context) { ServiceDescriptionCollection descs = GetDescriptions (); DiscoveryDocument doc = new DiscoveryDocument (); ContractReference cref = new ContractReference (); cref.Ref = _url + "?wsdl"; cref.DocRef = _url; doc.References.Add (cref); foreach (ServiceDescription desc in descs) foreach (Service ser in desc.Services) foreach (Port port in ser.Ports) { SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding; if (sab != null) { System.Web.Services.Discovery.SoapBinding dsb = new System.Web.Services.Discovery.SoapBinding (); dsb.Address = sab.Location; dsb.Binding = port.Binding; doc.AdditionalInfo.Add (dsb); } } context.Response.ContentType = "text/xml; charset=utf-8"; XmlTextWriter xtw = new XmlTextWriter (context.Response.OutputStream, new UTF8Encoding (false)); xtw.Formatting = Formatting.Indented; doc.Write (xtw); }
public override object ReadDocument(Stream stream) { return(DiscoveryDocument.Read(stream)); }
public DiscoveryDocument DiscoverAny(string url) { Type[] discoveryReferenceTypes = WebServicesSection.Current.DiscoveryReferenceTypes; DiscoveryReference reference = null; string contentType = null; Stream stream = this.Download(ref url, ref contentType); this.Errors.Clear(); bool flag = true; Exception innerException = null; ArrayList list = new ArrayList(); foreach (Type type in discoveryReferenceTypes) { if (typeof(DiscoveryReference).IsAssignableFrom(type)) { reference = (DiscoveryReference)Activator.CreateInstance(type); reference.Url = url; reference.ClientProtocol = this; stream.Position = 0L; Exception exception2 = reference.AttemptResolve(contentType, stream); if (exception2 == null) { break; } this.Errors[type.FullName] = exception2; reference = null; InvalidContentTypeException exception3 = exception2 as InvalidContentTypeException; if ((exception3 == null) || !ContentType.MatchesBase(exception3.ContentType, "text/html")) { flag = false; } if (exception2 is InvalidDocumentContentsException) { innerException = exception2; break; } if ((exception2.InnerException != null) && (exception2.InnerException.InnerException == null)) { list.Add(exception2.InnerException.Message); } } } if (reference == null) { if (innerException != null) { StringBuilder builder = new StringBuilder(Res.GetString("TheDocumentWasUnderstoodButContainsErrors")); while (innerException != null) { builder.Append("\n - ").Append(innerException.Message); innerException = innerException.InnerException; } throw new InvalidOperationException(builder.ToString()); } if (flag) { throw new InvalidOperationException(Res.GetString("TheHTMLDocumentDoesNotContainDiscoveryInformation")); } bool flag2 = (list.Count == this.Errors.Count) && (this.Errors.Count > 0); for (int i = 1; flag2 && (i < list.Count); i++) { if (((string)list[i - 1]) != ((string)list[i])) { flag2 = false; } } if (flag2) { throw new InvalidOperationException(Res.GetString("TheDocumentWasNotRecognizedAsAKnownDocumentType", new object[] { list[0] })); } StringBuilder builder2 = new StringBuilder(Res.GetString("WebMissingResource", new object[] { url })); foreach (DictionaryEntry entry in this.Errors) { Exception exception5 = (Exception)entry.Value; string key = (string)entry.Key; if (string.Compare(key, typeof(ContractReference).FullName, StringComparison.Ordinal) == 0) { key = Res.GetString("WebContractReferenceName"); } else if (string.Compare(key, typeof(SchemaReference).FullName, StringComparison.Ordinal) == 0) { key = Res.GetString("WebShemaReferenceName"); } else if (string.Compare(key, typeof(DiscoveryDocumentReference).FullName, StringComparison.Ordinal) == 0) { key = Res.GetString("WebDiscoveryDocumentReferenceName"); } builder2.Append("\n- ").Append(Res.GetString("WebDiscoRefReport", new object[] { key, exception5.Message })); while (exception5.InnerException != null) { builder2.Append("\n - ").Append(exception5.InnerException.Message); exception5 = exception5.InnerException; } } throw new InvalidOperationException(builder2.ToString()); } if (reference is DiscoveryDocumentReference) { return(((DiscoveryDocumentReference)reference).Document); } this.References[reference.Url] = reference; DiscoveryDocument document = new DiscoveryDocument(); document.References.Add(reference); return(document); }
public void ProcessRequest(HttpContext context) { TraceMethod caller = Tracing.On ? new TraceMethod(this, "ProcessRequest", new object[0]) : null; if (Tracing.On) { Tracing.Enter("IHttpHandler.ProcessRequest", caller, Tracing.Details(context.Request)); } new PermissionSet(PermissionState.Unrestricted).Demand(); string physicalPath = context.Request.PhysicalPath; bool traceVerbose = System.ComponentModel.CompModSwitches.DynamicDiscoverySearcher.TraceVerbose; if (File.Exists(physicalPath)) { DynamicDiscoveryDocument document = null; FileStream input = null; try { input = new FileStream(physicalPath, FileMode.Open, FileAccess.Read); XmlTextReader reader = new XmlTextReader(input) { WhitespaceHandling = WhitespaceHandling.Significant, XmlResolver = null, DtdProcessing = DtdProcessing.Prohibit }; if (reader.IsStartElement("dynamicDiscovery", "urn:schemas-dynamicdiscovery:disco.2000-03-17")) { input.Position = 0L; document = DynamicDiscoveryDocument.Load(input); } } finally { if (input != null) { input.Close(); } } if (document != null) { DynamicDiscoSearcher searcher; string[] excludedUrls = new string[document.ExcludePaths.Length]; string directoryName = Path.GetDirectoryName(physicalPath); string fileName = Path.GetFileName(physicalPath); for (int i = 0; i < excludedUrls.Length; i++) { excludedUrls[i] = document.ExcludePaths[i].Path; } Uri url = context.Request.Url; string str = Uri.EscapeUriString(url.ToString()).Replace("#", "%23"); string dirPartOfPath = GetDirPartOfPath(str); if ((GetDirPartOfPath(url.LocalPath).Length == 0) || System.ComponentModel.CompModSwitches.DynamicDiscoveryVirtualSearch.Enabled) { fileName = GetFilePartOfPath(str); searcher = new DynamicVirtualDiscoSearcher(directoryName, excludedUrls, dirPartOfPath); } else { searcher = new DynamicPhysicalDiscoSearcher(directoryName, excludedUrls, dirPartOfPath); } bool flag2 = System.ComponentModel.CompModSwitches.DynamicDiscoverySearcher.TraceVerbose; searcher.Search(fileName); DiscoveryDocument discoveryDocument = searcher.DiscoveryDocument; MemoryStream stream = new MemoryStream(0x400); StreamWriter writer = new StreamWriter(stream, new UTF8Encoding(false)); discoveryDocument.Write(writer); stream.Position = 0L; byte[] buffer = new byte[(int)stream.Length]; int count = stream.Read(buffer, 0, buffer.Length); context.Response.ContentType = ContentType.Compose("text/xml", Encoding.UTF8); context.Response.OutputStream.Write(buffer, 0, count); } else { context.Response.ContentType = "text/xml"; context.Response.WriteFile(physicalPath); } if (Tracing.On) { Tracing.Exit("IHttpHandler.ProcessRequest", caller); } } else { if (Tracing.On) { Tracing.Exit("IHttpHandler.ProcessRequest", caller); } throw new HttpException(0x194, System.Web.Services.Res.GetString("WebPathNotFound", new object[] { context.Request.Path })); } }
void AddDiscoReferences (DiscoveryDocument doc) { foreach (DiscoveryReference re in doc.References) { re.ClientProtocol = this; references.Add (re.Url, re); } if (doc.AdditionalInfo != null) { foreach (object info in doc.AdditionalInfo) additionalInformation.Add (info); } }
private DiscoveryDocument Read9_DiscoveryDocument(bool isNullable, bool checkType) { XmlQualifiedName type = checkType ? base.GetXsiType() : null; bool flag = false; if (isNullable) { flag = base.ReadNull(); } if ((checkType && (type != null)) && ((type.Name != this.id3_DiscoveryDocument) || (type.Namespace != this.id2_Item))) { throw base.CreateUnknownTypeException(type); } if (flag) { return null; } DiscoveryDocument o = new DiscoveryDocument(); IList references = o.References; while (base.Reader.MoveToNextAttribute()) { if (!base.IsXmlnsAttribute(base.Reader.Name)) { base.UnknownNode(o); } } base.Reader.MoveToElement(); if (base.Reader.IsEmptyElement) { base.Reader.Skip(); return o; } base.Reader.ReadStartElement(); base.Reader.MoveToContent(); int whileIterations = 0; int readerCount = base.ReaderCount; while ((base.Reader.NodeType != XmlNodeType.EndElement) && (base.Reader.NodeType != XmlNodeType.None)) { if (base.Reader.NodeType == XmlNodeType.Element) { if ((base.Reader.LocalName == this.id4_discoveryRef) && (base.Reader.NamespaceURI == this.id2_Item)) { if (references == null) { base.Reader.Skip(); } else { references.Add(this.Read3_DiscoveryDocumentReference(false, true)); } } else if ((base.Reader.LocalName == this.id5_contractRef) && (base.Reader.NamespaceURI == this.id6_Item)) { if (references == null) { base.Reader.Skip(); } else { references.Add(this.Read5_ContractReference(false, true)); } } else if ((base.Reader.LocalName == this.id7_schemaRef) && (base.Reader.NamespaceURI == this.id8_Item)) { if (references == null) { base.Reader.Skip(); } else { references.Add(this.Read7_SchemaReference(false, true)); } } else if ((base.Reader.LocalName == this.id9_soap) && (base.Reader.NamespaceURI == this.id10_Item)) { if (references == null) { base.Reader.Skip(); } else { references.Add(this.Read8_SoapBinding(false, true)); } } else { base.UnknownNode(o, "http://schemas.xmlsoap.org/disco/:discoveryRef, http://schemas.xmlsoap.org/disco/scl/:contractRef, http://schemas.xmlsoap.org/disco/schema/:schemaRef, http://schemas.xmlsoap.org/disco/soap/:soap"); } } else { base.UnknownNode(o, "http://schemas.xmlsoap.org/disco/:discoveryRef, http://schemas.xmlsoap.org/disco/scl/:contractRef, http://schemas.xmlsoap.org/disco/schema/:schemaRef, http://schemas.xmlsoap.org/disco/soap/:soap"); } base.Reader.MoveToContent(); base.CheckReaderCount(ref whileIterations, ref readerCount); } base.ReadEndElement(); return o; }