public override WebServiceDiscoveryResult Load (WebReferenceItem item)
		{
			FilePath basePath = item.MapFile.FilePath.ParentDirectory;
			ReferenceGroup resfile = ReferenceGroup.Read (item.MapFile.FilePath);
			
			// TODO: Read as MetadataSet
			
			DiscoveryClientProtocol protocol = new DiscoveryClientProtocol ();
			
			foreach (MetadataFile dcr in resfile.Metadata)
			{
				DiscoveryReference dr;
				switch (dcr.MetadataType) {
					case "Wsdl":
						dr = new System.Web.Services.Discovery.ContractReference ();
						break;
					case "Disco":
						dr = new System.Web.Services.Discovery.DiscoveryDocumentReference ();
						break;
					case "Schema":
						dr = new System.Web.Services.Discovery.SchemaReference ();
						break;
					default:
						continue;
				}

				dr.Url = dcr.SourceUrl;
				FileStream fs = new FileStream (basePath.Combine (dcr.FileName), FileMode.Open, FileAccess.Read);
				protocol.Documents.Add (dr.Url, dr.ReadDocument (fs));
				fs.Close ();
				protocol.References.Add (dr.Url, dr);
			}
			return new WebServiceDiscoveryResultWCF (protocol, null, item, resfile);
		}
Esempio n. 2
0
        internal override void LoadExternals(Hashtable loadedExternals)
        {
            ServiceDescription contract = null;

            try {
                contract = Contract;
            }
            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.
                ClientProtocol.Errors[Url] = e;
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "LoadExternals", e);
                }
            }
            if (contract != null)
            {
                foreach (XmlSchema schema in Contract.Types.Schemas)
                {
                    SchemaReference.LoadExternals(schema, Url, ClientProtocol, loadedExternals);
                }
            }
        }
 private void Write7_SchemaReference(string n, string ns, SchemaReference o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(SchemaReference)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.WriteStartElement(n, ns, o, false, null);
         if (needType)
         {
             base.WriteXsiType("SchemaReference", "http://schemas.xmlsoap.org/disco/schema/");
         }
         base.WriteAttribute("ref", "", o.Ref);
         base.WriteAttribute("targetNamespace", "", o.TargetNamespace);
         base.WriteEndElement(o);
     }
 }
Esempio n. 4
0
        internal override void LoadExternals(Hashtable loadedExternals)
        {
            ServiceDescription contract = null;

            try
            {
                contract = this.Contract;
            }
            catch (Exception exception)
            {
                if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                {
                    throw;
                }
                base.ClientProtocol.Errors[this.Url] = exception;
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "LoadExternals", exception);
                }
            }
            if (contract != null)
            {
                foreach (XmlSchema schema in this.Contract.Types.Schemas)
                {
                    SchemaReference.LoadExternals(schema, this.Url, base.ClientProtocol, loadedExternals);
                }
            }
        }
Esempio n. 5
0
 internal static void LoadExternals(XmlSchema schema, string url, DiscoveryClientProtocol client, Hashtable loadedExternals)
 {
     if (schema == null)
     {
         return;
     }
     foreach (XmlSchemaExternal external in schema.Includes)
     {
         if (external.SchemaLocation == null || external.SchemaLocation.Length == 0 || external.Schema != null)
         {
             continue;
         }
         if (external is XmlSchemaInclude || external is XmlSchemaRedefine)
         {
             string location = UriToString(url, external.SchemaLocation);
             if (client.References[location] is SchemaReference)
             {
                 SchemaReference externalRef = (SchemaReference)client.References[location];
                 external.Schema = externalRef.GetSchema();
                 if (external.Schema != null)
                 {
                     loadedExternals[location] = external.Schema;
                 }
                 externalRef.LoadExternals(loadedExternals);
             }
         }
     }
 }
