public override List <string> GetBaseAddresses(EndpointConfig config) { List <string> ret = new List <string>(); Configuration svcconfig = GetConfiguration(true); ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(svcconfig); ServiceElementCollection serviceColl = sg.Services.Services; ServiceElement serviceElement = null; // Find serviceElement foreach (ServiceElement el in serviceColl) { if (config.MatchServiceType(el.Name)) { serviceElement = el; break; } } if (null == serviceElement) { return(ret); } foreach (BaseAddressElement element in serviceElement.Host.BaseAddresses) { ret.Add(element.BaseAddress); } return(ret); }
protected bool RemoveEndpointFromServiceOnly(Configuration config, EndpointConfig endpointConfig) { ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config); ServiceElementCollection serviceColl = sg.Services.Services; ServiceElement serviceElement = null; // Find serviceElement foreach (ServiceElement el in serviceColl) { if (endpointConfig.MatchServiceType(el.Name)) { serviceElement = el; break; } } if (serviceElement == null) { // Didn't find class return(false); } // Now, check if endpoint already exists.. foreach (ServiceEndpointElement ee in serviceElement.Endpoints) { if (endpointConfig.MatchContract(ee.Contract) && (ee.Address == endpointConfig.Address)) { // found it ! serviceElement.Endpoints.Remove(ee); if (!endpointConfig.IsMexEndpoint) { RemoveComContractIfNotUsedByAnyService(config, ee.Contract); } if (serviceElement.Endpoints.Count == 1) { if (serviceElement.Endpoints[0].Contract == ServiceMetadataBehavior.MexContractName) { serviceElement.Endpoints.Remove(serviceElement.Endpoints[0]); // if Mex endpoint remove it. } } if (serviceElement.Endpoints.Count == 0) { serviceColl.Remove(serviceElement); if (serviceColl.Count == 0) { EnsureComMetaDataExchangeBehaviorRemoved(config); RemoveBinding(config); } } return(true); } } return(false); }
protected bool RemoveEndpointFromServiceOnly(Configuration config, EndpointConfig endpointConfig) { ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config); ServiceElementCollection serviceColl = sg.Services.Services; ServiceElement serviceElement = null; // Find serviceElement foreach (ServiceElement el in serviceColl) { if (endpointConfig.MatchServiceType(el.Name)) { serviceElement = el; break; } } if (serviceElement == null) { // Didn't find class return false; } // Now, check if endpoint already exists.. foreach (ServiceEndpointElement ee in serviceElement.Endpoints) { if (endpointConfig.MatchContract(ee.Contract) && (ee.Address == endpointConfig.Address)) { // found it ! serviceElement.Endpoints.Remove(ee); if (!endpointConfig.IsMexEndpoint) RemoveComContractIfNotUsedByAnyService(config, ee.Contract); if (serviceElement.Endpoints.Count == 1) if (serviceElement.Endpoints[0].Contract == ServiceMetadataBehavior.MexContractName) serviceElement.Endpoints.Remove(serviceElement.Endpoints[0]); // if Mex endpoint remove it. if (serviceElement.Endpoints.Count == 0) { serviceColl.Remove(serviceElement); if (serviceColl.Count == 0) { EnsureComMetaDataExchangeBehaviorRemoved(config); RemoveBinding(config); } } return true; } } return false; }
// returns true if added successfully, or false if didnt add due to duplicate. protected bool BaseAddEndpointConfig(Configuration config, EndpointConfig endpointConfig) { ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config); ServiceElementCollection serviceColl = sg.Services.Services; ServiceElement serviceElement = null; // Find serviceElement foreach (ServiceElement el in serviceColl) { if (endpointConfig.MatchServiceType(el.Name)) { serviceElement = el; break; } } if (serviceElement == null) { // Didn't find one, create new element for this clsid serviceElement = new ServiceElement(endpointConfig.ServiceType); string baseServiceAddress = BaseServiceAddress(endpointConfig.Appid, endpointConfig.Clsid, endpointConfig.Iid); if (!String.IsNullOrEmpty(baseServiceAddress)) { BaseAddressElement bae = new BaseAddressElement(); bae.BaseAddress = baseServiceAddress; serviceElement.Host.BaseAddresses.Add(bae); } sg.Services.Services.Add(serviceElement); } if (endpointConfig.IsMexEndpoint) { EnsureComMetaDataExchangeBehaviorAdded(config); serviceElement.BehaviorConfiguration = comServiceBehavior; } bool methodsAdded = false; if (!endpointConfig.IsMexEndpoint) { methodsAdded = AddComContractToConfig(config, endpointConfig.InterfaceName, endpointConfig.Iid.ToString("B"), endpointConfig.Methods); } // Now, check if endpoint already exists.. foreach (ServiceEndpointElement ee in serviceElement.Endpoints) { bool listenerExists = true; if (this is ComplusEndpointConfigContainer) listenerExists = ((ComplusEndpointConfigContainer)this).ListenerComponentExists; if (endpointConfig.MatchContract(ee.Contract)) { if (listenerExists) return methodsAdded; // didn't add due to duplicate else serviceElement.Endpoints.Remove(ee); } } // All right, add the new endpoint now ServiceEndpointElement endpointElement = new ServiceEndpointElement(endpointConfig.Address, endpointConfig.ContractType); endpointElement.Binding = endpointConfig.BindingType; endpointElement.BindingConfiguration = endpointConfig.BindingName; serviceElement.Endpoints.Add(endpointElement); AddBinding(config); return true; }
public override List<string> GetBaseAddresses(EndpointConfig config) { List<string> ret = new List<string>(); Configuration svcconfig = GetConfiguration(true); ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(svcconfig); ServiceElementCollection serviceColl = sg.Services.Services; ServiceElement serviceElement = null; // Find serviceElement foreach (ServiceElement el in serviceColl) { if (config.MatchServiceType(el.Name)) { serviceElement = el; break; } } if (null == serviceElement) return ret; foreach (BaseAddressElement element in serviceElement.Host.BaseAddresses) ret.Add(element.BaseAddress); return ret; }
// returns true if added successfully, or false if didnt add due to duplicate. protected bool BaseAddEndpointConfig(Configuration config, EndpointConfig endpointConfig) { ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config); ServiceElementCollection serviceColl = sg.Services.Services; ServiceElement serviceElement = null; // Find serviceElement foreach (ServiceElement el in serviceColl) { if (endpointConfig.MatchServiceType(el.Name)) { serviceElement = el; break; } } if (serviceElement == null) { // Didn't find one, create new element for this clsid serviceElement = new ServiceElement(endpointConfig.ServiceType); string baseServiceAddress = BaseServiceAddress(endpointConfig.Appid, endpointConfig.Clsid, endpointConfig.Iid); if (!String.IsNullOrEmpty(baseServiceAddress)) { BaseAddressElement bae = new BaseAddressElement(); bae.BaseAddress = baseServiceAddress; serviceElement.Host.BaseAddresses.Add(bae); } sg.Services.Services.Add(serviceElement); } if (endpointConfig.IsMexEndpoint) { EnsureComMetaDataExchangeBehaviorAdded(config); serviceElement.BehaviorConfiguration = comServiceBehavior; } bool methodsAdded = false; if (!endpointConfig.IsMexEndpoint) { methodsAdded = AddComContractToConfig(config, endpointConfig.InterfaceName, endpointConfig.Iid.ToString("B"), endpointConfig.Methods); } // Now, check if endpoint already exists.. foreach (ServiceEndpointElement ee in serviceElement.Endpoints) { bool listenerExists = true; if (this is ComplusEndpointConfigContainer) { listenerExists = ((ComplusEndpointConfigContainer)this).ListenerComponentExists; } if (endpointConfig.MatchContract(ee.Contract)) { if (listenerExists) { return(methodsAdded); // didn't add due to duplicate } else { serviceElement.Endpoints.Remove(ee); } } } // All right, add the new endpoint now ServiceEndpointElement endpointElement = new ServiceEndpointElement(endpointConfig.Address, endpointConfig.ContractType); endpointElement.Binding = endpointConfig.BindingType; endpointElement.BindingConfiguration = endpointConfig.BindingName; serviceElement.Endpoints.Add(endpointElement); AddBinding(config); return(true); }