Пример #1
0
        static void Generate(string url, TextWriter writer)
        {
            var cr = new ContractReference();
            cr.Url = url;

            var protocol = new DiscoveryClientProtocol();

            var wc = new WebClient();
            using (var stream = wc.OpenRead(cr.Url))
                protocol.Documents.Add(cr.Url, cr.ReadDocument(stream));

            var mset = ToMetadataSet(protocol);

            var importer = new WsdlImporter(mset);
            var xsdImporter = new XsdDataContractImporter();
            var options = new ImportOptions();
            options.ReferencedCollectionTypes.Add(typeof(LinkedList<>));
            xsdImporter.Options = options;
            importer.State.Add(typeof(XsdDataContractImporter), xsdImporter);

            Collection<ContractDescription> contracts = importer.ImportAllContracts();

            CodeCompileUnit ccu = new CodeCompileUnit();
            CodeNamespace cns = new CodeNamespace("TestNamespace");
            ccu.Namespaces.Add(cns);

            var generator = new ServiceContractGenerator(ccu);

            foreach (var cd in contracts)
                generator.GenerateServiceContractType(cd);

            var provider = new CSharpCodeProvider();
            provider.GenerateCodeFromCompileUnit(ccu, writer, null);
        }
Пример #2
0
		public void SetUpFixture()
		{
			project = WebReferenceTestHelper.CreateTestProject("C#");
			project.FileName = FileName.Create("C:\\projects\\test\\foo.csproj");

			protocol = new DiscoveryClientProtocol();
			DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference();
			discoveryRef.Url = updateFromUrl;
			protocol.References.Add(discoveryRef);
			
			ContractReference contractRef = new ContractReference();
			contractRef.Url = "http://localhost/test.asmx?wsdl";
			contractRef.ClientProtocol = new DiscoveryClientProtocol();
			ServiceDescription desc = new ServiceDescription();
			contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc);
			protocol.References.Add(contractRef);
			
			WebReferenceTestHelper.InitializeProjectBindings();
			
			webReference = new SD.WebReference(project, updateFromUrl, name, proxyNamespace, protocol);
			
			webReferenceUrl = webReference.WebReferenceUrl;
			discoFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\test.disco", ItemType.None);
			referenceMapFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\Reference.map", ItemType.None);
			wsdlFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\test.wsdl", ItemType.None); 
			proxyFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\Reference.cs", ItemType.Compile);
			webReferencesProjectItem = (WebReferencesProjectItem)WebReferenceTestHelper.GetProjectItem(webReference.Items, "Web References\\", ItemType.WebReferences);
			webServicesReferenceProjectItem = (ReferenceProjectItem)WebReferenceTestHelper.GetProjectItem(webReference.Items, ItemType.Reference);
		}
		public override void FixtureSetUp()
		{
			base.FixtureSetUp();
			project = WebReferenceTestHelper.CreateTestProject("C#");
			project.FileName = FileName.Create("C:\\projects\\test\\foo.csproj");

			protocol = new DiscoveryClientProtocol();
			DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference();
			discoveryRef.Url = updateFromUrl;
			protocol.References.Add(discoveryRef);
			
			ContractReference contractRef = new ContractReference();
			contractRef.Url = "http://localhost/test.asmx?wsdl";
			contractRef.ClientProtocol = new DiscoveryClientProtocol();
			ServiceDescription desc = new ServiceDescription();
			contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc);
			protocol.References.Add(contractRef);
			
			WebReferenceTestHelper.InitializeProjectBindings();
			
			webReference = new Gui.WebReference(project, updateFromUrl, name, proxyNamespace, protocol);
			
			foreach (ProjectItem item in webReference.Items) {
				ProjectService.AddProjectItem(project, item);
			}
			webReferencesProjectItem = webReference.WebReferencesProjectItem;
		}
 private void Write5_ContractReference(string n, string ns, ContractReference o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(ContractReference)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.WriteStartElement(n, ns, o, false, null);
         if (needType)
         {
             base.WriteXsiType("ContractReference", "http://schemas.xmlsoap.org/disco/scl/");
         }
         base.WriteAttribute("ref", "", o.Ref);
         base.WriteAttribute("docRef", "", o.DocRef);
         base.WriteEndElement(o);
     }
 }
		public override void FixtureSetUp()
		{
			base.FixtureSetUp();
			project = WebReferenceTestHelper.CreateTestProject("C#");
			WebReferencesProjectItem item = new WebReferencesProjectItem(project);
			item.Include = "Web References\\";
			ProjectService.AddProjectItem(project, item);

			protocol = new DiscoveryClientProtocol();
			DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference();
			discoveryRef.Url = updateFromUrl;
			protocol.References.Add(discoveryRef);

			ContractReference contractRef = new ContractReference();
			contractRef.Url = "http://localhost/test.asmx?wsdl";
			contractRef.ClientProtocol = new DiscoveryClientProtocol();
			ServiceDescription desc = new ServiceDescription();
			contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc);
			protocol.References.Add(contractRef);

			WebReferenceTestHelper.InitializeProjectBindings();

			webReference = new Gui.WebReference(project, updateFromUrl, name, proxyNamespace, protocol);
			webReferencesProjectItem = WebReferenceTestHelper.GetProjectItem(webReference.Items, "Web References\\", ItemType.WebReferences);
		}
		void GetFiles (string baseUrl, string relPath, string path, DiscoveryDocument doc, DynamicDiscoveryDocument ddoc)
		{
			string url = baseUrl + relPath;
			if (!url.EndsWith ("/")) url += "/";
			
			string[] files = Directory.GetFiles (path);
			foreach (string file in files)
			{
				string ext = Path.GetExtension (file).ToLower();
				if (ext == ".asmx")
				{
					ContractReference cref = new ContractReference ();
					cref.DocRef = url + Path.GetFileName (file);
					cref.Ref = cref.DocRef + "?wsdl";
					doc.References.Add (cref);
				}
				else if (ext == ".disco")
				{
					DiscoveryDocumentReference dref = new DiscoveryDocumentReference ();
					dref.Ref = url + Path.GetFileName (file);
					doc.References.Add (dref);
				}
			}
			string[] dirs = Directory.GetDirectories (path);
			
			foreach (string dir in dirs)
			{
				string rel = Path.Combine (relPath, Path.GetFileName(dir));
				if (!ddoc.IsExcluded (rel))
					GetFiles (baseUrl, rel, Path.Combine (path, dir), doc, ddoc);
			}
		}
