Beispiel #1
0
        private MetadataSection CreateMetadataSection(object document)
        {
            System.Web.Services.Description.ServiceDescription description =
                document as System.Web.Services.Description.ServiceDescription;

            XmlSchema       schema  = document as XmlSchema;
            XmlElement      element = document as XmlElement;
            MetadataSection section;

            if (description != null)
            {
                section = MetadataSection.CreateFromServiceDescription(description);
            }
            else if (schema != null)
            {
                section = MetadataSection.CreateFromSchema(schema);
            }
            else if ((element != null) && IsPolicyElement(element))
            {
                section = MetadataSection.CreateFromPolicy(element, null);
            }
            else
            {
                section          = new MetadataSection();
                section.Metadata = document;
            }

            return(section);
        }
Beispiel #2
0
        private static void AddDocumentToResults(object document, ICollection <MetadataSection> results)
        {
            ServiceDescription serviceDescription = document as ServiceDescription;
            XmlSchema          xmlSchema          = document as XmlSchema;
            XmlElement         xmlElement         = document as XmlElement;

            if (serviceDescription != null)
            {
                results.Add(MetadataSection.CreateFromServiceDescription(serviceDescription));
            }
            else if (xmlSchema != null)
            {
                results.Add(MetadataSection.CreateFromSchema(xmlSchema));
            }
            else if (xmlElement != null && (xmlElement.NamespaceURI == "http://schemas.xmlsoap.org/ws/2004/09/policy" || xmlElement.NamespaceURI == "http://www.w3.org/ns/ws-policy") && xmlElement.LocalName == "Policy")
            {
                results.Add(MetadataSection.CreateFromPolicy(xmlElement, null));
            }
            else
            {
                MetadataSection mexDoc = new MetadataSection();
                mexDoc.Metadata = document;
                results.Add(mexDoc);
            }
        }
Beispiel #3
0
        void AddDocumentToResults(object document, Collection <MetadataSection> results)
        {
            WsdlNS.ServiceDescription wsdl = document as WsdlNS.ServiceDescription;
            XmlSchema  schema = document as XmlSchema;
            XmlElement xmlDoc = document as XmlElement;

            if (wsdl != null)
            {
                results.Add(MetadataSection.CreateFromServiceDescription(wsdl));
            }
            else if (schema != null)
            {
                results.Add(MetadataSection.CreateFromSchema(schema));
            }
            else if (xmlDoc != null && xmlDoc.LocalName == "Policy")
            {
                results.Add(MetadataSection.CreateFromPolicy(xmlDoc, null));
            }
            else
            {
                MetadataSection mexDoc = new MetadataSection();
                mexDoc.Metadata = document;
                results.Add(mexDoc);
            }
        }
Beispiel #4
0
        private void AddDocumentToResults(object document, Collection <MetadataSection> results)
        {
            var wsdl   = document as ServiceDescription;
            var schema = document as XmlSchema;
            var xmlDoc = document as XmlElement;

            if (wsdl != null)
            {
                results.Add(MetadataSection.CreateFromServiceDescription(wsdl));
            }
            else if (schema != null)
            {
                results.Add(MetadataSection.CreateFromSchema(schema));
            }
            else if (xmlDoc != null && xmlDoc.LocalName == "Policy")
            {
                results.Add(MetadataSection.CreateFromPolicy(xmlDoc, null));
            }
            else
            {
                var mexDoc = new MetadataSection {
                    Metadata = document
                };
                results.Add(mexDoc);
            }
        }
