[SoapHeader("header")] //用户身份验证的soap header public string InitDBConfig(string setupDbType, DatabaseInfo dbi) { //验证是否有权访问(当然,也可以通过查询数据库实现,具体视项目要求) if (!CheckAdmin(header.UserName, header.PassWord)) { throw new Exception("无权使用此服务"); } string source = "We7.CMS.Install-InstallWebService-SetSiteConfig"; try { BaseConfigInfo baseConfig = Installer.GenerateConnectionString(setupDbType, dbi); string file = Server.MapPath("~/config/db.config"); BaseConfigs.SaveConfigTo(baseConfig, file); BaseConfigs.ResetConfig(); if (dbi.CreateDB) { Exception ex = null; int ret = Installer.CreateDatabase(baseConfig, out ex); if (ret == -1) { string msg = "数据库已存在,请重新命名或去掉重新“创建新数据库”前面的勾,使用已有数据库。"; Exception ex1 = new Exception(msg); EventLogHelper.WriteToLog(source, ex1, EventLogEntryType.Error); return(msg); } else if (ret == 0) { string exceptionMsgs = ex.Message; EventLogHelper.WriteToLog(source, ex, EventLogEntryType.Error); return("创建数据库发生错误。错误原因:" + exceptionMsgs); } } //设置数据库脚本路径 //string basePath = Server.MapPath("/install/SQL"); //if (!Directory.Exists(basePath)) //{ // basePath = Server.MapPath("../install/SQL"); //} if (!Directory.Exists(Server.MapPath("/_data/"))) { Directory.CreateDirectory(Server.MapPath("/_data/")); } List <string> files = new List <string>(); files.Add("create.xml"); files.Add("install.xml"); files.Add("update.xml"); Installer.ExcuteSQLGroup(baseConfig, files); //创建内容模型表 Installer.CreateModelTables(); ApplicationHelper.ResetApplication(); return("0"); } catch (Exception ex) { EventLogHelper.WriteToLog(source, ex, EventLogEntryType.Error); return("创建数据库发生错误。错误原因:" + ex.Message); } }