示例#1
0
        void CreateProxy()
        {
            CreateServiceContractGenerator();

            foreach (var contract in contracts)
            {
                contractGenerator.GenerateServiceContractType(contract);
            }

            var success = true;

            codegenWarnings = contractGenerator.Errors;
            if (codegenWarnings != null)
            {
                foreach (var error in codegenWarnings)
                {
                    if (!error.IsWarning)
                    {
                        success = false;
                        break;
                    }
                }
            }

            if (!success)
            {
                var exception = new DynamicProxyException(
                    Constants.ErrorMessages.CodeGenerationError);
                exception.CodeGenerationErrors = codegenWarnings;
                throw exception;
            }
        }
示例#2
0
        void CompileProxy()
        {
            // reference the required assemblies with the correct path.
            var compilerParams = new CompilerParameters();

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

            AddAssemblyReference(
                typeof(WsdlNS.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);

            var results =
                codeDomProvider.CompileAssemblyFromSource(
                    compilerParams,
                    proxyCode);

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

                throw exception;
            }

            compilerWarnings = ToEnumerable(results.Errors);
            proxyAssembly    = Assembly.LoadFile(results.PathToAssembly);
        }
示例#3
0
        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;

            var success = true;

            if (importWarnings != null)
            {
                foreach (var error in importWarnings)
                {
                    if (!error.IsWarning)
                    {
                        success = false;
                        break;
                    }
                }
            }

            if (!success)
            {
                var exception = new DynamicProxyException(
                    Constants.ErrorMessages.ImportError);
                exception.MetadataImportErrors = importWarnings;
                throw exception;
            }
        }