void IWsdlImportExtension.ImportContract (WsdlImporter importer,
			WsdlContractConversionContext context)
		{
			if (!enabled)
				return;

			if (importer == null)
				throw new ArgumentNullException ("importer");
			if (context == null)
				throw new ArgumentNullException ("context");
			if (this.importer != null || this.context != null)
				throw new SystemException ("INTERNAL ERROR: unexpected recursion of ImportContract method call");

#if USE_DATA_CONTRACT_IMPORTER
			dc_importer = new XsdDataContractImporter ();
			schema_set_in_use = new XmlSchemaSet ();
			schema_set_in_use.Add (importer.XmlSchemas);
			foreach (WSDL wsdl in importer.WsdlDocuments)
				foreach (XmlSchema xs in wsdl.Types.Schemas)
					schema_set_in_use.Add (xs);
			dc_importer.Import (schema_set_in_use);
#endif

			this.importer = importer;
			this.context = context;
			try {
				DoImportContract ();
			} finally {
				this.importer = null;
				this.context = null;
			}
		}
Пример #2
0
 static void UseWcf()
 {
     /*
      动态下载服务元数据
      */
     MetadataExchangeClient metaExchangeClient =
         new MetadataExchangeClient(
             new Uri("http://localhost:8002/ManualService"),
             MetadataExchangeClientMode.HttpGet
         );
     //下载元数据
     MetadataSet metadataSet = metaExchangeClient.GetMetadata();
     WsdlImporter importer = new WsdlImporter(metadataSet);
     ServiceEndpointCollection endpointCollection = importer.ImportAllEndpoints();
     IManulService manulProxy = null;
     foreach (ServiceEndpoint endPointItem in endpointCollection)
     {
         manulProxy = new ChannelFactory<IManulService>(
             endPointItem.Binding,
             endPointItem.Address
             ).CreateChannel();
         ((IChannel)manulProxy).Open();
         Console.WriteLine("WCF调用结果为:{0}",
             manulProxy.GetData());
         ((IChannel)manulProxy).Close();
     }
 }
Пример #3
0
        void IWsdlImportExtension.ImportContract(WsdlImporter importer,
                                                 WsdlContractConversionContext context)
        {
            if (!enabled)
            {
                return;
            }

            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (this.importer != null || this.context != null)
            {
                throw new SystemException("INTERNAL ERROR: unexpected recursion of ImportContract method call");
            }

            this.importer = importer;
            this.context  = context;
            try {
                DoImportContract();
            } finally {
                this.importer = null;
                this.context  = null;
            }
        }
Пример #4
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);
        }
 protected override void Init(WsdlImporter importer)
 {
     if (dc_importer == null)
     {
         dc_importer = importer.GetState <XsdDataContractImporter> ();
     }
 }
 protected override void Init(WsdlImporter importer)
 {
     if (ccu == null)
     {
         ccu = importer.GetState <CodeCompileUnit> ();
     }
 }
        static internal void ImportMessageBinding(WsdlImporter importer, WsdlEndpointConversionContext endpointContext, Type schemaImporterType)
        {
            // All the work is done in ImportMessageContract call
            bool isReferencedContract = IsReferencedContract(importer, endpointContext);

            MarkSoapExtensionsAsHandled(endpointContext.WsdlBinding);

            foreach (WsdlNS.OperationBinding wsdlOperationBinding in endpointContext.WsdlBinding.Operations)
            {
                OperationDescription operation = endpointContext.GetOperationDescription(wsdlOperationBinding);
                if (isReferencedContract || OperationHasBeenHandled(operation))
                {
                    MarkSoapExtensionsAsHandled(wsdlOperationBinding);

                    if (wsdlOperationBinding.Input != null)
                    {
                        MarkSoapExtensionsAsHandled(wsdlOperationBinding.Input);
                    }

                    if (wsdlOperationBinding.Output != null)
                    {
                        MarkSoapExtensionsAsHandled(wsdlOperationBinding.Output);
                    }

                    foreach (WsdlNS.MessageBinding wsdlMessageBinding in wsdlOperationBinding.Faults)
                    {
                        MarkSoapExtensionsAsHandled(wsdlMessageBinding);
                    }
                }
            }

        }
		private static void GenerateCodeDomTree(WsdlImporter wsdlImporter, ServiceContractGenerator contractGenerator)
		{
			Collection<ContractDescription> contracts = wsdlImporter.ImportAllContracts();
			Collection<Binding> bindings = wsdlImporter.ImportAllBindings();
			ServiceEndpointCollection endpoints = wsdlImporter.ImportAllEndpoints();

			if (wsdlImporter.Errors.Any(e => !e.IsWarning))
			{
				throw new CodeGenerationException(wsdlImporter.Errors);
			}

			foreach (ContractDescription contract in contracts)
			{
				//TODO:Alex:Make the naming scheme customisable.
				contract.Name = "I" + contract.Name.Replace("Interface", string.Empty);
				contractGenerator.GenerateServiceContractType(contract);
			}

			foreach (Binding binding in bindings)
			{
				string bindingSectionName, configurationName;
				contractGenerator.GenerateBinding(binding, out bindingSectionName, out configurationName);
			}

			foreach (ServiceEndpoint endpoint in endpoints)
			{
				ChannelEndpointElement channelElement;
				contractGenerator.GenerateServiceEndpoint(endpoint, out channelElement);
			}
		}
