protected void GVBinding_RowDeleting(object sender, GridViewDeleteEventArgs e) { var gv = sender as GridView; if (gv.Rows.Count < 1) { e.Cancel = true; this.LabelSEPServiceEndPointErrorMessage.Text = "无记录"; return; } var bindingname = gv.Rows[e.RowIndex].Cells[1].Text; var context = new WcfConfigDataContext(); var query = (from serverfarm in context.Bindings where serverfarm.BindingName == bindingname select serverfarm); this.OnDeleteSubmit <Binding>( context, query.First <Binding>(), this.LabelBindingErrorMessage, new Action[] { this.InitBinding } ); this.LabelBindingErrorMessage.Focus(); }
private void OnDeleteSubmit <T>(WcfConfigDataContext wcfconfigdatacontext, T entity, Label errorlabel, Action[] callback) where T : class { try { var query = (from e in wcfconfigdatacontext.GetTable <T>() where e == entity select e); wcfconfigdatacontext.GetTable <T>().DeleteOnSubmit(entity); wcfconfigdatacontext.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict); wcfconfigdatacontext.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues); } catch (Exception ex) { errorlabel.Text = ex.Message; } finally { foreach (Action act in callback) { act(); } } }
private void OnAddSubmit <T>(T newobj, Label errorlabel, Action[] callback) where T : class { try { var wcfconfigdatacontext = new WcfConfigDataContext(); wcfconfigdatacontext.GetTable <T>().InsertOnSubmit(newobj); wcfconfigdatacontext.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict); wcfconfigdatacontext.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues); errorlabel.Text = "添加成功"; } catch (Exception ex) { errorlabel.Text = ex.Message; } finally { foreach (Action act in callback) { act(); } } }
public WcfClientEndpoint GetWcfClientEndpoint(string serviceContractType, string serviceContractVersion, string machineIP) { try { using (WcfConfigDataContext data = new WcfConfigDataContext()) { var wcfClientEndpoint = (from ep in (data.ServiceEndpoints .Where(s => s.ServiceContractType == serviceContractType).ToList()) where (ep.ServiceContractVersion == "" || float.Parse(ep.ServiceContractVersion) >= float.Parse(serviceContractVersion)) orderby ep.ServiceContractVersion ascending, ep.Binding.BindingPriority descending select new WcfClientEndpoint { EndpointName = ep.ServiceEndpointName, EndpointPort = ep.ServiceEndpointPort, ServiceContractType = ep.ServiceContractType, EndpointBindingType = ep.Binding.BindingType, EndpointBindingXml = ep.Binding.BindingXml != null ? ep.Binding.BindingXml.ToString() : "", EndpointProtocol = ep.Binding.BindingProtocol, ServiceType = ep.ServiceType, }).FirstOrDefault(); if (wcfClientEndpoint == null) { LocalLogService.Log("wcfClientEndpoint = null"); return(null); } var wcfService = data.Services.Where(s => s.ServiceType == wcfClientEndpoint.ServiceType).FirstOrDefault(); if (wcfService == null) { LocalLogService.Log("wcfService = null"); return(null); } var wcfServerFarm = wcfService.ServerFarm; wcfClientEndpoint.EndpointAddress = wcfServerFarm.ServerFarmAddress; wcfClientEndpoint.ServerFarmName = wcfServerFarm.ServerFarmName; var accessableFarmNames = data.ClientAccesses.ToList().Where(acc => acc.ClientMachineIP == "*" || machineIP.Contains(acc.ClientMachineIP)).Select(a => a.AccessServerFarmName).ToList(); if (!accessableFarmNames.Contains("*") && !accessableFarmNames.Contains(wcfClientEndpoint.ServerFarmName)) { LocalLogService.Log("accessableFarmNames = null"); return(null); } var query = (from ce in data.ClientEndpoints where ce.ServiceContractType == wcfClientEndpoint.ServiceContractType select ce.ClientEndpointBehaviorXml).FirstOrDefault(); wcfClientEndpoint.EndpointBehaviorXml = query != null?query.ToString() : ""; return(wcfClientEndpoint); } } catch (Exception ex) { LocalLogService.Log(ex.ToString()); return(null); } }
protected void GVServerFarm_RowEditing(object sender, GridViewEditEventArgs e) { if (GVServerFarm.Rows.Count < 1) { return; } var key = GVServerFarm.Rows[e.NewEditIndex].Cells[1].Text; var context = new WcfConfigDataContext(); var query = (from serverfarm in context.ServerFarms where serverfarm.ServerFarmName == key select serverfarm).First <ServerFarm>(); if (query == null) { return; } this.TBServerFarmName.Text = query.ServerFarmName; this.TBServerFarmName.Focus(); this.TBServerFarmAddress.Text = query.ServerFarmAddress; }
protected void GVClientEndPoint_RowDeleting(object sender, GridViewDeleteEventArgs e) { var gv = sender as GridView; if (gv.Rows.Count < 1) { e.Cancel = true; this.LabelClientEndPointErrorMessage.Text = "无记录"; return; } var servicecontracttype = gv.Rows[e.RowIndex].Cells[1].Text; var context = new WcfConfigDataContext(); var query = (from serverfarm in context.ClientEndpoints where serverfarm.ServiceContractType == servicecontracttype select serverfarm); this.OnDeleteSubmit <ClientEndpoint>( context, query.First <ClientEndpoint>(), this.LabelClientEndPointErrorMessage, new Action[] { this.InitClientEndPoint } ); this.LabelClientEndPointErrorMessage.Focus(); }
protected void GVSEPServiceEndPoint_RowEditing(object sender, GridViewEditEventArgs e) { if (GVSEPServiceEndPoint.Rows.Count < 1) { return; } var key = GVSEPServiceEndPoint.Rows[e.NewEditIndex].Cells[1].Text; var context = new WcfConfigDataContext(); var query = (from serviceendpoint in context.ServiceEndpoints where serviceendpoint.ServiceContractType == key select serviceendpoint).First <ServiceEndpoint>(); this.TBSEPServiceContractType.Text = query.ServiceContractType; this.TBSEPServiceContractType.Focus(); this.TBSEPServiceContractVersion.Text = query.ServiceContractVersion; this.TBSEPServiceType.Text = query.ServiceType; this.DDLSEPServiceEndPointBindingName.SelectedValue = query.ServiceEndpointBindingName; this.TBSEPServiceEndPointPort.Text = query.ServiceEndpointPort.ToString(); this.TBSEPServiceEndPointName.Text = query.ServiceEndpointName; this.TBSEPServiceEndPointBehaviorXml.Text = query.ServiceEndpointBehaviorXml.ToString(); }
protected void GVServerFarm_RowDeleting(object sender, GridViewDeleteEventArgs e) { var gv = sender as GridView; if (gv.Rows.Count < 1) { e.Cancel = true; this.LabelServerFarmErrorMessage.Text = "无记录"; return; } var serverfarmname = gv.Rows[e.RowIndex].Cells[1].Text; var context = new WcfConfigDataContext(); var query = (from serverfarm in context.ServerFarms where serverfarm.ServerFarmName == serverfarmname select serverfarm); this.OnDeleteSubmit <ServerFarm>( context, query.First <ServerFarm>(), this.LabelServerFarmErrorMessage, new Action[] { this.InitServerFarms } ); this.LabelServerFarmErrorMessage.Focus(); }
protected void InitClientEndPoint() { var wcfconfigdatacontext = new WcfConfigDataContext(); var query = (from clientendpoint in wcfconfigdatacontext.ClientEndpoints select clientendpoint); this.InitGV(this.GVClientEndPoint, query); }
protected void InitService() { var wcfconfigdatacontext = new WcfConfigDataContext(); var query = (from service in wcfconfigdatacontext.Services select service); this.InitGV(this.GVService, query); }
protected void InitBinding() { var wcfconfigdatacontext = new WcfConfigDataContext(); var query = (from binding in wcfconfigdatacontext.Bindings select binding); this.InitGV(this.GVBinding, query); }
protected void BtnAddService_Click(object sender, EventArgs e) { var servicetype = this.TBServiceType.Text.Trim(); var behaviorxml = this.TBServiceBehaviorXml.Text.Trim(); var serviceconfig = this.TBServiceConfig.Text.Trim(); var servermachineIP = this.TBServerMachineIP.Text.Trim(); var context = new WcfConfigDataContext(); var query = (from service in context.Services where service.ServiceType == servicetype select service); if (query.Count() < 1) { this.OnAddSubmit <Service>( new Service() { ServerFarmName = this.DDLServerFarm.SelectedValue, ServiceType = servicetype, ServiceBehaviorXml = string.IsNullOrEmpty(behaviorxml) ? null : XElement.Parse(behaviorxml), ServiceConfig = string.IsNullOrEmpty(serviceconfig) ? null : XElement.Parse(serviceconfig), ServerMachineIP = servermachineIP }, this.LabelServiceErrorMessage, new Action[] { this.InitService } ); } else { var obj = query.First <Service>(); obj.ServerFarmName = this.DDLServerFarm.SelectedValue; obj.ServiceType = servicetype; obj.ServiceBehaviorXml = string.IsNullOrEmpty(behaviorxml) ? null : XElement.Parse(behaviorxml); obj.ServiceConfig = string.IsNullOrEmpty(serviceconfig) ? null : XElement.Parse(serviceconfig); obj.ServerMachineIP = servermachineIP; context.SubmitChanges(); this.LabelServiceErrorMessage.Text = "修改成功"; this.InitService(); } this.LabelServiceErrorMessage.Focus(); }
protected void InitServerFarms() { var wcfconfigdatacontext = new WcfConfigDataContext(); var query = (from serverfarm in wcfconfigdatacontext.ServerFarms select serverfarm); this.InitGV(this.GVServerFarm, query); this.DDLServerFarm.DataSource = query; this.DDLServerFarm.DataTextField = "ServerFarmName"; this.DDLServerFarm.DataValueField = "ServerFarmName"; this.DDLServerFarm.DataBind(); }
protected void BtnAddBinding_Click(object sender, EventArgs e) { var bindingname = this.TBBindingName.Text.Trim(); var bindingtype = this.DDLBindingType.SelectedValue; var bindingpriority = int.Parse(this.DDLBindingPriority.SelectedValue); var bindingxml = this.TBBindingXml.Text.Trim(); var bindingprotocol = this.DDLBindingProtocol.SelectedValue; var context = new WcfConfigDataContext(); var query = (from binding in context.Bindings where binding.BindingName == bindingname select binding); if (query.Count() < 1) { this.OnAddSubmit <Binding>( new Binding() { BindingName = bindingname, BindingType = bindingtype, BindingPriority = bindingpriority, BindingXml = string.IsNullOrEmpty(bindingxml) ? null : XElement.Parse(bindingxml), BindingProtocol = bindingprotocol }, this.LabelBindingErrorMessage, new Action[] { this.InitBinding } ); } else { var obj = query.First <Binding>(); obj.BindingName = bindingname; obj.BindingType = bindingtype; obj.BindingPriority = bindingpriority; obj.BindingXml = string.IsNullOrEmpty(bindingxml) ? null : XElement.Parse(bindingxml); obj.BindingProtocol = bindingprotocol; context.SubmitChanges(); this.LabelBindingErrorMessage.Text = "修改成功"; this.InitBinding(); } this.LabelBindingErrorMessage.Focus(); //this.PublisherToRedisMessageChannel(REDISMESSAGESERVERCHANNEL, bindingname); }
public WcfService GetWcfService(string serviceType, string serviceContractVersion, string machineIP) { try { using (WcfConfigDataContext data = new WcfConfigDataContext()) { var wcfServices = data.Services.Where(s => s.ServiceType == serviceType).ToList(); var wcfService = wcfServices.Where(s => (machineIP.Contains(s.ServerMachineIP))).FirstOrDefault(); if (wcfService == null) { wcfService = wcfServices.Where(s => s.ServerMachineIP == "*").FirstOrDefault(); } var service = new WcfService { ServiceType = serviceType, ServiceBehaviorXml = wcfService.ServiceBehaviorXml != null?wcfService.ServiceBehaviorXml.ToString() : "", Endpoints = (from ep in data.ServiceEndpoints where ep.ServiceType == serviceType && ep.ServiceContractVersion == serviceContractVersion && (ep.ServerMachineIP == wcfService.ServerMachineIP || ep.ServerMachineIP == "*") select new WcfServiceEndpoint { EndpointBehaviorXml = ep.ServiceEndpointBehaviorXml != null ? ep.ServiceEndpointBehaviorXml.ToString() : "", EndpointBindingName = ep.ServiceEndpointBindingName, EndpointName = ep.ServiceEndpointName, EndpointPort = ep.ServiceEndpointPort, ServiceContractType = ep.ServiceContractType, EndpointBindingType = ep.Binding.BindingType, EndpointBindingXml = ep.Binding.BindingXml != null ? ep.Binding.BindingXml.ToString() : "", EndpointProtocol = ep.Binding.BindingProtocol }).ToArray() }; return(service); } } catch (Exception ex) { LocalLogService.Log(ex.ToString()); return(null); } }
protected void BtnAddClientEndPoint_Click(object sender, EventArgs e) { var servicecontracttype = this.TBServiceContractType.Text.Trim(); var clientendpointbehaviorxml = this.TBClientEndpointBehaviorXml.Text.Trim(); var context = new WcfConfigDataContext(); var query = (from clientendpoint in context.ClientEndpoints where clientendpoint.ServiceContractType == servicecontracttype select clientendpoint); if (query.Count() < 1) { this.OnAddSubmit <ClientEndpoint>( new ClientEndpoint() { ServiceContractType = servicecontracttype, ClientMachineIP = "*", ClientEndpointBehaviorXml = string.IsNullOrEmpty(clientendpointbehaviorxml) ? null : XElement.Parse(clientendpointbehaviorxml) }, this.LabelClientEndPointErrorMessage, new Action[] { this.InitClientEndPoint } ); } else { var obj = query.First <ClientEndpoint>(); obj.ServiceContractType = servicecontracttype; obj.ClientMachineIP = "*"; obj.ClientEndpointBehaviorXml = string.IsNullOrEmpty(clientendpointbehaviorxml) ? null : XElement.Parse(clientendpointbehaviorxml); context.SubmitChanges(); this.LabelClientEndPointErrorMessage.Text = "修改成功"; this.InitClientEndPoint(); } this.LabelClientEndPointErrorMessage.Focus(); //this.PublisherToRedisMessageChannel(REDISMESSAGECLIENTCHANNEL, servicecontracttype); }
private void InitServiceEndPoint() { var wcfconfigdatacontext = new WcfConfigDataContext(); var query = (from serviceendpoint in wcfconfigdatacontext.ServiceEndpoints select serviceendpoint); this.InitGV(this.GVSEPServiceEndPoint, query); var query2 = (from binding in wcfconfigdatacontext.Bindings select binding); this.DDLSEPServiceEndPointBindingName.DataSource = query2; this.DDLSEPServiceEndPointBindingName.DataTextField = "BindingName"; /// Binding表里的BindingName this.DDLSEPServiceEndPointBindingName.DataValueField = "BindingName"; this.DDLSEPServiceEndPointBindingName.DataBind(); }
protected void GVClientEndPoint_RowEditing(object sender, GridViewEditEventArgs e) { if (GVClientEndPoint.Rows.Count < 1) { return; } var key = GVClientEndPoint.Rows[e.NewEditIndex].Cells[1].Text; var context = new WcfConfigDataContext(); var query = (from clientendpoint in context.ClientEndpoints where clientendpoint.ServiceContractType == key select clientendpoint).First <ClientEndpoint>(); this.TBServiceContractType.Text = query.ServiceContractType; this.TBServiceContractType.Focus(); this.TBClientEndpointBehaviorXml.Text = query.ClientEndpointBehaviorXml.ToString(); }
protected void BtnAddServerFarm_Click(object sender, EventArgs e) { var name = TBServerFarmName.Text.Trim(); var address = TBServerFarmAddress.Text.Trim(); var context = new WcfConfigDataContext(); var query = (from serverfarm in context.ServerFarms where serverfarm.ServerFarmName == name select serverfarm); if (query.Count() < 1) // create { this.OnAddSubmit <ServerFarm>( new ServerFarm() { ServerFarmName = name, ServerFarmAddress = address }, this.LabelServerFarmErrorMessage, new Action[] { this.InitServerFarms, this.InitService } ); } else { var obj = query.First <ServerFarm>(); obj.ServerFarmName = name; obj.ServerFarmAddress = address; context.SubmitChanges(); this.LabelServerFarmErrorMessage.Text = "修改成功"; this.InitServerFarms(); this.InitService(); } this.LabelServerFarmErrorMessage.Focus(); }
protected void GVBinding_RowEditing(object sender, GridViewEditEventArgs e) { if (GVBinding.Rows.Count < 1) { return; } var key = GVBinding.Rows[e.NewEditIndex].Cells[1].Text; var context = new WcfConfigDataContext(); var query = (from binding in context.Bindings where binding.BindingName == key select binding).First <Binding>(); this.TBBindingName.Text = query.BindingName; this.TBBindingName.Focus(); this.DDLBindingType.SelectedValue = query.BindingType; this.DDLBindingProtocol.SelectedValue = query.BindingProtocol; this.DDLBindingPriority.SelectedValue = query.BindingPriority.ToString(); this.TBBindingXml.Text = query.BindingXml.ToString(); }
protected void GVService_RowEditing(object sender, GridViewEditEventArgs e) { if (GVService.Rows.Count < 1) { return; } var key = GVService.Rows[e.NewEditIndex].Cells[1].Text; var context = new WcfConfigDataContext(); var query = (from service in context.Services where service.ServiceType == key select service).First <Service>(); this.DDLServerFarm.SelectedValue = query.ServerFarmName; this.DDLServerFarm.Focus(); this.TBServiceType.Text = query.ServiceType; this.TBServerMachineIP.Text = query.ServerMachineIP; this.TBServiceBehaviorXml.Text = query.ServiceBehaviorXml.ToString(); this.TBServiceConfig.Text = query.ServiceConfig.ToString(); }
public WcfClientSetting GetClientSetting(string serviceContractType, string machineIP) { var setting = new WcfClientSetting { WcfLogSetting = new WcfLogSetting { Enabled = true, ExceptionInfoSetting = new ExceptionInfoSetting { Enabled = false, }, InvokeInfoSetting = new InvokeInfoSetting { Enabled = false, }, StartInfoSetting = new StartInfoSetting { Enabled = true, }, MessageInfoSetting = new MessageInfoSetting { Enabled = false, } }, WcfSecuritySetting = new WcfSecuritySetting { PasswordCheck = new PasswordCheck { Enable = false, } } }; try { using (WcfConfigDataContext data = new WcfConfigDataContext()) { var endpoints = data.ClientEndpoints.Where(ep => ep.ServiceContractType == serviceContractType).ToList(); var e = endpoints.Where(endpoint => machineIP.Contains(endpoint.ClientMachineIP)).FirstOrDefault(); if (e == null) e = endpoints.Where(endpoint => endpoint.ClientMachineIP == "*").FirstOrDefault(); var clientConfig = e.ServiceConfig; if (clientConfig != null) { if (clientConfig.Element("WcfLogSetting") != null) ParseLogSettingXml(clientConfig.Element("WcfLogSetting"), setting.WcfLogSetting); } var serviceEndpoint = data.ServiceEndpoints.Where(se => se.ServiceContractType == serviceContractType).FirstOrDefault(); if (serviceEndpoint != null) { var service = data.Services.Where(s => s.ServiceType == serviceEndpoint.ServiceType).FirstOrDefault(); if (service != null) { var serviceConfig = service.ServiceConfig; if (serviceConfig != null) { if (serviceConfig.Element("WcfSecuritySetting") != null) ParseSecuritySettingXml(serviceConfig.Element("WcfSecuritySetting"), setting.WcfSecuritySetting); } } } } } catch (Exception ex) { LocalLogService.Log(ex.ToString()); } return setting; }
public WcfService GetWcfService(string serviceType, string serviceContractVersion, string machineIP) { try { using (WcfConfigDataContext data = new WcfConfigDataContext()) { var wcfServices = data.Services.Where(s => s.ServiceType == serviceType).ToList(); var wcfService = wcfServices.Where(s => (machineIP.Contains(s.ServerMachineIP))).FirstOrDefault(); if (wcfService == null ) wcfService = wcfServices.Where(s => s.ServerMachineIP == "*" ).FirstOrDefault(); var service = new WcfService { ServiceType = serviceType, ServiceBehaviorXml = wcfService.ServiceBehaviorXml != null ? wcfService.ServiceBehaviorXml.ToString() : "", Endpoints = (from ep in data.ServiceEndpoints where ep.ServiceType == serviceType && ep.ServiceContractVersion == serviceContractVersion && (ep.ServerMachineIP == wcfService.ServerMachineIP || ep.ServerMachineIP == "*") select new WcfServiceEndpoint { EndpointBehaviorXml = ep.ServiceEndpointBehaviorXml != null ? ep.ServiceEndpointBehaviorXml.ToString() : "", EndpointBindingName = ep.ServiceEndpointBindingName, EndpointName = ep.ServiceEndpointName, EndpointPort = ep.ServiceEndpointPort, ServiceContractType = ep.ServiceContractType, EndpointBindingType = ep.Binding.BindingType, EndpointBindingXml = ep.Binding.BindingXml != null ? ep.Binding.BindingXml.ToString() : "", EndpointProtocol = ep.Binding.BindingProtocol }).ToArray() }; return service; } } catch (Exception ex) { LocalLogService.Log(ex.ToString()); return null; } }
public WcfServerSetting GetServerSetting(string serviceType, string machineIP) { var setting = new WcfServerSetting { WcfCoreSetting = new WcfCoreSetting { EnableUnity = false, }, WcfLogSetting = new WcfLogSetting { Enabled = true, ExceptionInfoSetting = new ExceptionInfoSetting { Enabled = true, }, InvokeInfoSetting = new InvokeInfoSetting { Enabled = false, }, StartInfoSetting = new StartInfoSetting { Enabled = true, }, MessageInfoSetting = new MessageInfoSetting { Enabled = false, } }, WcfSecuritySetting = new WcfSecuritySetting { PasswordCheck = new PasswordCheck { Enable = false, } } }; try { using (WcfConfigDataContext data = new WcfConfigDataContext()) { var services = data.Services.Where(service => service.ServiceType == serviceType).ToList(); var s = services.Where(service => machineIP.Contains(service.ServerMachineIP)).FirstOrDefault(); if (s == null) s = services.Where(service => service.ServerMachineIP == "*").FirstOrDefault(); var config = s.ServiceConfig; if (config != null) { if (config.Element("WcfLogSetting") != null) ParseLogSettingXml(config.Element("WcfLogSetting"), setting.WcfLogSetting); if (config.Element("WcfCoreSetting") != null) ParseCoreSettingXml(config.Element("WcfCoreSetting"), setting.WcfCoreSetting); if (config.Element("WcfSecuritySetting") != null) ParseSecuritySettingXml(config.Element("WcfSecuritySetting"), setting.WcfSecuritySetting); } } } catch (Exception ex) { LocalLogService.Log(ex.ToString()); } return setting; }
public WcfClientSetting GetClientSetting(string serviceContractType, string machineIP) { var setting = new WcfClientSetting { WcfLogSetting = new WcfLogSetting { Enabled = true, ExceptionInfoSetting = new ExceptionInfoSetting { Enabled = false, }, InvokeInfoSetting = new InvokeInfoSetting { Enabled = false, }, StartInfoSetting = new StartInfoSetting { Enabled = true, }, MessageInfoSetting = new MessageInfoSetting { Enabled = false, } }, WcfSecuritySetting = new WcfSecuritySetting { PasswordCheck = new PasswordCheck { Enable = false, } } }; try { using (WcfConfigDataContext data = new WcfConfigDataContext()) { var endpoints = data.ClientEndpoints.Where(ep => ep.ServiceContractType == serviceContractType).ToList(); var e = endpoints.Where(endpoint => machineIP.Contains(endpoint.ClientMachineIP)).FirstOrDefault(); if (e == null) { e = endpoints.Where(endpoint => endpoint.ClientMachineIP == "*").FirstOrDefault(); } var clientConfig = e.ServiceConfig; if (clientConfig != null) { if (clientConfig.Element("WcfLogSetting") != null) { ParseLogSettingXml(clientConfig.Element("WcfLogSetting"), setting.WcfLogSetting); } } var serviceEndpoint = data.ServiceEndpoints.Where(se => se.ServiceContractType == serviceContractType).FirstOrDefault(); if (serviceEndpoint != null) { var service = data.Services.Where(s => s.ServiceType == serviceEndpoint.ServiceType).FirstOrDefault(); if (service != null) { var serviceConfig = service.ServiceConfig; if (serviceConfig != null) { if (serviceConfig.Element("WcfSecuritySetting") != null) { ParseSecuritySettingXml(serviceConfig.Element("WcfSecuritySetting"), setting.WcfSecuritySetting); } } } } } } catch (Exception ex) { LocalLogService.Log(ex.ToString()); } return(setting); }
public WcfServerSetting GetServerSetting(string serviceType, string machineIP) { var setting = new WcfServerSetting { WcfCoreSetting = new WcfCoreSetting { EnableUnity = false, }, WcfLogSetting = new WcfLogSetting { Enabled = true, ExceptionInfoSetting = new ExceptionInfoSetting { Enabled = true, }, InvokeInfoSetting = new InvokeInfoSetting { Enabled = false, }, StartInfoSetting = new StartInfoSetting { Enabled = true, }, MessageInfoSetting = new MessageInfoSetting { Enabled = false, } }, WcfSecuritySetting = new WcfSecuritySetting { PasswordCheck = new PasswordCheck { Enable = false, } } }; try { using (WcfConfigDataContext data = new WcfConfigDataContext()) { var services = data.Services.Where(service => service.ServiceType == serviceType).ToList(); var s = services.Where(service => machineIP.Contains(service.ServerMachineIP)).FirstOrDefault(); if (s == null) { s = services.Where(service => service.ServerMachineIP == "*").FirstOrDefault(); } var config = s.ServiceConfig; if (config != null) { if (config.Element("WcfLogSetting") != null) { ParseLogSettingXml(config.Element("WcfLogSetting"), setting.WcfLogSetting); } if (config.Element("WcfCoreSetting") != null) { ParseCoreSettingXml(config.Element("WcfCoreSetting"), setting.WcfCoreSetting); } if (config.Element("WcfSecuritySetting") != null) { ParseSecuritySettingXml(config.Element("WcfSecuritySetting"), setting.WcfSecuritySetting); } } } } catch (Exception ex) { LocalLogService.Log(ex.ToString()); } return(setting); }
protected void BtnAddServiceEndPoint_Click(object sender, EventArgs e) { var servicecontracttype = this.TBSEPServiceContractType.Text.Trim(); var serviceContractversion = this.TBSEPServiceContractVersion.Text.Trim(); var servicetype = this.TBSEPServiceType.Text.Trim(); var serviceendpointbehaviorxml = this.TBSEPServiceEndPointBehaviorXml.Text.Trim(); var serviceendpointbindingname = this.DDLSEPServiceEndPointBindingName.SelectedValue; var serviceendpointport = int.Parse(this.TBSEPServiceEndPointPort.Text.Trim()); var serviceendpointname = this.TBSEPServiceEndPointName.Text.Trim(); var context = new WcfConfigDataContext(); var query = (from serviceendpoint in context.ServiceEndpoints where serviceendpoint.ServiceContractType == servicecontracttype && serviceendpoint.ServiceContractVersion == serviceContractversion select serviceendpoint); if (query.Count() < 1) { this.OnAddSubmit <ServiceEndpoint>( new ServiceEndpoint() { ServiceContractType = servicecontracttype, ServiceContractVersion = serviceContractversion, ServiceType = servicetype, ServiceEndpointBehaviorXml = string.IsNullOrEmpty(serviceendpointbehaviorxml) ? null : XElement.Parse(serviceendpointbehaviorxml), ServiceEndpointBindingName = serviceendpointbindingname, ServiceEndpointName = serviceendpointname, ServerMachineIP = "*", ServiceEndpointPort = serviceendpointport }, this.LabelSEPServiceEndPointErrorMessage, new Action[] { this.InitServiceEndPoint } ); } else { var obj = query.First <ServiceEndpoint>(); obj.ServiceContractType = servicecontracttype; obj.ServiceContractVersion = serviceContractversion; obj.ServiceType = servicetype; obj.ServiceEndpointBehaviorXml = string.IsNullOrEmpty(serviceendpointbehaviorxml) ? null : XElement.Parse(serviceendpointbehaviorxml); obj.ServiceEndpointBindingName = serviceendpointbindingname; obj.ServiceEndpointName = serviceendpointname; obj.ServiceEndpointPort = serviceendpointport; obj.ServerMachineIP = "*"; context.SubmitChanges(); this.LabelSEPServiceEndPointErrorMessage.Text = "修改成功"; this.InitServiceEndPoint(); } this.LabelSEPServiceEndPointErrorMessage.Focus(); }
public WcfClientEndpoint GetWcfClientEndpoint(string serviceContractType, string serviceContractVersion, string machineIP) { try { using (WcfConfigDataContext data = new WcfConfigDataContext()) { var wcfClientEndpoint = (from ep in (data.ServiceEndpoints .Where(s => s.ServiceContractType == serviceContractType).ToList()) where (ep.ServiceContractVersion == "" || float.Parse(ep.ServiceContractVersion) >= float.Parse(serviceContractVersion)) orderby ep.ServiceContractVersion ascending, ep.Binding.BindingPriority descending select new WcfClientEndpoint { EndpointName = ep.ServiceEndpointName, EndpointPort = ep.ServiceEndpointPort, ServiceContractType = ep.ServiceContractType, EndpointBindingType = ep.Binding.BindingType, EndpointBindingXml = ep.Binding.BindingXml != null ? ep.Binding.BindingXml.ToString() : "", EndpointProtocol = ep.Binding.BindingProtocol, ServiceType = ep.ServiceType, }).FirstOrDefault(); if (wcfClientEndpoint == null) { LocalLogService.Log("wcfClientEndpoint = null"); return null; } var wcfService = data.Services.Where(s => s.ServiceType == wcfClientEndpoint.ServiceType).FirstOrDefault(); if (wcfService == null) { LocalLogService.Log("wcfService = null"); return null; } var wcfServerFarm = wcfService.ServerFarm; wcfClientEndpoint.EndpointAddress = wcfServerFarm.ServerFarmAddress; wcfClientEndpoint.ServerFarmName = wcfServerFarm.ServerFarmName; var accessableFarmNames = data.ClientAccesses.ToList().Where(acc => acc.ClientMachineIP == "*" || machineIP.Contains(acc.ClientMachineIP)).Select(a => a.AccessServerFarmName).ToList(); if (!accessableFarmNames.Contains("*") && !accessableFarmNames.Contains(wcfClientEndpoint.ServerFarmName)) { LocalLogService.Log("accessableFarmNames = null"); return null; } var query = (from ce in data.ClientEndpoints where ce.ServiceContractType == wcfClientEndpoint.ServiceContractType select ce.ClientEndpointBehaviorXml).FirstOrDefault(); wcfClientEndpoint.EndpointBehaviorXml = query != null ? query.ToString() : ""; return wcfClientEndpoint; } } catch (Exception ex) { LocalLogService.Log(ex.ToString()); return null; } }