Esempio n. 6
0
        /// <include file='doc\SchemaReference.uex' path='docs/doc[@for="SchemaReference.Resolve"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected internal override void Resolve(string contentType, Stream stream)
        {
            if (ContentType.IsHtml(contentType))
            {
                throw new InvalidContentTypeException(Res.GetString(Res.WebInvalidContentType, contentType), contentType);
            }
            XmlSchema schema = ClientProtocol.Documents[Url] as XmlSchema;

            if (schema == null)
            {
                schema = XmlSchema.Read(stream, null);
                ClientProtocol.Documents[Url] = schema;
            }

            ClientProtocol.References[Url] = this;

            // now resolve references in the schema.
            foreach (object item in schema.Includes)
            {
                string location = null;
                try {
                    if (item is XmlSchemaInclude)
                    {
                        location = ((XmlSchemaInclude)item).SchemaLocation;
                        if (location == null)
                        {
                            continue;
                        }
                        location = new Uri(new Uri(Url), location).ToString();
                        SchemaReference includeRef = new SchemaReference(location);
                        includeRef.ClientProtocol           = ClientProtocol;
                        ClientProtocol.References[location] = includeRef;
                        includeRef.Resolve();
                    }
                    else if (item is XmlSchemaImport)
                    {
                        location = ((XmlSchemaImport)item).SchemaLocation;
                        if (location == null)
                        {
                            continue;
                        }
                        location = new Uri(new Uri(Url), location).ToString();
                        SchemaReference importRef = new SchemaReference(location);
                        importRef.ClientProtocol            = ClientProtocol;
                        ClientProtocol.References[location] = importRef;
                        importRef.Resolve();
                    }
                }
                catch (Exception e) {
                    throw new InvalidDocumentContentsException(Res.GetString(Res.TheSchemaDocumentContainsLinksThatCouldNotBeResolved, location), e);
                }
            }

            return;
        }
Esempio n. 7
0
        internal void ResolveInternal(DiscoveryClientProtocol prot, XmlSchema xsd)
        {
            if (xsd.Includes.Count == 0)
            {
                return;
            }

            foreach (XmlSchemaExternal ext in xsd.Includes)
            {
                if (ext.SchemaLocation == null)
                {
                    continue;
                }

                // Make relative uris to absoulte

                Uri    uri = new Uri(BaseUri, ext.SchemaLocation);
                string url = uri.ToString();

                if (prot.Documents.Contains(url))                       // Already resolved
                {
                    continue;
                }

                try
                {
                    string        contentType = null;
                    Stream        stream      = prot.Download(ref url, ref contentType);
                    XmlTextReader reader      = new XmlTextReader(url, stream);
                    reader.XmlResolver = null;
                    reader.MoveToContent();

                    DiscoveryReference refe;
                    XmlSchema          schema = XmlSchema.Read(reader, null);
                    refe = new SchemaReference();
                    refe.ClientProtocol = prot;
                    refe.Url            = url;
                    prot.Documents.Add(url, schema);
                    ((SchemaReference)refe).ResolveInternal(prot, schema);

                    if (!prot.References.Contains(url))
                    {
                        prot.References.Add(refe);
                    }

                    stream.Close();
                }
                catch (Exception ex)
                {
                    ReportError(url, ex);
                }
            }
        }
Esempio n. 8
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);
                }
            }
        }
Esempio n. 9
0
        /// <include file='doc\SchemaReference.uex' path='docs/doc[@for="SchemaReference.Resolve"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected internal override void Resolve(string contentType, Stream stream)
        {
            if (ContentType.IsHtml(contentType))
            {
                ClientProtocol.Errors[Url] = new InvalidContentTypeException(Res.GetString(Res.WebInvalidContentType, contentType), contentType);
            }
            XmlSchema schema = ClientProtocol.Documents[Url] as XmlSchema;

            if (schema == null)
            {
                if (ClientProtocol.Errors[Url] != null)
                {
                    throw (Exception)ClientProtocol.Errors[Url];
                }
                schema = (XmlSchema)ReadDocument(stream);
                ClientProtocol.Documents[Url] = schema;
            }
            if (ClientProtocol.References[Url] != this)
            {
                ClientProtocol.References[Url] = this;
            }
            // now resolve references in the schema.
            foreach (XmlSchemaExternal external in schema.Includes)
            {
                string location = null;
                try {
                    if (external.SchemaLocation != null && external.SchemaLocation.Length > 0)
                    {
                        location = UriToString(Url, external.SchemaLocation);
                        SchemaReference externalRef = new SchemaReference(location);
                        externalRef.ClientProtocol          = ClientProtocol;
                        ClientProtocol.References[location] = externalRef;
                        externalRef.Resolve();
                    }
                }
                catch (Exception e) {
                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                    {
                        throw;
                    }
                    throw new InvalidDocumentContentsException(Res.GetString(Res.TheSchemaDocumentContainsLinksThatCouldNotBeResolved, location), e);
                }
            }
            return;
        }