Пример #9
0
        private static ServiceEndpointCollection ResolveContracts(
            IEnumerable <ContractDescription> contracts,
            Func <MetadataSet> metadataGetter)
        {
            if (contracts == null)
            {
                throw new ArgumentNullException("contracts");
            }

            List <ContractDescription> list = new List <ContractDescription> (contracts);

            if (list.Count == 0)
            {
                throw new ArgumentException("There must be atleast one ContractDescription", "contracts");
            }

            MetadataSet  metadata = metadataGetter();
            WsdlImporter importer = new WsdlImporter(metadata);
            ServiceEndpointCollection endpoints = importer.ImportAllEndpoints();

            ServiceEndpointCollection ret = new ServiceEndpointCollection();

            foreach (ContractDescription contract in list)
            {
                Collection <ServiceEndpoint> colln =
                    endpoints.FindAll(new QName(contract.Name, contract.Namespace));

                for (int i = 0; i < colln.Count; i++)
                {
                    ret.Add(colln [i]);
                }
            }

            return(ret);
        }
        void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext contractContext)
        {
            if (contractContext == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("contractContext"));

            MessageContractImporter.ImportMessageContract(importer, contractContext, MessageContractImporter.XmlSerializerSchemaImporter.Get(importer));
        }
		void IWsdlImportExtension.ImportContract (WsdlImporter importer,
			WsdlContractConversionContext context)
		{
			if (!enabled)
				return;

			if (importer == null)
				throw new ArgumentNullException ("importer");
			if (context == null)
				throw new ArgumentNullException ("context");
			if (this.importer != null || this.context != null)
				throw new SystemException ("INTERNAL ERROR: unexpected recursion of ImportContract method call");

			dc_importer = new XsdDataContractImporter ();
			schema_set_in_use = new XmlSchemaSet ();
			schema_set_in_use.Add (importer.XmlSchemas);
			foreach (WSDL wsdl in importer.WsdlDocuments)
				foreach (XmlSchema xs in wsdl.Types.Schemas)
					schema_set_in_use.Add (xs);

			// commenting out this import operation, but might be required (I guess not).
			//dc_importer.Import (schema_set_in_use);
			schema_set_in_use.Compile ();

			this.importer = importer;
			this.context = context;
			try {
				DoImportContract ();
			} finally {
				this.importer = null;
				this.context = null;
			}
		}
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

#pragma warning suppress 56506 // [....], these properties cannot be null in this context
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }

#pragma warning suppress 56506 // [....], CustomBinding.Elements never be null
            TransportBindingElement transportBindingElement = GetBindingElements(context).Find<TransportBindingElement>();

            bool transportHandledExternaly = (transportBindingElement != null) && !StateHelper.IsRegisteredTransportBindingElement(importer, context);
            if (transportHandledExternaly)
                return;

#pragma warning suppress 56506 // [....], these properties cannot be null in this context
            WsdlNS.SoapBinding soapBinding = (WsdlNS.SoapBinding)context.WsdlBinding.Extensions.Find(typeof(WsdlNS.SoapBinding));
            if (soapBinding != null && transportBindingElement == null)
            {
                CreateLegacyTransportBindingElement(importer, soapBinding, context);
            }

            // Try to import WS-Addressing address from the port
            if (context.WsdlPort != null)
            {
                ImportAddress(context, transportBindingElement);
            }

        }
