예제 #1
0
        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);
                }
            }
        }
예제 #2
0
 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);
                 }
             }
         }
     }
 }
예제 #3
0
        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);
                    }
                }
            }
        }
        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);
                }
            }
        }