Пример #7
0
		public override void FixtureSetUp()
		{
			base.FixtureSetUp();
			// Set up the project.
			MSBuildBasedProject project = WebReferenceTestHelper.CreateTestProject("C#");
			project.FileName = FileName.Create("c:\\projects\\test\\foo.csproj");
			
			// Web references item.
			WebReferencesProjectItem webReferencesItem = new WebReferencesProjectItem(project);
			webReferencesItem.Include = "Web References\\";
			ProjectService.AddProjectItem(project, webReferencesItem);
			
			// Web reference url.
			WebReferenceUrl webReferenceUrl = new WebReferenceUrl(project);
			webReferenceUrl.Include = "http://localhost/test.asmx";
			webReferenceUrl.UpdateFromURL = "http://localhost/test.asmx";
			webReferenceUrl.RelPath = "Web References\\localhost";
			ProjectService.AddProjectItem(project, webReferenceUrl);
			
			FileProjectItem discoFileItem = new FileProjectItem(project, ItemType.None);
			discoFileItem.Include = "Web References\\localhost\\test.disco";
			ProjectService.AddProjectItem(project, discoFileItem);

			FileProjectItem wsdlFileItem = new FileProjectItem(project, ItemType.None);
			wsdlFileItem.Include = "Web References\\localhost\\test.wsdl";
			ProjectService.AddProjectItem(project, wsdlFileItem);
			
			// Proxy
			FileProjectItem proxyItem = new FileProjectItem(project, ItemType.Compile);
			proxyItem.Include = "Web References\\localhost\\Reference.cs";
			proxyItem.DependentUpon = "Reference.map";
			ProjectService.AddProjectItem(project, proxyItem);
			
			// Reference map.
			FileProjectItem mapItem = new FileProjectItem(project, ItemType.None);
			mapItem.Include = "Web References\\localhost\\Reference.map";
			ProjectService.AddProjectItem(project, mapItem);
			
			// System.Web.Services reference.
			ReferenceProjectItem webServicesReferenceItem = new ReferenceProjectItem(project, "System.Web.Services");
			ProjectService.AddProjectItem(project, webServicesReferenceItem);
			
			// Set up the web reference.
			DiscoveryClientProtocol	protocol = new DiscoveryClientProtocol();
			DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference();
			discoveryRef.Url = "http://localhost/new.asmx";
			protocol.References.Add(discoveryRef);
			
			ContractReference contractRef = new ContractReference();
			contractRef.Url = "http://localhost/new.asmx?wsdl";
			contractRef.ClientProtocol = new DiscoveryClientProtocol();
			ServiceDescription desc = new ServiceDescription();
			contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc);
			protocol.References.Add(contractRef);
			
			WebReferenceTestHelper.InitializeProjectBindings();
			
			var webReference = new Gui.WebReference(project, "http://localhost/new.asmx", "localhost", "ProxyNamespace", protocol);
			changes = webReference.GetChanges(project);
		}
		public void SetUpFixture()
		{
			project = WebReferenceTestHelper.CreateTestProject("C#");
			project.FileName = "C:\\projects\\test\\foo.csproj";
			
			ReferenceProjectItem referenceItem = new ReferenceProjectItem(project, "System.Web.Services");
			ProjectService.AddProjectItem(project, referenceItem);
			
			protocol = new DiscoveryClientProtocol();
			DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference();
			discoveryRef.Url = updateFromUrl;
			protocol.References.Add(discoveryRef);
			
			ContractReference contractRef = new ContractReference();
			contractRef.Url = "http://localhost/test.asmx?wsdl";
			contractRef.ClientProtocol = new DiscoveryClientProtocol();
			ServiceDescription desc = new ServiceDescription();
			contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc);
			protocol.References.Add(contractRef);
			
			WebReferenceTestHelper.InitializeLanguageBindings();
			
			webReference = new SD.WebReference(project, updateFromUrl, name, proxyNamespace, protocol);
			webServicesReferenceProjectItem = (ReferenceProjectItem)WebReferenceTestHelper.GetProjectItem(webReference.Items, ItemType.Reference);
		}
		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);
		}