Пример #13
0
		void NoExtensionsSetup ()
		{
			XmlReaderSettings xs = new XmlReaderSettings ();
			xs.IgnoreWhitespace = true;
			xtr = XmlTextReader.Create ("Test/System.ServiceModel.Description/dump.xml", xs);

			xtr.Read ();

			//FIXME: skipping Headers
			while (xtr.LocalName != "Body") {
				if (!xtr.Read ())
					return;
			}

			//Move to <Metadata ..
			xtr.Read ();
			ms = MetadataSet.ReadFrom (xtr);

			//MyWsdlImportExtension mw = new MyWsdlImportExtension ();
			List<IWsdlImportExtension> list = new List<IWsdlImportExtension> ();
			//list.Add (mw);
			list.Add (new DataContractSerializerMessageContractImporter ());

			/*list.Add (new MessageEncodingBindingElementImporter ());
			list.Add (new TransportBindingElementImporter ());
			list.Add (new StandardBindingImporter ());*/

			wi = new WsdlImporter (ms, null, list);
		}
 void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
 {
     if (context != null && context.WsdlBinding != null && ContainsHttpBindingExtension(context.WsdlBinding))
     {
         httpBindingContracts.Add(context.ContractConversionContext.Contract);
     }
 }
		void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer,
			WsdlEndpointConversionContext context)
		{
			for (int i = 0; i < context.WsdlBinding.Extensions.Count; i ++) {
				if (context.WsdlBinding.Extensions [i] is SoapBinding) {
					SoapBinding transport = context.WsdlBinding.Extensions [i] as SoapBinding;
					if (transport.Transport != SoapBinding.HttpTransport)
						//FIXME: not http
						return;

					if (! (context.Endpoint.Binding is CustomBinding))
						//FIXME: 
						throw new Exception ();

					((CustomBinding) context.Endpoint.Binding).Elements.Add (new HttpTransportBindingElement ());
					//((CustomBinding) context.Endpoint.Binding).Scheme = "http";

					for (int j = 0; j < context.WsdlPort.Extensions.Count; j ++) {
						SoapAddressBinding address = context.WsdlPort.Extensions [j] as SoapAddressBinding;
						if (address == null)
							continue;

						context.Endpoint.Address = new EndpointAddress (address.Location);
						context.Endpoint.ListenUri = new Uri (address.Location);
					}

					break;
				}
			}
		}
Пример #16
0
        static void GenerateVBCodeForService(Uri metadataAddress, string outputFile)
        {
            MetadataExchangeClient mexClient = new MetadataExchangeClient(metadataAddress, MetadataExchangeClientMode.HttpGet);
              mexClient.ResolveMetadataReferences = true;
              MetadataSet metaDocs = mexClient.GetMetadata();

              WsdlImporter importer = new WsdlImporter(metaDocs);
              ServiceContractGenerator generator = new ServiceContractGenerator();

              System.Collections.ObjectModel.Collection<ContractDescription> contracts = importer.ImportAllContracts();
              foreach (ContractDescription contract in contracts)
              {
            generator.GenerateServiceContractType(contract);
              }
              if (generator.Errors.Count != 0)
            throw new ApplicationException("There were errors during code compilation.");

              // Write the code dom.
              System.CodeDom.Compiler.CodeGeneratorOptions options = new System.CodeDom.Compiler.CodeGeneratorOptions();
              options.BracingStyle = "C";
              System.CodeDom.Compiler.CodeDomProvider codeDomProvider = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("VB");
              System.CodeDom.Compiler.IndentedTextWriter textWriter = new System.CodeDom.Compiler.IndentedTextWriter(new System.IO.StreamWriter(outputFile));
              codeDomProvider.GenerateCodeFromCompileUnit(generator.TargetCompileUnit, textWriter, options);
              textWriter.Close();
        }
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext endpointContext)
        {
            if (endpointContext == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("endpointContext"));

            MessageContractImporter.ImportMessageBinding(importer, endpointContext, typeof(MessageContractImporter.XmlSerializerSchemaImporter));
        }
