private bool processProxy() { if (!System.IO.File.Exists(textBoxProxy.Text)) { MessageBox.Show(this, string.Format(System.Globalization.CultureInfo.InvariantCulture, "Proxy file not found: [{0}].", textBoxProxy.Text), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } int n = textBoxProxy.Text.LastIndexOf(".", StringComparison.Ordinal); if (n < 1) { MessageBox.Show(this, string.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid proxy file: [{0}].", textBoxProxy.Text), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (!_filesFixed) { textBoxDll.Text = textBoxProxy.Text.Substring(0, n) + ".dll"; if (System.IO.File.Exists(textBoxDll.Text)) { DlgAskFileOverwrite dlg = new DlgAskFileOverwrite(); dlg.Text = "Create web service proxy dll"; dlg.SetFilePath(textBoxDll.Text); DialogResult ret = dlg.ShowDialog(this); if (ret == DialogResult.OK) { textBoxDll.Text = dlg.NewFilePath; } else if (ret != DialogResult.Ignore) { return(false); } } } CompilerParameters cp = new CompilerParameters(); /* * using System; * using System.ComponentModel; * using System.Diagnostics; * using System.Web.Services; * using System.Web.Services.Protocols; * using System.Xml.Serialization; */ StringCollection sc = new StringCollection(); sc.Add(typeof(System.Web.Services.Protocols.SoapHttpClientProtocol).Assembly.Location); string sLoc = typeof(System.Threading.SendOrPostCallback).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(Uri).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(Process).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.Xml.Serialization.IXmlSerializable).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.ComponentModel.AsyncOperation).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.Threading.SendOrPostCallback).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.Web.Services.Protocols.InvokeCompletedEventArgs).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.Data.DataSet).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } foreach (string loc in sc) { cp.ReferencedAssemblies.Add(loc); } cp.CompilerOptions = "/t:library"; cp.GenerateExecutable = false; cp.GenerateInMemory = false; cp.IncludeDebugInformation = true; cp.OutputAssembly = textBoxDll.Text; // string pdbFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(textBoxDll.Text), System.IO.Path.GetFileNameWithoutExtension(textBoxDll.Text)) + ".pdb"; if (System.IO.File.Exists(pdbFile)) { try { System.IO.File.Delete(pdbFile); } catch (Exception err0) { MessageBox.Show(this, string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}\r\nCannot overwrite {1}. Please close Limnor Studio and all programs that may use this file. Then manually delete this file", err0.Message, pdbFile), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(false); } } // string[] sourceFiles = new string[1]; sourceFiles[0] = textBoxProxy.Text; // //use C# code provider CSharpCodeProvider ccp = new CSharpCodeProvider(new Dictionary <string, string>() { { "CompilerVersion", "v3.5" } }); CompilerResults cr = ccp.CompileAssemblyFromFile(cp, sourceFiles); // if (cr.Errors.HasErrors) { FormStringList.ShowErrors("Error compiling the web service proxy", this, cr.Errors); //FormStringList dlgErr = new FormStringList(); //dlgErr.AddString("Error compiling the web service proxy"); //foreach (CompilerError error in cr.Errors) //{ // dlgErr.AddString(error.ToString()); //} //dlgErr.ShowDialog(this); return(false); } if (_designPane != null) { List <WebServiceProxy> proxyList = _designPane.Project.GetTypedProjectData <List <WebServiceProxy> >(); if (proxyList == null) { proxyList = new List <WebServiceProxy>(); _designPane.Project.SetTypedProjectData <List <WebServiceProxy> >(proxyList); } Assembly a = Assembly.LoadFile(textBoxDll.Text); _proxy = new WebServiceProxy(textBoxDll.Text, a, textBoxAsmx.Text); proxyList.Add(_proxy); } return(true); }
private bool processProxy() { string targetFilename = string.Format(CultureInfo.InvariantCulture, "{0}.cs", Path.Combine(_prj.ProjectFolder, textBoxSourceFilename.Text)); string configFilename = string.Format(CultureInfo.InvariantCulture, "{0}.config", Path.Combine(_prj.ProjectFolder, textBoxSourceFilename.Text)); if (!System.IO.File.Exists(targetFilename)) { MessageBox.Show(this, string.Format(System.Globalization.CultureInfo.InvariantCulture, "Proxy file not generated: [{0}].", targetFilename), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } string dllFilename = string.Format(CultureInfo.InvariantCulture, "{0}.dll", Path.Combine(_prj.ProjectFolder, textBoxSourceFilename.Text)); if (System.IO.File.Exists(dllFilename)) { File.Delete(dllFilename); } string targetFilename2 = string.Format(CultureInfo.InvariantCulture, "{0}2.cs", Path.Combine(_prj.ProjectFolder, textBoxSourceFilename.Text)); if (File.Exists(targetFilename2)) { File.Delete(targetFilename2); } string className = null; StreamReader sr = new StreamReader(targetFilename); while (!sr.EndOfStream && string.IsNullOrEmpty(className)) { string line = sr.ReadLine(); if (!string.IsNullOrEmpty(line)) { if (line.StartsWith("public partial class ", StringComparison.Ordinal)) { int n = line.IndexOf(':'); if (n > 0) { string s = line.Substring(0, n).Trim(); n = s.LastIndexOf(' '); className = s.Substring(n).Trim(); } } } } sr.Close(); if (string.IsNullOrEmpty(className)) { throw new DesignerException("WCF proxy class not found in {0}", targetFilename); } StreamWriter sw = new StreamWriter(targetFilename2); string code2 = Resources.CodeFileWcfProxy; code2 = code2.Replace("proxyName", className); sw.Write(code2); sw.Close(); CompilerParameters cp = new CompilerParameters(); StringCollection sc = new StringCollection(); string sLoc; sLoc = typeof(System.ServiceModel.ServiceHost).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(Uri).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(Process).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.Xml.Serialization.IXmlSerializable).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.ComponentModel.AsyncOperation).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.Threading.SendOrPostCallback).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.Web.Services.Protocols.InvokeCompletedEventArgs).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.Data.DataSet).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(System.Windows.Forms.Form).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(UITypeEditor).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } sLoc = typeof(IWindowsFormsEditorService).Assembly.Location; if (!sc.Contains(sLoc)) { sc.Add(sLoc); } foreach (string loc in sc) { cp.ReferencedAssemblies.Add(loc); } cp.CompilerOptions = "/t:library"; cp.GenerateExecutable = false; cp.GenerateInMemory = false; cp.IncludeDebugInformation = true; cp.OutputAssembly = dllFilename; // string pdbFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(dllFilename), System.IO.Path.GetFileNameWithoutExtension(dllFilename)) + ".pdb"; if (System.IO.File.Exists(pdbFile)) { try { System.IO.File.Delete(pdbFile); } catch (Exception err0) { MessageBox.Show(this, string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}\r\nCannot overwrite {1}. Please close Limnor Studio and all programs that may use this file. Then manually delete this file", err0.Message, pdbFile), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(false); } } // string[] sourceFiles = new string[] { targetFilename, targetFilename2 }; // //use C# code provider CSharpCodeProvider ccp = new CSharpCodeProvider(new Dictionary <string, string>() { { "CompilerVersion", "v3.5" } }); CompilerResults cr = ccp.CompileAssemblyFromFile(cp, sourceFiles); // if (cr.Errors.HasErrors) { FormStringList.ShowErrors("Error compiling the web service proxy", this, cr.Errors); return(false); } if (_prj != null) { string appDllFilename = string.Format(CultureInfo.InvariantCulture, "{0}.dll", Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), textBoxSourceFilename.Text)); List <WcfServiceProxy> proxyList = _prj.GetTypedProjectData <List <WcfServiceProxy> >(); if (proxyList == null) { proxyList = new List <WcfServiceProxy>(); _prj.SetTypedProjectData <List <WcfServiceProxy> >(proxyList); } try { File.Copy(dllFilename, appDllFilename, true); } catch (Exception err) { MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Error copying [{0}] to [{1}]. You may close Limnor Studio and manually copy the file. \r\n{2}", dllFilename, appDllFilename, err.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } Assembly a = Assembly.LoadFile(appDllFilename); _proxy = new WcfServiceProxy(Path.GetFileName(dllFilename), a, textBoxServiceUrl.Text, string.Format(CultureInfo.InvariantCulture, "{0}.config", textBoxSourceFilename.Text)); proxyList.Add(_proxy); MessageBox.Show(this, "The WCF Remoting Service proxy has been added to the Toolbox", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } return(true); }