Пример #10
0
		public static MetadataSet GetMetadataSet (Stream stream)
		{
			var dr = new ContractReference ();
			var doc = (WebServices.Description.ServiceDescription) dr.ReadDocument (stream);
			
			var metadata = new MetadataSet ();
			metadata.MetadataSections.Add (
				new MetadataSection (MetadataSection.ServiceDescriptionDialect, "", doc));
			return metadata;
		}
		public void SetUpFixture()
		{
			project = WebReferenceTestHelper.CreateTestProject("VBNet");

			protocol = new DiscoveryClientProtocol();
			DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference();
			discoveryRef.Url = updateFromUrl;
			protocol.References.Add(discoveryRef);
			
			ContractReference contractRef = new ContractReference();
			contractRef.Url = "http://localhost/test.asmx?wsdl";
			contractRef.ClientProtocol = new DiscoveryClientProtocol();
			ServiceDescription desc = new ServiceDescription();
			contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc);
			protocol.References.Add(contractRef);
			
			WebReferenceTestHelper.InitializeProjectBindings();
			
			webReference = new SD.WebReference(project, updateFromUrl, name, proxyNamespace, protocol);
			
			proxyFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\Reference.vb", ItemType.Compile);
		}
Пример #12
0
        void GetFiles(string baseUrl, string relPath, string path, DiscoveryDocument doc, DynamicDiscoveryDocument ddoc)
        {
            string url = baseUrl + relPath;

            if (!url.EndsWith("/"))
            {
                url += "/";
            }

            string[] files = Directory.GetFiles(path);
            foreach (string file in files)
            {
                string ext = Path.GetExtension(file).ToLower();
                if (ext == ".asmx")
                {
                    ContractReference cref = new ContractReference();
                    cref.DocRef = url + Path.GetFileName(file);
                    cref.Ref    = cref.DocRef + "?wsdl";
                    doc.References.Add(cref);
                }
                else if (ext == ".disco")
                {
                    DiscoveryDocumentReference dref = new DiscoveryDocumentReference();
                    dref.Ref = url + Path.GetFileName(file);
                    doc.References.Add(dref);
                }
            }
            string[] dirs = Directory.GetDirectories(path);

            foreach (string dir in dirs)
            {
                string rel = Path.Combine(relPath, Path.GetFileName(dir));
                if (!ddoc.IsExcluded(rel))
                {
                    GetFiles(baseUrl, rel, Path.Combine(path, dir), doc, ddoc);
                }
            }
        }
        public override void FixtureSetUp()
        {
            base.FixtureSetUp();
            project = WebReferenceTestHelper.CreateTestProject("C#");
            project.FileName = FileName.Create("C:\\Projects\\Web.csproj");
            WebReferencesProjectItem item = new WebReferencesProjectItem(project);
            item.Include = "Web References\\";
            ProjectService.AddProjectItem(project, item);

            protocol = new DiscoveryClientProtocol();
            DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference();
            discoveryRef.Url = updateFromUrl;
            protocol.References.Add(discoveryRef);

            ContractReference contractRef = new ContractReference();
            contractRef.Url = "http://localhost/test.asmx?wsdl";
            contractRef.ClientProtocol = new DiscoveryClientProtocol();
            ServiceDescription desc = new ServiceDescription();
            contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc);
            protocol.References.Add(contractRef);

            WebReferenceTestHelper.InitializeProjectBindings();

            webReference = new Gui.WebReference(project, updateFromUrl, oldName, proxyNamespace, protocol);

            // Force generation of items.
            List<ProjectItem> items = webReference.Items;

            // Change the web reference name.
            webReference.Name = name;
            webReferenceUrl = (WebReferenceUrl)WebReferenceTestHelper.GetProjectItem(webReference.Items, ItemType.WebReferenceUrl);

            discoFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost1\\test.disco", ItemType.None);
            referenceMapFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost1\\Reference.map", ItemType.None);
            wsdlFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost1\\test.wsdl", ItemType.None);
            proxyFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost1\\Reference.cs", ItemType.Compile);
        }
 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);
             }
         }
     }
 }