Пример #18
0
		static ServiceEndpointCollection QueryMexEndpoint(string mexAddress, BindingElement bindingElement)
		{
			var binding = new CustomBinding(bindingElement);
			var MEXClient = new MetadataExchangeClient(binding);
			var metadata = MEXClient.GetMetadata(new EndpointAddress(mexAddress));
			var importer = new WsdlImporter(metadata);
			return importer.ImportAllEndpoints();
		}
 void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext contractContext)
 {
     if (contractContext == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("contractContext"));
     }
     MessageContractImporter.ImportMessageContract(importer, contractContext, MessageContractImporter.XmlSerializerSchemaImporter.Get(importer));
 }
 void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext endpointContext)
 {
     if (endpointContext == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("endpointContext"));
     }
     MessageContractImporter.ImportMessageBinding(importer, endpointContext, typeof(MessageContractImporter.XmlSerializerSchemaImporter));
 }
Пример #21
0
		public void ImportEndpoint (WsdlImporter importer, WsdlEndpointConversionContext context)
		{
			// Only import the binding, not the endpoint.
			if (context.WsdlPort == null)
				return;
			
			DoImportEndpoint (context);
		}
		void IWsdlImportExtension.ImportEndpoint (WsdlImporter importer,
			WsdlEndpointConversionContext context)
		{
			if (!Enabled)
				return;

			impl.ImportEndpoint (importer, context);
		}
 private static void CreateLegacyTransportBindingElement(WsdlImporter importer, SoapBinding soapBinding, WsdlEndpointConversionContext context)
 {
     TransportBindingElement item = CreateTransportBindingElements(soapBinding.Transport, null);
     if (item != null)
     {
         ConvertToCustomBinding(context).Elements.Add(item);
         StateHelper.RegisterTransportBindingElement(importer, context);
     }
 }
        public ServiceMetadataInformation ImportMetadata(Collection<MetadataSection> metadataCollection, MetadataImporterSerializerFormatMode formatMode)
        {
            CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
            CodeDomProvider codeDomProvider = m_CodeDomProviderFactory.CreateProvider();

            WsdlImporter importer = new WsdlImporter(new MetadataSet(metadataCollection));
            switch (formatMode)
            {
                case MetadataImporterSerializerFormatMode.DataContractSerializer:
                    AddStateForDataContractSerializerImport(importer, formatMode, codeCompileUnit, codeDomProvider);
                    break;
                case MetadataImporterSerializerFormatMode.XmlSerializer:
                    AddStateForXmlSerializerImport(importer, codeCompileUnit, codeDomProvider);
                    break;
                case MetadataImporterSerializerFormatMode.Auto:
                    AddStateForDataContractSerializerImport(importer, formatMode, codeCompileUnit, codeDomProvider);
                    AddStateForXmlSerializerImport(importer, codeCompileUnit, codeDomProvider);
                    break;
            }

            if (!importer.State.ContainsKey(typeof(WrappedOptions)))
            {
                importer.State.Add(typeof(WrappedOptions), new WrappedOptions
                {
                    WrappedFlag = false
                });
            }

            Collection<Binding> bindings = importer.ImportAllBindings();
            Collection<ContractDescription> contracts = importer.ImportAllContracts();
            ServiceEndpointCollection endpoints = importer.ImportAllEndpoints();
            Collection<MetadataConversionError> importErrors = importer.Errors;

            bool success = true;
            if (importErrors != null)
            {
                foreach (MetadataConversionError error in importErrors)
                {
                    if (!error.IsWarning)
                    {
                        success = false;
                        break;
                    }
                }
            }
            if (!success)
            {
                //TODO: Throw exception
            }
               return new ServiceMetadataInformation(codeCompileUnit, codeDomProvider)
               {
                   Bindings = bindings,
                   Contracts = contracts,
                   Endpoints = endpoints
               };
        }
