2 // System.Web.Compilation.WebServiceCompiler
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
8 // Copyright (c) 2040 Novell, Inc. (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.CodeDom.Compiler;
34 using System.Web.Configuration;
36 using System.Reflection;
38 namespace System.Web.Compilation
40 class WebServiceCompiler : BaseCompiler
42 SimpleWebHandlerParser parser;
45 public WebServiceCompiler (SimpleWebHandlerParser wService)
48 this.parser = wService;
51 public static Type CompileIntoType (SimpleWebHandlerParser wService)
53 WebServiceCompiler wsc = new WebServiceCompiler (wService);
54 return wsc.GetCompiledType ();
57 public override Type GetCompiledType ()
59 Type type = CachingCompiler.GetTypeFromCache (parser.PhysicalPath);
63 if (parser.Program.Trim () == "") {
64 type = Type.GetType (parser.ClassName, false);
66 type = parser.GetTypeFromBin (parser.ClassName);
67 CachingCompiler.InsertTypeFileDep (type, parser.PhysicalPath);
71 string lang = parser.Language;
72 string compilerOptions;
76 CodeDomProvider provider;
77 Provider = provider = CreateProvider (parser.Context, lang, out compilerOptions, out warningLevel, out tempdir);
79 throw new HttpException ("Configuration error. Language not supported: " +
83 Compiler = provider.CreateCompiler ();
86 CompilerParameters compilerParameters;
87 CompilerParameters = compilerParameters = CachingCompiler.GetOptions (parser.Assemblies);
88 compilerParameters.IncludeDebugInformation = parser.Debug;
89 compilerParameters.CompilerOptions = compilerOptions;
90 compilerParameters.WarningLevel = warningLevel;
92 bool keepFiles = (Environment.GetEnvironmentVariable ("MONO_ASPNET_NODELETE") != null);
94 TempFileCollection tempcoll;
95 tempcoll = new TempFileCollection (tempdir, keepFiles);
96 compilerParameters.TempFiles = tempcoll;
98 inputFile = tempcoll.AddExtension (provider.FileExtension);
99 Stream st = File.OpenWrite (inputFile);
100 StreamWriter sw = new StreamWriter (st);
101 sw.WriteLine (parser.Program);
104 string dllfilename = Path.GetFileName (tempcoll.AddExtension ("dll", true));
106 compilerParameters.OutputAssembly = Path.Combine (DynamicDir (), dllfilename);
108 CompilerResults results = CachingCompiler.Compile (this);
109 CheckCompilerErrors (results);
110 Assembly assembly = results.CompiledAssembly;
111 if (assembly == null) {
112 if (!File.Exists (compilerParameters.OutputAssembly))
113 throw new CompilationException (inputFile, results.Errors,
114 "No assembly returned after compilation!?");
115 assembly = Assembly.LoadFrom (compilerParameters.OutputAssembly);
118 results.TempFiles.Delete ();
119 type = assembly.GetType (parser.ClassName, true);
120 CachingCompiler.InsertTypeFileDep (type, parser.PhysicalPath);
124 void CheckCompilerErrors (CompilerResults results)
126 if (results.NativeCompilerReturnValue == 0)
129 throw new CompilationException (parser.PhysicalPath, results.Errors, parser.Program);
132 internal new SimpleWebHandlerParser Parser {
133 get { return parser; }
136 internal string InputFile {
137 get { return inputFile; }