Example #1
0
        public override void Run()
        {
            var servicesSection = (ServicesSection)GetConfig().GetSection("system.serviceModel/services");

            var services = servicesSection.Services;

            if (services.Count == 0)
            {
                throw new AssertionException("No services section could be found.");
            }

            BaseAddressElement baseAddress = null;

            foreach (ServiceElement se in services.OfType <ServiceElement>().Where(se => se.Name == ServiceName))
            {
                var baseAddressElements = se.Host.BaseAddresses.OfType <BaseAddressElement>();
                baseAddress = baseAddressElements.FirstOrDefault(e => e.BaseAddress == ExpectedBaseAddressValue);
                AssertState.NotNull(baseAddress, "Base address is incorrect or not present");
            }

            if (baseAddress == null)
            {
                throw new AssertionException(string.Format("Could not find Base address with name {0}", ServiceName));
            }
        }
Example #2
0
        // 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);
        }