Пример #15
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);
                    }
                }
            }
        }
Пример #16
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;
            }
        }
Пример #17
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);
            }
        }
Пример #18
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);
                }
            }
        }
		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);
		}
        /// <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;
        }
        /// <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);
                }
            }
        }
Пример #22
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);
			}
		}
        // See comment on the ServerProtocol.IsCacheUnderPressure method for explanation of the excludeSchemeHostPortFromCachingKey logic.
        internal DiscoveryServerType(Type type, string uri, bool excludeSchemeHostPortFromCachingKey)
            : base(typeof(DiscoveryServerProtocol))
        {
            if (excludeSchemeHostPortFromCachingKey)
            {
                this.UriFixups = new List<Action<Uri>>();
            }            
            //
            // parse the uri from a string into a Uri object
            //
            Uri uriObject = new Uri(uri, true);
            //
            // and get rid of the query string if there's one
            //
            uri = uriObject.GetLeftPart(UriPartial.Path);
            methodInfo = new LogicalMethodInfo(typeof(DiscoveryServerProtocol).GetMethod("Discover", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
            ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(this.UriFixups);
            reflector.Reflect(type, uri);

            XmlSchemas schemas = reflector.Schemas;
            this.description = reflector.ServiceDescription;
            
            // We need to force initialization of ServiceDescription's XmlSerializer since we
            // won't necessarily have the permissions to do it when we actually need it
            XmlSerializer serializer = ServiceDescription.Serializer;

            // add imports to the external schemas
            AddSchemaImports(schemas, uri, reflector.ServiceDescriptions);

            // add imports to the other service descriptions
            for (int i = 1; i < reflector.ServiceDescriptions.Count; i++) {
                ServiceDescription description = reflector.ServiceDescriptions[i];
                Import import = new Import();
                import.Namespace = description.TargetNamespace;

                // 


                string id = "wsdl" + i.ToString(CultureInfo.InvariantCulture);

                import.Location = uri + "?wsdl=" + id;
                this.AddUriFixup(delegate(Uri current)
                {
                    import.Location = CombineUris(current, import.Location);
                });
                reflector.ServiceDescription.Imports.Add(import);
                wsdlTable.Add(id, description);
            }

            discoDoc = new DiscoveryDocument();
            ContractReference contractReference = new ContractReference(uri + "?wsdl", uri);
            this.AddUriFixup(delegate(Uri current)
            {
                contractReference.Ref = CombineUris(current, contractReference.Ref);
                contractReference.DocRef = CombineUris(current, contractReference.DocRef);
            });
            discoDoc.References.Add(contractReference);

            foreach (Service service in reflector.ServiceDescription.Services) {
                foreach (Port port in service.Ports) {
                    SoapAddressBinding soapAddress = (SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding));
                    if (soapAddress != null) {
                        System.Web.Services.Discovery.SoapBinding binding = new System.Web.Services.Discovery.SoapBinding();
                        binding.Binding = port.Binding;
                        binding.Address = soapAddress.Location;
                        this.AddUriFixup(delegate(Uri current)
                        {
                            binding.Address = CombineUris(current, binding.Address);
                        });
                        discoDoc.References.Add(binding);
                    }
                }
            }
        }
Пример #24
0
		void GenerateDiscoDocument (HttpContext context)
		{
			ServiceDescriptionCollection descs = GetDescriptions ();
			
			DiscoveryDocument doc = new DiscoveryDocument ();
			ContractReference cref = new ContractReference ();
			cref.Ref = _url + "?wsdl";
			cref.DocRef = _url;
			doc.References.Add (cref);
			
			foreach (ServiceDescription desc in descs)
				foreach (Service ser in desc.Services)
					foreach (Port port in ser.Ports)
					{
						SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
						if (sab != null)
						{
							System.Web.Services.Discovery.SoapBinding dsb = new System.Web.Services.Discovery.SoapBinding ();
							dsb.Address = sab.Location;
							dsb.Binding = port.Binding;
							doc.AdditionalInfo.Add (dsb);
						}
					}

			context.Response.ContentType = "text/xml; charset=utf-8";
			XmlTextWriter xtw = new XmlTextWriter (context.Response.OutputStream, new UTF8Encoding (false));
			xtw.Formatting = Formatting.Indented;
			doc.Write (xtw);
		}
        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);
                }
            }
        }
Пример #26
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 ContractReference Read5_ContractReference(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.id18_ContractReference) || (type.Namespace != this.id6_Item)))
     {
         throw base.CreateUnknownTypeException(type);
     }
     if (flag)
     {
         return null;
     }
     ContractReference o = new ContractReference();
     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.id19_docRef)) && (base.Reader.NamespaceURI == this.id13_Item))
             {
                 o.DocRef = base.Reader.Value;
                 flagArray[1] = true;
                 continue;
             }
             if (!base.IsXmlnsAttribute(base.Reader.Name))
             {
                 base.UnknownNode(o, ":ref, :docRef");
             }
         }
     }
     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;
 }