Esempio n. 10
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);
                 }
             }
         }
     }
 }
Esempio n. 11
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);
                    }
                }
            }
        }
Esempio n. 12
0
		internal void ResolveInternal (DiscoveryClientProtocol prot, XmlSchema xsd) 
		{
			if (xsd.Includes.Count == 0) return;
			
			foreach (XmlSchemaExternal ext in xsd.Includes)
			{
				if (ext.SchemaLocation == null)
					continue;

				// Make relative uris to absoulte

				Uri uri = new Uri (BaseUri, ext.SchemaLocation);
				string url = uri.ToString ();

				if (prot.Documents.Contains (url)) 	// Already resolved
					continue;

				try
				{
					string contentType = null;
					Stream stream = prot.Download (ref url, ref contentType);
					XmlTextReader reader = new XmlTextReader (url, stream);
					reader.XmlResolver = null;
					reader.MoveToContent ();
					
					DiscoveryReference refe;
					XmlSchema schema = XmlSchema.Read (reader, null);
					refe = new SchemaReference ();
					refe.ClientProtocol = prot;
					refe.Url = url;
					prot.Documents.Add (url, schema);
					((SchemaReference)refe).ResolveInternal (prot, schema);
					
					if (!prot.References.Contains (url))
						prot.References.Add (refe);
						
					stream.Close ();
				}
				catch (Exception ex)
				{
					ReportError (url, ex);
				}
			}
		}
Esempio n. 13
0
        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;
            }
        }
Esempio n. 14
0
        /// <include file='doc\ContractReference.uex' path='docs/doc[@for="ContractReference.Resolve"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected internal override void Resolve(string contentType, Stream stream)
        {
            if (ContentType.IsHtml(contentType))
            {
                throw new InvalidContentTypeException(Res.GetString(Res.WebInvalidContentType, contentType), contentType);
            }
            ServiceDescription serviceDescription = ClientProtocol.Documents[Url] as ServiceDescription;

            if (serviceDescription == null)
            {
                serviceDescription = ServiceDescription.Read(stream, true);
                serviceDescription.RetrievalUrl = Url;
                ClientProtocol.Documents[Url]   = serviceDescription;
            }

            ClientProtocol.References[Url] = this;

            ArrayList importUrls = new ArrayList();

            foreach (Import import in serviceDescription.Imports)
            {
                if (import.Location != null)
                {
                    importUrls.Add(import.Location);
                }
            }
            foreach (XmlSchema schema in serviceDescription.Types.Schemas)
            {
                foreach (XmlSchemaExternal external in schema.Includes)
                {
                    if (external.SchemaLocation != null && external.SchemaLocation.Length > 0)
                    {
                        importUrls.Add(external.SchemaLocation);
                    }
                }
            }

            foreach (string urlFromImport in importUrls)
            {
                // make the (possibly) relative Uri in the contract fully qualified with respect to the contract URL
                string importUrl = UriToString(Url, urlFromImport);
                if (ClientProtocol.Documents[importUrl] != null)
                {
                    continue;
                }

                string oldUrl = importUrl;
                try {
                    stream = ClientProtocol.Download(ref importUrl, ref contentType);
                    try {
                        //Proceed only if not been here before
                        if (ClientProtocol.Documents[importUrl] == null)
                        {
                            XmlTextReader reader = new XmlTextReader(new StreamReader(stream, RequestResponseUtils.GetEncoding(contentType)));
                            reader.WhitespaceHandling = WhitespaceHandling.Significant;
                            reader.XmlResolver        = null;
                            reader.DtdProcessing      = DtdProcessing.Prohibit;
                            //Resolve on WSDL and XSD will go recursivelly
                            if (ServiceDescription.CanRead(reader))
                            {
                                ServiceDescription doc = ServiceDescription.Read(reader, true);
                                doc.RetrievalUrl = importUrl;
                                ClientProtocol.Documents[importUrl] = doc;
                                ContractReference contractReference = new ContractReference(importUrl, null);
                                contractReference.ClientProtocol = ClientProtocol;
                                try {
                                    contractReference.Resolve(contentType, stream);
                                }
                                catch (Exception e) {
                                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                                    {
                                        throw;
                                    }
                                    contractReference.Url = oldUrl;
                                    if (Tracing.On)
                                    {
                                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "Resolve", e);
                                    }
                                }
                            }
                            else if (reader.IsStartElement("schema", XmlSchema.Namespace))
                            {
                                ClientProtocol.Documents[importUrl] = XmlSchema.Read(reader, null);
                                SchemaReference schemaReference = new SchemaReference(importUrl);
                                schemaReference.ClientProtocol = ClientProtocol;
                                try {
                                    schemaReference.Resolve(contentType, stream);
                                }
                                catch (Exception e) {
                                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                                    {
                                        throw;
                                    }
                                    schemaReference.Url = oldUrl;
                                    if (Tracing.On)
                                    {
                                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "Resolve", e);
                                    }
                                }
                            }
                            // If it's not XML, or we don't know what kind of XML it is, skip the file.  The user
                            // will have to download the dependent file(s) manually, but at least we will continue
                            // to discover files instead of throwing an exception.
                        }
                    }
                    finally {
                        stream.Close();
                    }
                }
                catch (Exception e) {
                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                    {
                        throw;
                    }
                    throw new InvalidDocumentContentsException(Res.GetString(Res.TheWSDLDocumentContainsLinksThatCouldNotBeResolved, importUrl), e);
                }
            }
        }
 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);
             }
         }
     }
 }
