예제 #1
0
        private void CreateProxy()
        {
            CreateServiceContractGenerator();

            foreach (ContractDescription contract in _contracts)
            {
                _contractGenerator.GenerateServiceContractType(contract);
            }

            bool success = true;

            _codegenWarnings = _contractGenerator.Errors;
            if (_codegenWarnings != null)
            {
                success = _codegenWarnings.All(error => error.IsWarning);
            }

            if (!success)
            {
                var exception = new DynamicProxyException(Constants.ErrorMessages.CodeGenerationError)
                {
                    CodeGenerationErrors = _codegenWarnings
                };
                throw exception;
            }
        }
예제 #2
0
        private void ImportMetadata()
        {
            _codeCompileUnit = new CodeCompileUnit();
            CreateCodeDomProvider();

            var importer = new WsdlImporter(new MetadataSet(_metadataCollection));

            AddStateForDataContractSerializerImport(importer);
            AddStateForXmlSerializerImport(importer);

            _bindings       = importer.ImportAllBindings();
            _contracts      = importer.ImportAllContracts();
            _endpoints      = importer.ImportAllEndpoints();
            _importWarnings = importer.Errors;

            bool success = true;

            if (_importWarnings != null)
            {
                success = _importWarnings.All(error => error.IsWarning);
            }

            if (!success)
            {
                var exception = new DynamicProxyException(Constants.ErrorMessages.ImportError)
                {
                    MetadataImportErrors = _importWarnings
                };
                throw exception;
            }
        }
예제 #3
0
        private void CompileProxy()
        {
            // reference the required assemblies with the correct path.
            var compilerParams = new CompilerParameters();

            AddAssemblyReference(typeof(ServiceContractAttribute).Assembly, compilerParams.ReferencedAssemblies);

            AddAssemblyReference(typeof(ServiceDescription).Assembly, compilerParams.ReferencedAssemblies);

            AddAssemblyReference(typeof(DataContractAttribute).Assembly, compilerParams.ReferencedAssemblies);

            AddAssemblyReference(typeof(XmlElement).Assembly, compilerParams.ReferencedAssemblies);

            AddAssemblyReference(typeof(Uri).Assembly, compilerParams.ReferencedAssemblies);

            AddAssemblyReference(typeof(DataSet).Assembly, compilerParams.ReferencedAssemblies);

            CompilerResults results = _codeDomProvider.CompileAssemblyFromSource(compilerParams, _proxyCode);

            if ((results.Errors != null) && (results.Errors.HasErrors))
            {
                var exception = new DynamicProxyException(Constants.ErrorMessages.CompilationError)
                {
                    CompilationErrors = ToEnumerable(results.Errors)
                };

                throw exception;
            }

            _compilerWarnings = ToEnumerable(results.Errors);
            _proxyAssembly    = Assembly.LoadFile(results.PathToAssembly);

            Type[] types = _proxyAssembly.GetExportedTypes();

            _services       = new List <string>();
            _availableTypes = new Dictionary <string, Type>();

            AvailableServices = new Dictionary <string, WebServiceMethods>();

            foreach (Type type in types)
            {
                _services.Add(type.FullName);
                _availableTypes.Add(type.FullName, type);
                AvailableTypes = _availableTypes;
                GetServiceMethods(type.FullName);
            }
        }