int InitialApplication(out string strError) { strError = ""; if (this.app != null) { return(0); // 已经初始化 } HostInfo info = OperationContext.Current.Host.Extensions.Find <HostInfo>(); if (info.App != null) { this.app = info.App; return(0); } string strDataDir = info.DataDir; Debug.Assert(string.IsNullOrEmpty(strDataDir) == false, ""); lock (info.LockObject) { info.App = new UcApplication(); // parameter: // strDataDir data目录 // strError out参数,返回出错信息 // return: // -1 出错 // 0 成功 // 线: 安全的 int nRet = info.App.Initial(strDataDir, out strError); if (nRet == -1) { return(-1); } } this.app = info.App; return(0); }
void ThreadLoadUnionCatalog() { if (this.m_hostUnionCatalog != null) { this.m_hostUnionCatalog.Close(); this.m_hostUnionCatalog = null; } string strInstanceName = ""; string strDataDir = ""; string[] existing_urls = null; bool bRet = GetInstanceInfo("dp2ZServer", 0, out strInstanceName, out strDataDir, out existing_urls); if (bRet == false) { /* * this.Log.WriteEntry("dp2ZServer OnStart() 时发生错误: 注册表中找不到instance信息", * EventLogEntryType.Error); * */ return; } string strHttpHostUrl = FindUrl("http", existing_urls); if (string.IsNullOrEmpty(strHttpHostUrl) == true) { string strUrls = string.Join(";", existing_urls); this.Log.WriteEntry("dp2ZServer OnStart() 时发生错误: 协议绑定 '" + strUrls + "' 中,没有包含http协议,因此没有启动UnionCatalogService", EventLogEntryType.Error); return; } this.m_hostUnionCatalog = new ServiceHost(typeof(UnionCatalogService)); HostInfo info = new HostInfo(); info.DataDir = strDataDir; this.m_hostUnionCatalog.Extensions.Add(info); if (String.IsNullOrEmpty(strHttpHostUrl) == false) { this.m_hostUnionCatalog.AddServiceEndpoint(typeof(IUnionCatalogService), CreateBasicHttpBinding0(), strHttpHostUrl); } // metadata能力 if (this.m_hostUnionCatalog.Description.Behaviors.Find <ServiceMetadataBehavior>() == null) { string strMetadataUrl = strHttpHostUrl; if (String.IsNullOrEmpty(strMetadataUrl) == true) { strMetadataUrl = "http://localhost/unioncatalog/"; } if (strMetadataUrl[strMetadataUrl.Length - 1] != '/') { strMetadataUrl += "/"; } strMetadataUrl += "metadata"; ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true; behavior.HttpGetUrl = new Uri(strMetadataUrl); this.m_hostUnionCatalog.Description.Behaviors.Add(behavior); } if (this.m_hostUnionCatalog.Description.Behaviors.Find <ServiceThrottlingBehavior>() == null) { ServiceThrottlingBehavior behavior = new ServiceThrottlingBehavior(); behavior.MaxConcurrentCalls = 50; behavior.MaxConcurrentInstances = 1000; behavior.MaxConcurrentSessions = 1000; this.m_hostUnionCatalog.Description.Behaviors.Add(behavior); } // IncludeExceptionDetailInFaults ServiceDebugBehavior debug_behavior = this.m_hostUnionCatalog.Description.Behaviors.Find <ServiceDebugBehavior>(); if (debug_behavior == null) { this.m_hostUnionCatalog.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); } else { if (debug_behavior.IncludeExceptionDetailInFaults == false) { debug_behavior.IncludeExceptionDetailInFaults = true; } } this.m_hostUnionCatalog.Opening += new EventHandler(host_Opening); this.m_hostUnionCatalog.Closing += new EventHandler(m_host_Closing); try { this.m_hostUnionCatalog.Open(); } catch (Exception ex) { // 让调试器能感觉到 if (this.m_bConsoleRun == true) { throw ex; } this.Log.WriteEntry("dp2ZServer OnStart() host.Open() 时发生错误: " + ex.Message, EventLogEntryType.Error); return; } this.Log.WriteEntry("dp2ZServer OnStart() end", EventLogEntryType.Information); this.m_threadLoadUnionCatalog = null; }