Beispiel #5
0
        private static void ResolveImports(MetadataResolverOptions options, MetadataSet metadataSet)
        {
            // Resolve metadata using a DiscoveryClientProtocol.
            DiscoveryClientProtocol dcp = new DiscoveryClientProtocol();

            dcp.Credentials       = GetCredentials(options);
            dcp.AllowAutoRedirect = true;
            dcp.DiscoverAny(options.MetadataLocation);
            dcp.ResolveAll();

            foreach (object osd in dcp.Documents.Values)
            {
                if (osd is System.Web.Services.Description.ServiceDescription)
                {
                    MetadataSection mds = MetadataSection.CreateFromServiceDescription((System.Web.Services.Description.ServiceDescription)osd);
                    metadataSet.MetadataSections.Add(mds);
                    continue;
                }
                if (osd is XmlSchema)
                {
                    MetadataSection mds = MetadataSection.CreateFromSchema((XmlSchema)osd);
                    metadataSet.MetadataSections.Add(mds);
                    continue;
                }
            }
        }
        private static void AddDocumentToSet(MetadataSet metadataSet, object document)
        {
            ServiceDescription serviceDescription = document as ServiceDescription;
            XmlSchema          schema             = document as XmlSchema;
            XmlElement         policy             = document as XmlElement;

            if (serviceDescription != null)
            {
                metadataSet.MetadataSections.Add(MetadataSection.CreateFromServiceDescription(serviceDescription));
            }
            else if (schema != null)
            {
                metadataSet.MetadataSections.Add(MetadataSection.CreateFromSchema(schema));
            }
            else if ((policy != null) && IsPolicyElement(policy))
            {
                metadataSet.MetadataSections.Add(MetadataSection.CreateFromPolicy(policy, null));
            }
            else
            {
                MetadataSection item = new MetadataSection {
                    Metadata = document
                };
                metadataSet.MetadataSections.Add(item);
            }
        }
        void AddDocumentToSet(MetadataSet metadataSet, object document)
        {
            WsdlNS.ServiceDescription wsdl = document as WsdlNS.ServiceDescription;
            XmlSchema  schema = document as XmlSchema;
            XmlElement xmlDoc = document as XmlElement;

            if (wsdl != null)
            {
                metadataSet.MetadataSections.Add(MetadataSection.CreateFromServiceDescription(wsdl));
            }
            else if (schema != null)
            {
                metadataSet.MetadataSections.Add(MetadataSection.CreateFromSchema(schema));
            }
            else if (xmlDoc != null && MetadataSection.IsPolicyElement(xmlDoc))
            {
                metadataSet.MetadataSections.Add(MetadataSection.CreateFromPolicy(xmlDoc, null));
            }
            else
            {
                MetadataSection mexDoc = new MetadataSection();
                mexDoc.Metadata = document;
                metadataSet.MetadataSections.Add(mexDoc);
            }
        }
Beispiel #8
0
        internal static MetadataSet GetMetadataSetForMonolithicWsdl()
        {
            string    xmlSchemaFile = TestFiles.GetFilePath(TestFiles.RestaurantDataXsdFileName);
            XmlSchema xmlSchema;

            using (XmlTextReader xmlTextReader = new XmlTextReader(xmlSchemaFile))
            {
                xmlSchema = XmlSchema.Read(xmlTextReader, null);
            }

            string             serviceDescriptionFile = TestFiles.GetFilePath(TestFiles.RestaurantServiceWsdlFileName2);
            ServiceDescription serviceDescription;

            using (XmlTextReader xmlTextReader = new XmlTextReader(serviceDescriptionFile))
            {
                serviceDescription = ServiceDescription.Read(xmlTextReader);
            }

            List <MetadataSection> sections = new List <MetadataSection>
            {
                MetadataSection.CreateFromSchema(xmlSchema),
                MetadataSection.CreateFromServiceDescription(serviceDescription)
            };

            return(new MetadataSet(sections));
        }
