public DiscoveryClientResultCollection ReadAll(string topLevelFilename) { XmlSerializer ser = new XmlSerializer(typeof(DiscoveryClientResultsFile)); Stream file = File.OpenRead(topLevelFilename); string topLevelPath = Path.GetDirectoryName(topLevelFilename); DiscoveryClientResultsFile results = null; try { results = (DiscoveryClientResultsFile)ser.Deserialize(file); for (int i = 0; i < results.Results.Count; i++) { DiscoveryReference reference = (DiscoveryReference)Activator.CreateInstance(Type.GetType(results.Results[i].ReferenceTypeName)); reference.ClientProtocol = this; reference.Url = results.Results[i].Url; Stream docFile = File.OpenRead(Path.Combine(topLevelPath, results.Results[i].Filename)); try { Documents[results.Results[i].Url] = reference.ReadDocument(docFile); Debug.Assert(Documents[results.Results[i].Url] != null, "Couldn't deserialize file " + results.Results[i].Filename); } finally { docFile.Close(); } References[reference.Url] = reference; } } finally { file.Close(); } return(results.Results); }
public void ResolveOneLevel() { this.Errors.Clear(); DiscoveryReference[] array = new DiscoveryReference[this.References.Count]; this.References.Values.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { try { array[i].Resolve(); } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } this.Errors[array[i].Url] = exception; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveOneLevel", exception); } } } }
public void ResolveOneLevel() { // download everything we have a reference to, but don't recurse. Errors.Clear(); DiscoveryReference[] refs = new DiscoveryReference[References.Count]; References.Values.CopyTo(refs, 0); for (int i = 0; i < refs.Length; i++) { try { refs[i].Resolve(); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } // don't let the exception out - keep going. Just add it to the list of errors. Errors[refs[i].Url] = e; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveOneLevel", e); } } } }
public void ResolveAll() { this.Errors.Clear(); int count = this.InlinedSchemas.Keys.Count; while (count != this.References.Count) { count = this.References.Count; DiscoveryReference[] array = new DiscoveryReference[this.References.Count]; this.References.Values.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { DiscoveryReference reference = array[i]; if (reference is DiscoveryDocumentReference) { try { ((DiscoveryDocumentReference)reference).ResolveAll(true); } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } this.Errors[reference.Url] = exception; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveAll", exception); } } } else { try { reference.Resolve(); } catch (Exception exception2) { if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException)) { throw; } this.Errors[reference.Url] = exception2; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveAll", exception2); } } } } } this.FixupReferences(); }
public void ResolveAll() { // Resolve until we reach a 'steady state' (no more references added) Errors.Clear(); int resolvedCount = InlinedSchemas.Keys.Count; while (resolvedCount != References.Count) { resolvedCount = References.Count; DiscoveryReference[] refs = new DiscoveryReference[References.Count]; References.Values.CopyTo(refs, 0); for (int i = 0; i < refs.Length; i++) { DiscoveryReference discoRef = refs[i]; if (discoRef is DiscoveryDocumentReference) { try { // Resolve discovery document references deeply ((DiscoveryDocumentReference)discoRef).ResolveAll(true); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } // don't let the exception out - keep going. Just add it to the list of errors. Errors[discoRef.Url] = e; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveAll", e); } } } else { try { discoRef.Resolve(); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } // don't let the exception out - keep going. Just add it to the list of errors. Errors[discoRef.Url] = e; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveAll", e); } } } } } FixupReferences(); }
public DiscoveryClientResultCollection WriteAll(string directory, string topLevelFilename) { DiscoveryClientResultsFile results = new DiscoveryClientResultsFile(); Hashtable filenames = new Hashtable(); string topLevelFullPath = Path.Combine(directory, topLevelFilename); // write out each of the documents DictionaryEntry[] entries = new DictionaryEntry[Documents.Count + InlinedSchemas.Keys.Count]; int i = 0; foreach (DictionaryEntry entry in Documents) { entries[i++] = entry; } foreach (DictionaryEntry entry in InlinedSchemas) { entries[i++] = entry; } foreach (DictionaryEntry entry in entries) { string url = (string)entry.Key; object document = entry.Value; if (document == null) { continue; } DiscoveryReference reference = References[url]; string filename = reference == null?DiscoveryReference.FilenameFromUrl(Url) : reference.DefaultFilename; filename = GetUniqueFilename(filenames, Path.GetFullPath(Path.Combine(directory, filename))); results.Results.Add(new DiscoveryClientResult(reference == null ? null : reference.GetType(), url, GetRelativePath(filename, topLevelFullPath))); Stream file = File.Create(filename); try { reference.WriteDocument(document, file); } finally { file.Close(); } } // write out the file that points to all those documents. XmlSerializer ser = new XmlSerializer(typeof(DiscoveryClientResultsFile)); Stream topLevelFile = File.Create(topLevelFullPath); try { ser.Serialize(new StreamWriter(topLevelFile, new UTF8Encoding(false)), results); } finally { topLevelFile.Close(); } return(results.Results); }
public DiscoveryClientResultCollection ReadAll(string topLevelFilename) { XmlSerializer serializer = new XmlSerializer(typeof(DiscoveryClientResultsFile)); Stream stream = System.IO.File.OpenRead(topLevelFilename); string directoryName = Path.GetDirectoryName(topLevelFilename); DiscoveryClientResultsFile file = null; try { file = (DiscoveryClientResultsFile)serializer.Deserialize(stream); for (int i = 0; i < file.Results.Count; i++) { if (file.Results[i] == null) { throw new InvalidOperationException(Res.GetString("WebNullRef")); } string referenceTypeName = file.Results[i].ReferenceTypeName; if ((referenceTypeName == null) || (referenceTypeName.Length == 0)) { throw new InvalidOperationException(Res.GetString("WebRefInvalidAttribute", new object[] { "referenceType" })); } DiscoveryReference reference = (DiscoveryReference)Activator.CreateInstance(Type.GetType(referenceTypeName)); reference.ClientProtocol = this; string url = file.Results[i].Url; if ((url == null) || (url.Length == 0)) { throw new InvalidOperationException(Res.GetString("WebRefInvalidAttribute2", new object[] { reference.GetType().FullName, "url" })); } reference.Url = url; string filename = file.Results[i].Filename; if ((filename == null) || (filename.Length == 0)) { throw new InvalidOperationException(Res.GetString("WebRefInvalidAttribute2", new object[] { reference.GetType().FullName, "filename" })); } Stream stream2 = System.IO.File.OpenRead(Path.Combine(directoryName, file.Results[i].Filename)); try { this.Documents[reference.Url] = reference.ReadDocument(stream2); } finally { stream2.Close(); } this.References[reference.Url] = reference; } this.ResolveAll(); } finally { stream.Close(); } return(file.Results); }
public DiscoveryClientResultCollection ReadAll(string topLevelFilename) { XmlSerializer ser = new XmlSerializer(typeof(DiscoveryClientResultsFile)); Stream file = File.OpenRead(topLevelFilename); string topLevelPath = Path.GetDirectoryName(topLevelFilename); DiscoveryClientResultsFile results = null; try { results = (DiscoveryClientResultsFile)ser.Deserialize(file); for (int i = 0; i < results.Results.Count; i++) { if (results.Results[i] == null) { throw new InvalidOperationException(Res.GetString(Res.WebNullRef)); } string typeName = results.Results[i].ReferenceTypeName; if (typeName == null || typeName.Length == 0) { throw new InvalidOperationException(Res.GetString(Res.WebRefInvalidAttribute, "referenceType")); } DiscoveryReference reference = (DiscoveryReference)Activator.CreateInstance(Type.GetType(typeName)); reference.ClientProtocol = this; string url = results.Results[i].Url; if (url == null || url.Length == 0) { throw new InvalidOperationException(Res.GetString(Res.WebRefInvalidAttribute2, reference.GetType().FullName, "url")); } reference.Url = url; string fileName = results.Results[i].Filename; if (fileName == null || fileName.Length == 0) { throw new InvalidOperationException(Res.GetString(Res.WebRefInvalidAttribute2, reference.GetType().FullName, "filename")); } Stream docFile = File.OpenRead(Path.Combine(topLevelPath, results.Results[i].Filename)); try { Documents[reference.Url] = reference.ReadDocument(docFile); Debug.Assert(Documents[reference.Url] != null, "Couldn't deserialize file " + results.Results[i].Filename); } finally { docFile.Close(); } References[reference.Url] = reference; } ResolveAll(); } finally { file.Close(); } return(results.Results); }
public DiscoveryClientResultCollection WriteAll(string directory, string topLevelFilename) { DiscoveryClientResultsFile o = new DiscoveryClientResultsFile(); Hashtable filenames = new Hashtable(); string relativeTo = Path.Combine(directory, topLevelFilename); DictionaryEntry[] entryArray = new DictionaryEntry[this.Documents.Count + this.InlinedSchemas.Keys.Count]; int num = 0; foreach (DictionaryEntry entry in this.Documents) { entryArray[num++] = entry; } foreach (DictionaryEntry entry2 in this.InlinedSchemas) { entryArray[num++] = entry2; } foreach (DictionaryEntry entry3 in entryArray) { string key = (string)entry3.Key; object document = entry3.Value; if (document != null) { DiscoveryReference reference = this.References[key]; string uniqueFilename = (reference == null) ? DiscoveryReference.FilenameFromUrl(base.Url) : reference.DefaultFilename; uniqueFilename = GetUniqueFilename(filenames, Path.GetFullPath(Path.Combine(directory, uniqueFilename))); o.Results.Add(new DiscoveryClientResult((reference == null) ? null : reference.GetType(), key, GetRelativePath(uniqueFilename, relativeTo))); Stream stream = System.IO.File.Create(uniqueFilename); try { reference.WriteDocument(document, stream); } finally { stream.Close(); } } } XmlSerializer serializer = new XmlSerializer(typeof(DiscoveryClientResultsFile)); Stream stream2 = System.IO.File.Create(relativeTo); try { serializer.Serialize((TextWriter) new StreamWriter(stream2, new UTF8Encoding(false)), o); } finally { stream2.Close(); } return(o.Results); }
protected internal override void Resolve(string contentType, Stream stream) { if (ContentType.IsHtml(contentType)) { base.ClientProtocol.Errors[this.Url] = new InvalidContentTypeException(System.Web.Services.Res.GetString("WebInvalidContentType", new object[] { contentType }), contentType); } XmlSchema schema = base.ClientProtocol.Documents[this.Url] as XmlSchema; if (schema == null) { if (base.ClientProtocol.Errors[this.Url] != null) { throw base.ClientProtocol.Errors[this.Url]; } schema = (XmlSchema)this.ReadDocument(stream); base.ClientProtocol.Documents[this.Url] = schema; } if (base.ClientProtocol.References[this.Url] != this) { base.ClientProtocol.References[this.Url] = this; } foreach (XmlSchemaExternal external in schema.Includes) { string url = null; try { if ((external.SchemaLocation != null) && (external.SchemaLocation.Length > 0)) { url = DiscoveryReference.UriToString(this.Url, external.SchemaLocation); SchemaReference reference = new SchemaReference(url) { ClientProtocol = base.ClientProtocol }; base.ClientProtocol.References[url] = reference; reference.Resolve(); } } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } throw new InvalidDocumentContentsException(System.Web.Services.Res.GetString("TheSchemaDocumentContainsLinksThatCouldNotBeResolved", new object[] { url }), exception); } } }
public void ResolveOneLevel() { // download everything we have a reference to, but don't recurse. Errors.Clear(); DiscoveryReference[] refs = new DiscoveryReference[References.Count]; References.Values.CopyTo(refs, 0); for (int i = 0; i < refs.Length; i++) { try { refs[i].Resolve(); } catch (Exception e) { // don't let the exception out - keep going. Just add it to the list of errors. Errors[refs[i].Url] = e; } } }
public DiscoveryClientResultCollection ReadAll(string topLevelFilename) { StreamReader sr = new StreamReader(topLevelFilename); XmlSerializer ser = new XmlSerializer(typeof(DiscoveryClientResultsFile)); DiscoveryClientResultsFile resfile = (DiscoveryClientResultsFile)ser.Deserialize(sr); sr.Close(); string basePath = Path.GetDirectoryName(topLevelFilename); foreach (DiscoveryClientResult dcr in resfile.Results) { Type type = Type.GetType(dcr.ReferenceTypeName); DiscoveryReference dr = (DiscoveryReference)Activator.CreateInstance(type); dr.Url = dcr.Url; FileStream fs = new FileStream(Path.Combine(basePath, dcr.Filename), FileMode.Open, FileAccess.Read); Documents.Add(dr.Url, dr.ReadDocument(fs)); fs.Close(); References.Add(dr.Url, dr); } return(resfile.Results); }
public void ResolveAll() { // Resolve until we reach a 'steady state' (no more references added) Errors.Clear(); int resolvedCount = 0; while (resolvedCount != References.Count) { resolvedCount = References.Count; DiscoveryReference[] refs = new DiscoveryReference[References.Count]; References.Values.CopyTo(refs, 0); for (int i = 0; i < refs.Length; i++) { DiscoveryReference discoRef = refs[i]; if (discoRef is DiscoveryDocumentReference) { try { // Resolve discovery document references deeply ((DiscoveryDocumentReference)discoRef).ResolveAll(true); } catch (Exception e) { // don't let the exception out - keep going. Just add it to the list of errors. Errors[discoRef.Url] = e; } } else { try { discoRef.Resolve(); } catch (Exception e) { // don't let the exception out - keep going. Just add it to the list of errors. Errors[discoRef.Url] = e; } } } } }
internal static void LoadExternals(XmlSchema schema, string url, DiscoveryClientProtocol client, Hashtable loadedExternals) { if (schema != null) { foreach (XmlSchemaExternal external in schema.Includes) { if ((((external.SchemaLocation != null) && (external.SchemaLocation.Length != 0)) && (external.Schema == null)) && ((external is XmlSchemaInclude) || (external is XmlSchemaRedefine))) { string str = DiscoveryReference.UriToString(url, external.SchemaLocation); if (client.References[str] is SchemaReference) { SchemaReference reference = (SchemaReference)client.References[str]; external.Schema = reference.GetSchema(); if (external.Schema != null) { loadedExternals[str] = external.Schema; } reference.LoadExternals(loadedExternals); } } } } }
public bool Contains(DiscoveryReference value) { return(base.List.Contains(value)); }
public void ResolveOneLevel() { this.Errors.Clear(); DiscoveryReference[] array = new DiscoveryReference[this.References.Count]; this.References.Values.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { try { array[i].Resolve(); } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } this.Errors[array[i].Url] = exception; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveOneLevel", exception); } } } }
/// <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; }
public void ResolveAll() { // Resolve until we reach a 'steady state' (no more references added) Errors.Clear(); int resolvedCount = InlinedSchemas.Keys.Count; while (resolvedCount != References.Count) { resolvedCount = References.Count; DiscoveryReference[] refs = new DiscoveryReference[References.Count]; References.Values.CopyTo(refs, 0); for (int i = 0; i < refs.Length; i++) { DiscoveryReference discoRef = refs[i]; if (discoRef is DiscoveryDocumentReference) { try { // Resolve discovery document references deeply ((DiscoveryDocumentReference)discoRef).ResolveAll(true); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } // don't let the exception out - keep going. Just add it to the list of errors. Errors[discoRef.Url] = e; if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveAll", e); } } else { try { discoRef.Resolve(); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } // don't let the exception out - keep going. Just add it to the list of errors. Errors[discoRef.Url] = e; if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveAll", e); } } } } FixupReferences(); }
public void Add (string url, DiscoveryReference value) { InnerHashtable [url] = value; }
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; } }
protected internal override void Resolve(string contentType, Stream stream) { if (ContentType.IsHtml(contentType)) { throw new InvalidContentTypeException(System.Web.Services.Res.GetString("WebInvalidContentType", new object[] { contentType }), contentType); } ServiceDescription description = base.ClientProtocol.Documents[this.Url] as ServiceDescription; if (description == null) { description = ServiceDescription.Read(stream, true); description.RetrievalUrl = this.Url; base.ClientProtocol.Documents[this.Url] = description; } base.ClientProtocol.References[this.Url] = this; ArrayList list = new ArrayList(); foreach (Import import in description.Imports) { if (import.Location != null) { list.Add(import.Location); } } foreach (XmlSchema schema in description.Types.Schemas) { foreach (XmlSchemaExternal external in schema.Includes) { if ((external.SchemaLocation != null) && (external.SchemaLocation.Length > 0)) { list.Add(external.SchemaLocation); } } } foreach (string str in list) { string url = DiscoveryReference.UriToString(this.Url, str); if (base.ClientProtocol.Documents[url] == null) { string str3 = url; try { stream = base.ClientProtocol.Download(ref url, ref contentType); try { if (base.ClientProtocol.Documents[url] == null) { XmlTextReader reader = new XmlTextReader(new StreamReader(stream, RequestResponseUtils.GetEncoding(contentType))) { WhitespaceHandling = WhitespaceHandling.Significant, XmlResolver = null, DtdProcessing = DtdProcessing.Prohibit }; if (ServiceDescription.CanRead(reader)) { ServiceDescription description2 = ServiceDescription.Read(reader, true); description2.RetrievalUrl = url; base.ClientProtocol.Documents[url] = description2; ContractReference reference = new ContractReference(url, null) { ClientProtocol = base.ClientProtocol }; try { reference.Resolve(contentType, stream); } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } reference.Url = str3; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "Resolve", exception); } } } else if (reader.IsStartElement("schema", "http://www.w3.org/2001/XMLSchema")) { base.ClientProtocol.Documents[url] = XmlSchema.Read(reader, null); SchemaReference reference2 = new SchemaReference(url) { ClientProtocol = base.ClientProtocol }; try { reference2.Resolve(contentType, stream); } catch (Exception exception2) { if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException)) { throw; } reference2.Url = str3; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "Resolve", exception2); } } } } } finally { stream.Close(); } } catch (Exception exception3) { if (((exception3 is ThreadAbortException) || (exception3 is StackOverflowException)) || (exception3 is OutOfMemoryException)) { throw; } throw new InvalidDocumentContentsException(System.Web.Services.Res.GetString("TheWSDLDocumentContainsLinksThatCouldNotBeResolved", new object[] { url }), exception3); } } } }
/// <include file='doc\DiscoveryClientReferences.uex' path='docs/doc[@for="DiscoveryClientReferenceCollection.Add1"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Add(string url, DiscoveryReference value) { Dictionary.Add(url, value); }
public void Remove(DiscoveryReference value) { InnerList.Remove(value); }
/// <include file='doc\DiscoveryClientReferences.uex' path='docs/doc[@for="DiscoveryClientReferenceCollection.Add1"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Add(string url, DiscoveryReference value) { Dictionary.Add(url, value); }
/// <include file='doc\DiscoveryClientReferences.uex' path='docs/doc[@for="DiscoveryClientReferenceCollection.Add"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Add(DiscoveryReference value) { Add(value.Url, value); }
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); }
public void Add(string url, DiscoveryReference value) { InnerHashtable [url] = value; }
public void Add(DiscoveryReference value) { Add(value.Url, value); }
public void Remove(DiscoveryReference value) { base.List.Remove(value); }
public int Add (DiscoveryReference value) { return InnerList.Add (value); }
public int Add(DiscoveryReference value) { return(base.List.Add(value)); }
public void Remove (DiscoveryReference value) { InnerList.Remove (value); }
public int Add(DiscoveryReference value) { return(InnerList.Add(value)); }
public bool Contains(DiscoveryReference value) { return base.List.Contains(value); }
public void ResolveOneLevel() { // download everything we have a reference to, but don't recurse. Errors.Clear(); DiscoveryReference[] refs = new DiscoveryReference[References.Count]; References.Values.CopyTo(refs, 0); for (int i = 0; i < refs.Length; i++) { try { refs[i].Resolve(); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } // don't let the exception out - keep going. Just add it to the list of errors. Errors[refs[i].Url] = e; if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveOneLevel", e); } } }
public void Remove(DiscoveryReference value) { base.List.Remove(value); }
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 int Add(DiscoveryReference value) { return base.List.Add(value); }
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 ResolveAll() { this.Errors.Clear(); int count = this.InlinedSchemas.Keys.Count; while (count != this.References.Count) { count = this.References.Count; DiscoveryReference[] array = new DiscoveryReference[this.References.Count]; this.References.Values.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { DiscoveryReference reference = array[i]; if (reference is DiscoveryDocumentReference) { try { ((DiscoveryDocumentReference) reference).ResolveAll(true); } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } this.Errors[reference.Url] = exception; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveAll", exception); } } } else { try { reference.Resolve(); } catch (Exception exception2) { if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException)) { throw; } this.Errors[reference.Url] = exception2; if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, this, "ResolveAll", exception2); } } } } } this.FixupReferences(); }