示例#1
0
        public void ShouldGetMetadataFromWsdlFile()
        {
            string            wsdlLocation = ConfigurationLoader.GetConfigurationFilePath(@"SampleData\DescriptionModel\MockService.wsdl");
            MetadataDiscovery instance     = new MetadataDiscovery(wsdlLocation);
            MetadataSet       metadata     = instance.InspectMetadata();

            AssertMetadataForWsdlFile(metadata);
        }
示例#2
0
 public void ShouldFailWithNoMexEndpoint()
 {
     using (ServiceHost host = CreateBasicHttpHost(Address, false, true))
     {
         MetadataDiscovery instance = new MetadataDiscovery(Address);
         MetadataSet       metadata = instance.InspectMetadata();
     }
 }
示例#3
0
 public void ThrowOnBasicHttpHostSslMexAddress()
 {
     using (ServiceHost host = CreateBasicHttpHost(Address))
     {
         MetadataDiscovery instance = new MetadataDiscovery(SslMexAddress);
         instance.InspectMetadata();
     }
 }
示例#4
0
 public void ShouldGetMetadataFromBasicHttpHostWsdlAddressWithNoGet()
 {
     using (ServiceHost host = CreateBasicHttpHost(Address, false, false))
     {
         MetadataDiscovery instance = new MetadataDiscovery(WsdlAddress);
         MetadataSet       metadata = instance.InspectMetadata();
         AssertMetadataForBasicHttp(metadata);
     }
 }
示例#5
0
        public void ShouldGetWritenMetadataDocumentsToFiles()
        {
            string            wsdlLocation          = ConfigurationLoader.GetConfigurationFilePath(@"SampleData\DescriptionModel\MockService.wsdl");
            MetadataDiscovery instance              = new MetadataDiscovery(wsdlLocation);
            string            mapFile               = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"\Test\", "MockService.map");
            DiscoveryClientResultCollection results = instance.WriteMetadata(mapFile);

            Assert.AreEqual <int>(4, results.Count);
        }
示例#6
0
        /// <summary>
        /// Creates the WSDL importer.
        /// </summary>
        /// <param name="wsdlFile">The WSDL file.</param>
        /// <returns></returns>
        public static WsdlImporter CreateImporter(string wsdlFile)
        {
            MetadataDiscovery discovery = new MetadataDiscovery(ConfigurationLoader.GetConfigurationFilePath(wsdlFile));
            ContractGenerator generator = CreateContractGenerator();
            WsdlImporter      importer  = generator.CreateWsdlImporter(discovery.InspectMetadata());

            importer.ImportAllEndpoints();
            importer.ImportAllContracts();
            importer.ImportAllBindings();
            ContractGenerator.ThrowOnMetadataConversionErrors(importer.Errors);
            return(importer);
        }
示例#7
0
        public void Import(ICodeWriter codeWriter)
        {
            var dataContractGenerationExtensions = new List <IXsdImportExtension>
            {
                new TypeRenameExtension(TypeRenameMappings),
                new RemoveExtraDataContractNameExtension(),
                new TypeAccessModifierExtension(TypeAccessModifiers),
                new RemoveServiceContractConfigurationNameExtension(),
                new IsRequiredMemberOverrideExtension(RequiredMemberOverrides),
                new ReplaceArrayOfTWithListTExtension()
            };

            var codeCompileUnit = new CodeCompileUnit();
            var codeProvider    = CreateCodeProvider();

            var discovery        = new MetadataDiscovery();
            var metadataSections = new List <MetadataSection>();

            foreach (var wsdl in Wsdls)
            {
                var metadataSet = discovery.Discover(wsdl);
                metadataSections.AddRange(metadataSet.MetadataSections);
            }

            var xsdDataContractImporter = new XsdDataContractImporterFactory().Create(codeProvider, codeCompileUnit, NamespaceMappings);

            var wsdlImporter = new WsdlImporterFactory().Create(new MetadataSet(metadataSections),
                                                                xsdDataContractImporter,
                                                                NillableOverrides,
                                                                XmlTypeMappings,
                                                                DataContractGenerationOptions);
            var serviceContractGenerator = CreateServiceContractGenerator(codeCompileUnit,
                                                                          NamespaceMappings,
                                                                          ServiceContractGenerationOptions);

            wsdlImporter.ImportAllBindings();
            wsdlImporter.ImportAllEndpoints();

            foreach (var contract in wsdlImporter.ImportAllContracts())
            {
                serviceContractGenerator.GenerateServiceContractType(contract);
            }

            foreach (var dataContractGenerationExtension in dataContractGenerationExtensions)
            {
                dataContractGenerationExtension.GenerateContract(codeCompileUnit);
            }

            codeWriter.Write(codeProvider, codeCompileUnit);
        }
        private MetadataSet GetMetadataSet(Uri address,
                                           Type service, Type serviceContract, Type secondaryServiceContract)
        {
            MetadataDiscovery metadata = new MetadataDiscovery(address);

            if (!address.IsFile)
            {
                using (ServiceHost host = CreateWsHttpHost(address, service, serviceContract, secondaryServiceContract))
                {
                    return(metadata.InspectMetadata());
                }
            }
            return(metadata.InspectMetadata());
        }
示例#9
0
        private ServiceModel CreateServiceModel()
        {
            var discovery        = new MetadataDiscovery();
            var metadataSections = new List <MetadataSection>();

            foreach (var xsd in Xsds)
            {
                var metadataSet = discovery.Discover(xsd);
                metadataSections.AddRange(metadataSet.MetadataSections);
            }
            var schemaSet = CreateXmlSchemaSet(metadataSections);

            return(new ServiceModel {
                XmlSchemas = schemaSet
            });
        }
示例#10
0
 public void ShouldGetMetadataFromBasicHttpHostAsync()
 {
     using (ServiceHost host = CreateBasicHttpHost(Address))
     {
         AutoResetEvent    reset    = new AutoResetEvent(false);
         MetadataDiscovery instance = new MetadataDiscovery(Address);
         instance.InspectMetadataCompleted += delegate(object sender, InspectMetadataCompletedEventArgs e)
         {
             try
             {
                 Assert.IsNull(e.Exception);
                 AssertMetadataForBasicHttp(e.Metadata);
             }
             finally
             {
                 reset.Set();
             }
         };
         instance.InspectMetadataAsync();
         reset.WaitOne(100000, true);
     }
 }
示例#11
0
        public void ThrowOnFileNotFound()
        {
            MetadataDiscovery discovery = new MetadataDiscovery(@"c:\foo");

            discovery.InspectMetadata();
        }
示例#12
0
        public void CanCreateInstance()
        {
            MetadataDiscovery instance = new MetadataDiscovery(Address);

            Assert.AreEqual(Address, instance.Address);
        }
示例#13
0
        public void ThrowOnNoValidSslAddress()
        {
            MetadataDiscovery instance = new MetadataDiscovery(SslAddress);

            instance.InspectMetadata();
        }