Ejemplo n.º 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);
        }
Ejemplo n.º 2
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;
		}