Esempio n. 16
0
        internal void ResolveInternal(DiscoveryClientProtocol prot, ServiceDescription wsdl)
        {
            if (wsdl.Imports == null)
            {
                return;
            }

            foreach (Import import in wsdl.Imports)
            {
                // Make relative uris to absoulte

                Uri    uri = new Uri(BaseUri, import.Location);
                string url = uri.ToString();

                if (prot.Documents.Contains(url))                       // Already resolved
                {
                    continue;
                }

                try
                {
                    string        contentType = null;
                    Stream        stream      = prot.Download(ref url, ref contentType);
                    XmlTextReader reader      = new XmlTextReader(url, stream);
                    reader.XmlResolver = null;
                    reader.MoveToContent();

                    DiscoveryReference refe;
                    if (ServiceDescription.CanRead(reader))
                    {
                        ServiceDescription refWsdl = ServiceDescription.Read(reader);
                        refe = new ContractReference();
                        refe.ClientProtocol = prot;
                        refe.Url            = url;
                        ((ContractReference)refe).ResolveInternal(prot, refWsdl);
                        prot.Documents.Add(url, refWsdl);
                    }
                    else
                    {
                        XmlSchema schema = XmlSchema.Read(reader, null);
                        refe = new SchemaReference();
                        refe.ClientProtocol = prot;
                        refe.Url            = url;
                        prot.Documents.Add(url, schema);
                    }

                    if (!prot.References.Contains(url))
                    {
                        prot.References.Add(refe);
                    }

                    reader.Close();
                }
                catch (Exception ex)
                {
                    ReportError(url, ex);
                }
            }

            foreach (XmlSchema schema in wsdl.Types.Schemas)
            {
                // the schema itself is not added to the
                // references, but it has to resolve includes.
                Uri             uri  = BaseUri;
                string          url  = uri.ToString();
                SchemaReference refe = new SchemaReference();
                refe.ClientProtocol = prot;
                refe.Url            = url;
                refe.ResolveInternal(prot, schema);
            }
        }
        /// <include file='doc\ContractReference.uex' path='docs/doc[@for="ContractReference.Resolve"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected internal override void Resolve(string contentType, Stream stream) {
            if (ContentType.IsHtml(contentType))
                throw new InvalidContentTypeException(Res.GetString(Res.WebInvalidContentType, contentType), contentType);
            ServiceDescription serviceDescription = ClientProtocol.Documents[Url] as ServiceDescription;
            if ( serviceDescription == null ) {
                serviceDescription = ServiceDescription.Read(stream, true);
                serviceDescription.RetrievalUrl = Url;
                ClientProtocol.Documents[Url] = serviceDescription;
            }

            ClientProtocol.References[Url] = this;

            ArrayList importUrls = new ArrayList();
            foreach (Import import in serviceDescription.Imports)
                if (import.Location != null)
                    importUrls.Add(import.Location);
            foreach (XmlSchema schema in serviceDescription.Types.Schemas) {
                foreach (XmlSchemaExternal external in schema.Includes) {
                    if (external.SchemaLocation != null && external.SchemaLocation.Length > 0) {
                        importUrls.Add(external.SchemaLocation);
                    }
                }
            }

            foreach (string urlFromImport in importUrls) {
                // make the (possibly) relative Uri in the contract fully qualified with respect to the contract URL
                string importUrl = UriToString(Url, urlFromImport);
                if ( ClientProtocol.Documents[importUrl] != null ) {
                    continue;
                }

                string oldUrl = importUrl;
                try {
                    stream = ClientProtocol.Download(ref importUrl, ref contentType);
                    try {
                        //Proceed only if not been here before
                        if ( ClientProtocol.Documents[importUrl] == null ) {
                            XmlTextReader reader = new XmlTextReader(new StreamReader(stream, RequestResponseUtils.GetEncoding(contentType)));
                            reader.WhitespaceHandling = WhitespaceHandling.Significant;
                            reader.XmlResolver = null;
                            reader.DtdProcessing = DtdProcessing.Prohibit;
                            //Resolve on WSDL and XSD will go recursivelly
                            if (ServiceDescription.CanRead(reader)) {
                                ServiceDescription doc = ServiceDescription.Read(reader, true);
                                doc.RetrievalUrl = importUrl;
                                ClientProtocol.Documents[importUrl] = doc;
                                ContractReference contractReference = new ContractReference(importUrl, null);
                                contractReference.ClientProtocol = ClientProtocol;
                                try {
                                    contractReference.Resolve(contentType, stream);
                                }
                                catch (Exception e) {
                                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                                        throw;
                                    }
                                    contractReference.Url = oldUrl;
                                    if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "Resolve", e);
                                }
                            }
                            else if (reader.IsStartElement("schema", XmlSchema.Namespace)) {
                                ClientProtocol.Documents[importUrl] = XmlSchema.Read(reader, null);
                                SchemaReference schemaReference = new SchemaReference(importUrl);
                                schemaReference.ClientProtocol = ClientProtocol;
                                try {
                                    schemaReference.Resolve(contentType, stream);
                                }
                                catch (Exception e) {
                                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                                        throw;
                                    }
                                    schemaReference.Url = oldUrl;
                                    if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "Resolve", e);
                                }
                            }
                            // If it's not XML, or we don't know what kind of XML it is, skip the file.  The user 
                            // will have to download the dependent file(s) manually, but at least we will continue 
                            // to discover files instead of throwing an exception.
                        }
                    }
                    finally {
                        stream.Close();
                    }
                }
                catch (Exception e) {
                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                        throw;
                    }
                    throw new InvalidDocumentContentsException(Res.GetString(Res.TheWSDLDocumentContainsLinksThatCouldNotBeResolved, importUrl), e);
                }
            }
        }
 /// <include file='doc\SchemaReference.uex' path='docs/doc[@for="SchemaReference.Resolve"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 protected internal override void Resolve(string contentType, Stream stream) {
     if (ContentType.IsHtml(contentType))
         ClientProtocol.Errors[Url] = new InvalidContentTypeException(Res.GetString(Res.WebInvalidContentType, contentType), contentType);
     XmlSchema schema = ClientProtocol.Documents[Url] as XmlSchema;
     if ( schema == null ) {
         if (ClientProtocol.Errors[Url] != null)
             throw (Exception)ClientProtocol.Errors[Url];
         schema = (XmlSchema)ReadDocument(stream);
         ClientProtocol.Documents[Url] = schema;
     }
     if (ClientProtocol.References[Url] != this)
         ClientProtocol.References[Url] = this;
     // now resolve references in the schema.
     foreach (XmlSchemaExternal external in schema.Includes) {
         string location = null;
         try {
             if (external.SchemaLocation != null && external.SchemaLocation.Length > 0) {
                 location = UriToString(Url, external.SchemaLocation);
                 SchemaReference externalRef = new SchemaReference(location);
                 externalRef.ClientProtocol = ClientProtocol;
                 ClientProtocol.References[location] = externalRef;
                 externalRef.Resolve();
             }
         }
         catch (Exception e) {
             if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                 throw;
             }
             throw new InvalidDocumentContentsException(Res.GetString(Res.TheSchemaDocumentContainsLinksThatCouldNotBeResolved, location), e);
         }
     }
     return;
 }
		public override WebServiceDiscoveryResult Load (WebReferenceItem item)
		{
			FilePath basePath = item.MapFile.FilePath.ParentDirectory;
			ReferenceGroup resfile = ReferenceGroup.Read (item.MapFile.FilePath);
			
			// TODO: Read as MetadataSet
			
			var protocol = new DiscoveryClientProtocol ();
			
			foreach (MetadataFile dcr in resfile.Metadata)
			{
				DiscoveryReference dr;
				switch (dcr.MetadataType) {
					case "Wsdl":
						dr = new ContractReference ();
						break;
					case "Disco":
						dr = new DiscoveryDocumentReference ();
						break;
					case "Schema":
						dr = new SchemaReference ();
						break;
					default:
						continue;
				}

				dr.Url = dcr.SourceUrl;
				var fs = new FileStream (basePath.Combine (dcr.FileName), FileMode.Open, FileAccess.Read);
				protocol.Documents.Add (dr.Url, dr.ReadDocument (fs));
				fs.Close ();
				protocol.References.Add (dr.Url, dr);
			}
			return new WebServiceDiscoveryResultWCF (protocol, null, item, resfile, DefaultClientOptions);
		}
