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);
        }
Example #2
0
        public void Import(ICodeWriter codeWriter)
        {
            var codeCompileUnit = new CodeCompileUnit();
            var codeProvider    = CreateCodeProvider();
            var serviceModel    = CreateServiceModel();

            var xsdImportExtensions = new List <IXsdImportExtension>
            {
                new RemoveIExtensibleDataObjectImplementationExtension(),
                new ServiceModelBuilderExtension(serviceModel),
                new ComplexTypeElementTypeMappingExtension(serviceModel, XmlTypeMappings),
                new TypeAccessModifierExtension(TypeAccessModifiers),
                new TypeRenameExtension(TypeRenameMappings),
                new ReplaceArrayOfTWithListTExtension(),
                new RemoveExtraDataContractNameExtension(),
                new ComplexTypeOptionalElementsNillableExtension(serviceModel),
                new EmitDefaultValueExtension(serviceModel, XmlTypeMappings),
                new AbstractTypeExtension(serviceModel),
                new PascalCaseFieldNamesExtension()
            };

            foreach (var xsdImportExtension in xsdImportExtensions)
            {
                xsdImportExtension.BeforeImport(serviceModel.XmlSchemas);
            }

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

            foreach (var xsdImportExtension in xsdImportExtensions)
            {
                xsdImportExtension.ImportContract(xsdDataContractImporter);
            }

            xsdDataContractImporter.Import(serviceModel.XmlSchemas);

            foreach (var xsdImportExtension in xsdImportExtensions)
            {
                xsdImportExtension.GenerateContract(codeCompileUnit);
            }

            codeWriter.Write(codeProvider, codeCompileUnit);
        }