Beispiel #9
0
        /// <summary>
        ///     first response performance critical
        /// </summary>
        /// <returns></returns>
        public override MetadataSet GetGeneratedMetadata()
        {
            ImporterController.TryDocRevImporting();

            int i = 0;
            // let the base build up metadata for the service contracts as these are static
            MetadataSet _MetadataSet = base.GetGeneratedMetadata();

            foreach (DirectoryInfo _DirectoryInfo in Directory
                     .EnumerateDirectories(FilesystemTemplateController.DirectoryPath)
                     .Select(path => new DirectoryInfo(path)))
            {
                // persist the datacontract xml schema for the datacontract to the user's temporary directory
                //TODO:combine this logic and Runtime's that calculates it's dll output location
                int key = Math.Abs(File.ReadAllText(
                                       RequestPaths.GetPhysicalApplicationPath(
                                           "doc",
                                           _DirectoryInfo.Name,
                                           Runtime.MYSCHEMA_XSD_FILE_NAME)).GetHashCode()
                                   ^ WindowsIdentity.GetCurrent().User.Value.GetHashCode()); // just incase the user changes due to an apppool change

                string tempDataContractXsdPath = string.Format("{0}\\{1}.xsd", Path.GetTempPath(), Base36.Encode(key));

                if (!File.Exists(tempDataContractXsdPath))
                {
                    // the datacontracts are the things that are dynamic & change according to what DocTypes are present
                    XsdDataContractExporter _XsdDataContractExporter = new XsdDataContractExporter();
                    Type DocType = Runtime.ActivateBaseDocType(_DirectoryInfo.Name, TemplateController.Instance.TopDocRev(_DirectoryInfo.Name));
                    _XsdDataContractExporter.Export(DocType);
                    // _XsdDataContractExporter.Schemas.CompilationSettings.EnableUpaCheck = true;
                    _XsdDataContractExporter.Schemas.Compile();

                    foreach (XmlSchema _XmlSchema in _XsdDataContractExporter.Schemas.Schemas(_XsdDataContractExporter.GetRootElementName(DocType).Namespace))
                    {
                        using (Stream _Stream = File.OpenWrite(tempDataContractXsdPath))
                        {
                            _MetadataSet.MetadataSections.Add(MetadataSection.CreateFromSchema(_XmlSchema));
                            _XmlSchema.Write(_Stream);
                            break;
                        }
                    }
                }

                using (Stream _Stream = File.OpenRead(tempDataContractXsdPath))
                    _MetadataSet.MetadataSections.Add(MetadataSection.CreateFromSchema(
                                                          XmlSchema.Read(_Stream, (s, o) =>
                    {
                        /*if (o != null && o.Exception != null) throw o.Exception;*/
                    })));
            }

            return(_MetadataSet);
        }
        private async Task LoadAsXmlSchemaAsync(XmlNS.XmlReader reader, string uri, string basePath, CancellationToken cancellationToken)
        {
            var schema = await AsyncHelper.RunAsync(() => XmlNS.Schema.XmlSchema.Read(reader, null), cancellationToken).ConfigureAwait(false);

            _metadataSections.Add(MetadataSection.CreateFromSchema(schema));
            schema.SourceUri = uri;

            if (_resolveExternalDocs)
            {
                await LoadAsXmlSchemaIncludesAsync(schema, uri, basePath, cancellationToken).ConfigureAwait(false);
            }
        }
        MetadataSet GetMetadataSetFromWsdl(string path)
        {
            var ms = new MetadataSet();
            var sd = WSServiceDescription.Read(XmlReader.Create(path));

            ms.MetadataSections.Add(MetadataSection.CreateFromServiceDescription(sd));
            foreach (XmlSchema xs in sd.Types.Schemas)
            {
                foreach (XmlSchemaImport import in xs.Includes)
                {
                    using (var xr = XmlReader.Create(Path.Combine(Path.GetDirectoryName(path), import.SchemaLocation)))
                        ms.MetadataSections.Add(MetadataSection.CreateFromSchema(XmlSchema.Read(xr, null)));
                }
            }
            return(ms);
        }
        private static void AddDocumentToResults(object document, Collection <MetadataSection> results)
        {
            var serviceDescr = document as SWSServiceDescription;

            if (serviceDescr != null)
            {
                results.Add(MetadataSection.CreateFromServiceDescription(serviceDescr));
                return;
            }

            var schema = document as XmlSchema;

            if (schema != null)
            {
                results.Add(MetadataSection.CreateFromSchema(schema));
                return;
            }

            throw new NotSupportedException(string.Format("Metadata type '{0}' is currently not supported.", document.GetType().FullName));
        }