Esempio n. 20
0
		internal void ResolveInternal (DiscoveryClientProtocol prot, ServiceDescription wsdl) 
		{
			if (wsdl.Imports == null) return;
			
			foreach (Import import in wsdl.Imports)
			{
				// Make relative uris to absoulte

				Uri uri = new Uri (BaseUri, import.Location);
				string url = uri.ToString ();

				if (prot.Documents.Contains (url)) 	// Already resolved
					continue;

				try
				{
					string contentType = null;
					Stream stream = prot.Download (ref url, ref contentType);
					XmlTextReader reader = new XmlTextReader (url, stream);
					reader.XmlResolver = null;
					reader.MoveToContent ();
					
					DiscoveryReference refe;
					if (ServiceDescription.CanRead (reader))
					{
						ServiceDescription refWsdl = ServiceDescription.Read (reader);
						refe = new ContractReference ();
						refe.ClientProtocol = prot;
						refe.Url = url;
						((ContractReference)refe).ResolveInternal (prot, refWsdl);
						prot.Documents.Add (url, refWsdl);
					}
					else
					{
						XmlSchema schema = XmlSchema.Read (reader, null);
						refe = new SchemaReference ();
						refe.ClientProtocol = prot;
						refe.Url = url;
						prot.Documents.Add (url, schema);
					}
					
					if (!prot.References.Contains (url))
						prot.References.Add (refe);
						
					reader.Close ();
				}
				catch (Exception ex)
				{
					ReportError (url, ex);
				}
			}

			foreach (XmlSchema schema in wsdl.Types.Schemas)
			{
				// the schema itself is not added to the
				// references, but it has to resolve includes.
				Uri uri = BaseUri;
				string url = uri.ToString ();
				SchemaReference refe = new SchemaReference ();
				refe.ClientProtocol = prot;
				refe.Url = url;
				refe.ResolveInternal (prot, schema);
			}
		}
 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);
         }
     }
 }
