2 // System.Web.Compilation.WebServiceCompiler
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
12 using System.CodeDom.Compiler;
14 using Microsoft.CSharp;
16 namespace System.Web.Compilation
18 class WebServiceCompiler : BaseCompiler
20 SimpleWebHandlerParser wService;
21 ICodeCompiler compiler;
23 public WebServiceCompiler (SimpleWebHandlerParser wService)
26 this.wService = wService;
29 public static Type CompileIntoType (SimpleWebHandlerParser wService)
31 WebServiceCompiler wsc = new WebServiceCompiler (wService);
32 return wsc.GetCompiledType ();
35 public override Type GetCompiledType ()
37 if (wService.Program.Trim () == "")
38 return wService.GetTypeFromBin (wService.ClassName);
40 //FIXME: update when we support other languages
41 string fname = Path.ChangeExtension (Path.GetTempFileName (), ".cs");
42 StreamWriter sw = new StreamWriter (File.OpenWrite (fname));
43 sw.WriteLine (wService.Program);
46 //TODO: get the compiler and default options from system.web/compileroptions
47 CompilerResults results = CachingCompiler.Compile (this, fname);
48 CheckCompilerErrors (results);
50 return results.CompiledAssembly.GetType (wService.ClassName, true);
53 void CheckCompilerErrors (CompilerResults results)
55 if (results.NativeCompilerReturnValue == 0)
58 throw new CompilationException (wService.PhysicalPath, results.Errors, wService.Program);
61 internal new SimpleWebHandlerParser Parser {
62 get { return wService; }
65 internal override ICodeCompiler Compiler {
67 if (compiler == null) {
68 //TODO: get the compiler and default options from system.web/compileroptions
69 compiler = new CSharpCodeProvider ().CreateCompiler ();