Пример #1
0
        /// <summary>
        /// Renames the temp assembly.
        /// </summary>
        /// <param name="pathToAssembly">Path to assembly.</param>
        internal static void RenameTempAssembly(string pathToAssembly, string wsdl)
        {
            string path        = Path.GetDirectoryName(pathToAssembly);
            string newFilename = path + @"\" + CompiledAssemblyCache.GetMd5Sum(wsdl) + "_Thinktecture_tmp.dll";

            File.Copy(pathToAssembly, newFilename);
        }
Пример #2
0
        /// <summary>
        /// Builds the proxy.
        /// </summary>
        private void BuildProxy()
        {
            if (enableMessageAccess)
            {
                PipelineConfiguration.InjectExtension(typeof(SoapMessageAccessClientExtension));
                pipelineProperlyConfigured = true;
            }

            //check cache first
            Assembly cachedAssembly = CompiledAssemblyCache.CheckCacheForAssembly(wsdl);

            if (cachedAssembly == null)
            {
                wsdlSource = WsdlHelper.GetWsdl(wsdl);
                ass        = BuildAssemblyFromWsdl(wsdlSource);
            }
            else
            {
                ass = cachedAssembly;
            }

            proxyInstance = CreateInstance(typeName);
        }
Пример #3
0
        /// <summary>
        /// Builds the assembly from WSDL.
        /// </summary>
        /// <param name="strWsdl">STR WSDL.</param>
        /// <returns></returns>
        private Assembly BuildAssemblyFromWsdl(string strWsdl)
        {
            // Use an XmlTextReader to get the Web Service description
            StringReader  wsdlStringReader = new StringReader(strWsdl);
            XmlTextReader tr = new XmlTextReader(wsdlStringReader);

            ServiceDescription.Read(tr);
            tr.Close();

            // WSDL service description importer
            CodeNamespace cns = new CodeNamespace(CodeConstants.CODENAMESPACE);

            sdi = new ServiceDescriptionImporter();
            //sdi.AddServiceDescription(sd, null, null);

            // check for optional imports in the root WSDL
            CheckForImports(wsdl);

            sdi.ProtocolName = protocolName;
            sdi.Import(cns, null);

            // change the base class
            // get all available Service classes - not only the default one
            ArrayList newCtr = new ArrayList();

            foreach (CodeTypeDeclaration ctDecl in cns.Types)
            {
                if (ctDecl.BaseTypes.Count > 0)
                {
                    if (ctDecl.BaseTypes[0].BaseType == CodeConstants.DEFAULTBASETYPE)
                    {
                        newCtr.Add(ctDecl);
                    }
                }
            }

            foreach (CodeTypeDeclaration ctDecl in newCtr)
            {
                cns.Types.Remove(ctDecl);
                ctDecl.BaseTypes[0] = new CodeTypeReference(CodeConstants.CUSTOMBASETYPE);
                cns.Types.Add(ctDecl);
            }

            // source code generation
            CSharpCodeProvider cscp             = new CSharpCodeProvider();
            ICodeGenerator     icg              = cscp.CreateGenerator();
            StringBuilder      srcStringBuilder = new StringBuilder();
            StringWriter       sw = new StringWriter(srcStringBuilder, CultureInfo.CurrentCulture);

            if (schemas != null)
            {
                foreach (XmlSchema xsd in schemas)
                {
                    if (XmlSchemas.IsDataSet(xsd))
                    {
                        MemoryStream mem = new MemoryStream();
                        mem.Position = 0;
                        xsd.Write(mem);
                        mem.Position = 0;
                        DataSet dataSet1 = new DataSet();
                        dataSet1.Locale = CultureInfo.InvariantCulture;
                        dataSet1.ReadXmlSchema(mem);
                        TypedDataSetGenerator.Generate(dataSet1, cns, icg);
                    }
                }
            }

            icg.GenerateCodeFromNamespace(cns, sw, null);
            proxySource = srcStringBuilder.ToString();
            sw.Close();

            // assembly compilation
            string location = "";

            if (HttpContext.Current != null)
            {
                location  = HttpContext.Current.Server.MapPath(".");
                location += @"\bin\";
            }

            CompilerParameters cp = new CompilerParameters();

            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("System.Xml.dll");
            cp.ReferencedAssemblies.Add("System.Web.Services.dll");
            cp.ReferencedAssemblies.Add("System.Data.dll");
            cp.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
            cp.ReferencedAssemblies.Add(location + "Thinktecture.Tools.Web.Services.Extensions.Messages.dll");

            cp.GenerateExecutable      = false;
            cp.GenerateInMemory        = false;
            cp.IncludeDebugInformation = false;
            cp.TempFiles = new TempFileCollection(CompiledAssemblyCache.GetLibTempPath());

            ICodeCompiler   icc = cscp.CreateCompiler();
            CompilerResults cr  = icc.CompileAssemblyFromSource(cp, proxySource);

            if (cr.Errors.Count > 0)
            {
                throw new DynamicCompilationException(string.Format(CultureInfo.CurrentCulture, @"Building dynamic assembly failed: {0} errors", cr.Errors.Count));
            }

            Assembly compiledAssembly = cr.CompiledAssembly;

            //rename temporary assembly in order to cache it for later use
            CompiledAssemblyCache.RenameTempAssembly(cr.PathToAssembly, wsdl);

            return(compiledAssembly);
        }
Пример #4
0
 /// <summary>
 /// Clears the cache.
 /// </summary>
 /// <param name="wsdlLocation">WSDL location.</param>
 public static void ClearCache(string wsdlLocation)
 {
     CompiledAssemblyCache.ClearCache(wsdlLocation);
 }
Пример #5
0
 /// <summary>
 /// Clear all cached DLLs.
 /// </summary>
 public static void ClearAllCached()
 {
     CompiledAssemblyCache.ClearAllCached();
 }