Beispiel #13
0
        private static IEnumerable <MetadataSection> LoadAsXmlSchema(XmlReader reader, string path)
        {
            XmlSchema schema;

            try
            {
                schema = XmlSchema.Read(reader, null);
            }
            catch (Exception exception)
            {
                if (exception.IsFatal())
                {
                    throw;
                }

                string message = string.Format("XML Schema Parsing Error while reading: '{0}'. Verify that the XML is both well-formed and valid.", path);
                throw new MetadataDiscoveryException(message);
            }
            return(new List <MetadataSection> {
                MetadataSection.CreateFromSchema(schema)
            });
        }
Beispiel #14
0
        private void DownloadMetadata()
        {
            var results = new Collection <MetadataSection>();

            if (DiscoveryClient.Documents.Values != null)
            {
                foreach (var document in DiscoveryClient.Documents.Values)
                {
                    var wsdl   = document as System.Web.Services.Description.ServiceDescription;
                    var schema = document as XmlSchema;
                    var xmlDoc = document as XmlElement;

                    if (wsdl != null)
                    {
                        var metaSect = MetadataSection.CreateFromServiceDescription(wsdl);
                        results.Add(metaSect);
                    }
                    else if (schema != null)
                    {
                        results.Add(MetadataSection.CreateFromSchema(schema));
                    }
                    else if (xmlDoc != null && xmlDoc.LocalName == "Policy")
                    {
                        results.Add(MetadataSection.CreateFromPolicy(xmlDoc, null));
                    }
                    else
                    {
                        var mexDoc = new MetadataSection();
                        mexDoc.Metadata = document;
                        results.Add(mexDoc);
                    }
                }
            }

            Metadata = results;
        }
Beispiel #15
0
 private MetadataSection MapFromXmlSchema(XmlSchema schema)
 {
     return(MetadataSection.CreateFromSchema(schema));
 }
Beispiel #16
0
        public string GenFromWsdl(
            string uri,
            bool createAsync,
            string targetNamespace,
            string outputFile,
            Boolean generateClient)
        {
            var pd = new prepareData();

            var msg = checkAndPrepareData(uri, outputFile, targetNamespace, pd);

            if (!msg.IsNullOrWhiteSpace())
            {
                return(msg);
            }


            MetadataSet mdSet = new MetadataSet();

            mdSet.MetadataSections.Add(MetadataSection.CreateFromServiceDescription(WebDescription.ServiceDescription.Read(pd.MainTempFile)));

            foreach (var item in pd.Imperts)
            {
                using (var xr = XmlReader.Create(item))
                    mdSet.MetadataSections.Add(MetadataSection.CreateFromSchema(XmlSchema.Read(xr, null)));
            }

            WsdlImporter importer = new WsdlImporter(mdSet);

            var xsdDCImporter = new XsdDataContractImporter();

            xsdDCImporter.Options = new ImportOptions();
            xsdDCImporter.Options.Namespaces.Add("*", pd.TargetCSNamespace);

            importer.State.Add(typeof(XsdDataContractImporter), xsdDCImporter);

            var xmlOptions = new XmlSerializerImportOptions();

            xmlOptions.ClrNamespace = pd.TargetCSNamespace;
            importer.State.Add(typeof(XmlSerializerImportOptions), xmlOptions);

            var generator = new ServiceContractGenerator();

            generator.NamespaceMappings.Add("*", pd.TargetCSNamespace);

            //var options = ServiceContractGenerationOptions.TypedMessages;
            var options = ServiceContractGenerationOptions.None;

            if (generateClient)
            {
                options |= ServiceContractGenerationOptions.ClientClass;
            }

            if (createAsync)
            {
                options |= ServiceContractGenerationOptions.TaskBasedAsynchronousMethod;
            }

            generator.Options = options;

            foreach (var contract in importer.ImportAllContracts())
            {
                generator.GenerateServiceContractType(contract);
            }

            if (generator.Errors.Count != 0)
            {
                return(generator.Errors.Select(x => x.Message).JoinValuesToString(separator: Environment.NewLine));
            }

            StringBuilder sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
                CodeDomProvider.CreateProvider("C#")
                .GenerateCodeFromCompileUnit(
                    generator.TargetCompileUnit,
                    new IndentedTextWriter(sw),
                    new CodeGeneratorOptions()
                {
                    BracingStyle = "C"
                });

            File.WriteAllText(outputFile, sb.ToString());

            return(null);
        }