Пример #25
0
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer,
                                                 WsdlEndpointConversionContext context)
        {
            if (!Enabled)
            {
                return;
            }

            impl.ImportEndpoint(importer, context);
        }
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext endpointContext)
        {
            if (endpointContext == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext");

#pragma warning suppress 56506 // [....], endpointContext.Endpoint is never null
            if (endpointContext.Endpoint.Binding == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext.Binding");

            if (endpointContext.Endpoint.Binding is CustomBinding)
            {
                BindingElementCollection elements = ((CustomBinding)endpointContext.Endpoint.Binding).Elements;

                Binding binding;
                TransportBindingElement transport = elements.Find<TransportBindingElement>();

                if (transport is HttpTransportBindingElement)
                {
                    if (WSHttpBindingBase.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (WSDualHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (BasicHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (NetHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                }
                else if (transport is MsmqTransportBindingElement && NetMsmqBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
                else if (transport is NamedPipeTransportBindingElement && NetNamedPipeBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
#pragma warning disable 0618				
                else if (transport is PeerTransportBindingElement && NetPeerTcpBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
#pragma warning restore 0618				
                else if (transport is TcpTransportBindingElement && NetTcpBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
            }
        }
Пример #27
0
        public static void Run(Uri uri, string cache)
        {
            ServicePointManager.ServerCertificateValidationCallback = Validator;

            MetadataSet doc;
            string tempfile = null;
            bool needsDownload;
            if (cache == null) {
                needsDownload = true;
                tempfile = Path.GetTempFileName ();
                cache = tempfile;
            } else {
                needsDownload = !File.Exists (cache);
            }

            if (needsDownload) {
                Console.WriteLine ("Downloading service metadata ...");
                DownloadXml (uri, cache);
                Console.WriteLine ("Downloaded service metadata into {0}.", cache);
            }

            try {
                doc = LoadMetadata (uri, cache);
            } finally {
                if (tempfile != null)
                    File.Delete (tempfile);
            }

            var importer = new WsdlImporter (doc);

            var bindings = importer.ImportAllBindings ();
            var endpoints = importer.ImportAllEndpoints ();

            foreach (var error in importer.Errors) {
                if (error.IsWarning)
                    Console.WriteLine ("WARNING: {0}", error.Message);
                else
                    Console.WriteLine ("ERROR: {0}", error.Message);
            }

            Console.WriteLine ("DONE IMPORTING: {0} {1}", bindings.Count, endpoints.Count);

            foreach (var binding in bindings)
                Console.WriteLine ("BINDING: {0}", binding);
            foreach (var endpoint in endpoints)
                Console.WriteLine ("ENDPOINT: {0}", endpoint.Address);

            foreach (var endpoint in endpoints) {
                try {
                    Run (endpoint);
                } catch (Exception ex) {
                    Console.WriteLine ("ERROR ({0}): {1}", endpoint.Address, ex);
                }
            }
        }
Пример #28
0
      static ServiceEndpointCollection QueryMexEndpoint(string mexAddress,Binding binding,TokenProvider tokenProvider)
      {
         dynamic extendedBinding = binding;
         extendedBinding.MaxReceivedMessageSize *= MessageSizeMultiplier;

         MetadataExchangeClient mexClient = new MetadataExchangeClient(extendedBinding);
         mexClient.SetServiceBusCredentials(tokenProvider);
         MetadataSet metadata = mexClient.GetMetadata(new EndpointAddress(mexAddress));
         MetadataImporter importer = new WsdlImporter(metadata);
         return importer.ImportAllEndpoints();
      }
        public ClientServiceGenerator(MetadataSet metadataSet, PrimaryCodeGenerationOptions options, CodeDomProvider codeProvider)
        {
        	Enforce.IsNotNull(metadataSet, "metadataSet");
			this.options = Enforce.IsNotNull(options, "options");
			this.codeProvider = Enforce.IsNotNull(codeProvider, "codeProvider");

            compileUnit = new CodeCompileUnit();
            wsdlImporter = new WsdlImporter(metadataSet);

			InitializeConfiguration();
        }
Пример #30
0
      static ServiceEndpointCollection QueryMexEndpoint(string mexAddress,BindingElement bindingElement)
      {
         dynamic element = bindingElement;
         element.MaxReceivedMessageSize *= MessageSizeMultiplier;

         CustomBinding binding = new CustomBinding(element);
         
         MetadataExchangeClient mexClient = new MetadataExchangeClient(binding);
         MetadataSet metadata = mexClient.GetMetadata(new EndpointAddress(mexAddress));
         MetadataImporter importer = new WsdlImporter(metadata);
         return importer.ImportAllEndpoints();
      }
Пример #31
0
        public static void GenerateFromWsdl(Uri uri, string wsdlFilename,
		                                     string xmlFilename, string xsdFilename)
        {
            var doc = Utils.LoadMetadata (uri, wsdlFilename);
            var importer = new WsdlImporter (doc);
            var endpoints = importer.ImportAllEndpoints ();

            var config = new Configuration ();
            foreach (var endpoint in endpoints)
                config.AddEndpoint (endpoint);

            Generator.Write (xmlFilename, xsdFilename, config);
        }
        /// <summary>Called when importing a contract.</summary>
        /// <param name="importer">The importer.</param>
        /// <param name="context">The import context to be modified.</param>
        public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
        {
            // Ensure that the client class has been appropriately created in order for us to add methods to it.
            context.Contract.Behaviors.Add(new TaskAsyncServiceContractGenerationExtension());

            // For each operation, add a task-based async equivalent.
            foreach (Operation operation in context.WsdlPortType.Operations)
            {
                var description = context.Contract.Operations.Find(operation.Name);
                if (description != null)
                    description.Behaviors.Add(new TaskAsyncOperationContractGenerationExtension());
            }
        }
        public CodeCompileUnit GenerateCodeFromImportedContracts(WsdlImporter importer)
        {
            var generator = new ServiceContractGenerator();

            var contracts = importer.ImportAllContracts();
            foreach (var contract in contracts)
            {
                generator.GenerateServiceContractType(contract);
            }
            if (generator.Errors.Count != 0)
                throw new Exception("There were errors during code compilation.");
            var targetCompileUnit = generator.TargetCompileUnit;
            return targetCompileUnit;
        }
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

#pragma warning suppress 56506 // [....], these properties cannot be null in this context
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }

            BindingElementCollection bindingElements = GetBindingElements(context);
            MessageEncodingBindingElement messageEncodingBindingElement = bindingElements.Find<MessageEncodingBindingElement>();
            TextMessageEncodingBindingElement textEncodingBindingElement = messageEncodingBindingElement as TextMessageEncodingBindingElement;

            if (messageEncodingBindingElement != null)
            {
                Type elementType = messageEncodingBindingElement.GetType();
                if (elementType != typeof(TextMessageEncodingBindingElement)
                    && elementType != typeof(BinaryMessageEncodingBindingElement)
                    && elementType != typeof(MtomMessageEncodingBindingElement))
                    return;
            }

            EnsureMessageEncoding(context, messageEncodingBindingElement);

            foreach (OperationBinding wsdlOperationBinding in context.WsdlBinding.Operations)
            {
                OperationDescription operation = context.GetOperationDescription(wsdlOperationBinding);

                for (int i = 0; i < operation.Messages.Count; i++)
                {
                    MessageDescription message = operation.Messages[i];
                    MessageBinding wsdlMessageBinding = context.GetMessageBinding(message);
                    ImportMessageSoapAction(context.ContractConversionContext, message, wsdlMessageBinding, i != 0 /*isResponse*/);
                }

                foreach (FaultDescription fault in operation.Faults)
                {
                    FaultBinding wsdlFaultBinding = context.GetFaultBinding(fault);
                    if (wsdlFaultBinding != null)
                    {
                        ImportFaultSoapAction(context.ContractConversionContext, fault, wsdlFaultBinding);
                    }
                }
            }

        }
Пример #35
0
        public static void GenerateConfig(MetadataSet metadata, Configuration config)
        {
            WsdlImporter importer = new WsdlImporter (metadata);

            var endpoints = importer.ImportAllEndpoints ();

            var generator = new ServiceContractGenerator (config);
            generator.Options = ServiceContractGenerationOptions.None;

            foreach (var endpoint in endpoints) {
                ChannelEndpointElement channelElement;
                generator.GenerateServiceEndpoint (endpoint, out channelElement);
            }
        }
 private static void TraceWsdlImportErrors(WsdlImporter importer)
 {
     foreach (MetadataConversionError error in importer.Errors)
     {
         if (DiagnosticUtility.ShouldTraceWarning)
         {
             Hashtable hashtable2 = new Hashtable(2);
             hashtable2.Add("IsWarning", error.IsWarning);
             hashtable2.Add("Message", error.Message);
             Hashtable dictionary = hashtable2;
             TraceUtility.TraceEvent(TraceEventType.Warning, 0x8003d, System.ServiceModel.SR.GetString("TraceCodeWsmexNonCriticalWsdlExportError"), new DictionaryTraceRecord(dictionary), null, null);
         }
     }
 }
Пример #37
0
		public static void CheckImportErrors (WsdlImporter importer, TestLabel label)
		{
			bool foundErrors = false;
			foreach (var error in importer.Errors) {
				if (error.IsWarning)
					Console.WriteLine ("WARNING ({0}): {1}", label, error.Message);
				else {
					Console.WriteLine ("ERROR ({0}): {1}", label, error.Message);
					foundErrors = true;
				}
			}

			if (foundErrors)
				Assert.Fail ("Found import errors", label);
		}
Пример #38
0
        void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
        {
            string documentation = GetDocumentation(context.WsdlPortType);
            context.Contract.Behaviors.Add(new XmlCommentsSvcExtension(this, documentation));

            foreach (Operation operation in context.WsdlPortType.Operations)
            {
                documentation = GetDocumentation(operation);
                if (!String.IsNullOrEmpty(documentation))
                {
                    OperationDescription operationDescription = context.Contract.Operations.Find(operation.Name);
                    operationDescription.Behaviors.Add(new XmlCommentsOpExtension(this, documentation));
                }
            }
        }
Пример #39
0
 static void TraceWsdlImportErrors(WsdlImporter importer)
 {
     foreach (MetadataConversionError error in importer.Errors)
     {
         if (DiagnosticUtility.ShouldTraceWarning)
         {
             Hashtable h = new Hashtable(2)
             {
                 { "IsWarning", error.IsWarning },
                 { "Message", error.Message }
             };
             TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.WsmexNonCriticalWsdlExportError,
                                     SR.GetString(SR.TraceCodeWsmexNonCriticalWsdlExportError), new DictionaryTraceRecord(h), null, null);
         }
     }
 }
Пример #40
0
        public void ImportContract(WsdlImporter importer,
                                   WsdlContractConversionContext context)
        {
            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (this.importer != null || this.context != null)
            {
                throw new SystemException("INTERNAL ERROR: unexpected recursion of ImportContract method call");
            }

            schema_set_in_use = new XmlSchemaSet();
            schema_set_in_use.Add(importer.XmlSchemas);
            foreach (WSDL wsdl in importer.WsdlDocuments)
            {
                foreach (XmlSchema xs in wsdl.Types.Schemas)
                {
                    schema_set_in_use.Add(xs);
                }
            }

            schema_set_in_use.Compile();

            this.importer = importer;
            this.context  = context;
            try
            {
                DoImportContract();
            }
            finally
            {
                this.importer = null;
                this.context  = null;
            }
        }
        private static ServiceEndpointCollection ImportEndpoints(MetadataSet metadataSet, IEnumerable <ContractDescription> contracts, MetadataExchangeClient client)
        {
            ServiceEndpointCollection endpoints = new ServiceEndpointCollection();
            WsdlImporter importer = new WsdlImporter(metadataSet);

            importer.State.Add("MetadataExchangeClientKey", client);
            foreach (ContractDescription description in contracts)
            {
                importer.KnownContracts.Add(WsdlExporter.WsdlNamingHelper.GetPortTypeQName(description), description);
            }
            foreach (ContractDescription description2 in contracts)
            {
                foreach (ServiceEndpoint endpoint in importer.ImportEndpoints(description2))
                {
                    endpoints.Add(endpoint);
                }
            }
            if (importer.Errors.Count > 0)
            {
                TraceWsdlImportErrors(importer);
            }
            return(endpoints);
        }
Пример #42
0
 void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer,
                                          WsdlEndpointConversionContext context)
 {
 }
Пример #43
0
 void IWsdlImportExtension.ImportContract(WsdlImporter importer,
                                          WsdlContractConversionContext context)
 {
 }
 void System.ServiceModel.Description.IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext endpointContext)
 {
 }
Пример #45
0
 public void ImportEndpoint(WsdlImporter importer,
                            WsdlEndpointConversionContext context)
 {
 }
 void System.ServiceModel.Description.IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext contractContext)
 {
 }
 protected abstract void Init(WsdlImporter importer);