Esempio n. 22
0
		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;
			}
		}
 private SchemaReference Read7_SchemaReference(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.id15_SchemaReference) || (type.Namespace != this.id8_Item)))
     {
         throw base.CreateUnknownTypeException(type);
     }
     if (flag)
     {
         return null;
     }
     SchemaReference o = new SchemaReference();
     bool[] flagArray = new bool[2];
     while (base.Reader.MoveToNextAttribute())
     {
         if ((!flagArray[0] && (base.Reader.LocalName == this.id16_ref)) && (base.Reader.NamespaceURI == this.id13_Item))
         {
             o.Ref = base.Reader.Value;
             flagArray[0] = true;
         }
         else
         {
             if ((!flagArray[1] && (base.Reader.LocalName == this.id17_targetNamespace)) && (base.Reader.NamespaceURI == this.id13_Item))
             {
                 o.TargetNamespace = base.Reader.Value;
                 flagArray[1] = true;
                 continue;
             }
             if (!base.IsXmlnsAttribute(base.Reader.Name))
             {
                 base.UnknownNode(o, ":ref, :targetNamespace");
             }
         }
     }
     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)
         {
             base.UnknownNode(o, "");
         }
         else
         {
             base.UnknownNode(o, "");
         }
         base.Reader.MoveToContent();
         base.CheckReaderCount(ref whileIterations, ref readerCount);
     }
     base.ReadEndElement();
     return o;
 }