Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void CanRemoveElement()
        {
            ServiceElement se = new ServiceElement();

            se.ServiceType             = typeof(object);
            collection[se.ServiceType] = se;
            collection.Remove(typeof(object));

            Assert.AreEqual(0, collection.Count);
            Assert.IsNull(collection[typeof(object)]);
        }