예제 #1
0
        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);
        }
예제 #2
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);
        }
예제 #3
0
 // returns true if removed successfully, or false if didnt remove due to missing.
 protected bool BaseRemoveEndpointConfig(Configuration config, EndpointConfig endpointConfig)
 {
     if ((endpointConfig.Methods != null) && (!endpointConfig.IsMexEndpoint))
     {
         bool removeContract = RemoveComContractMethods(config, endpointConfig.Iid.ToString("B"), endpointConfig.Methods);
         if (removeContract)
         {
             RemoveAllServicesForContract(config, endpointConfig.Iid.ToString("B"));
         }
         return(true);
     }
     else
     {
         return(RemoveEndpointFromServiceOnly(config, endpointConfig));
     }
 }
예제 #4
0
        // NOTE that all EndpointConfigs returned by this guy have Guid.Empty as the appid, caller needs to fix that up
        protected Dictionary<string, List<EndpointConfig>> BaseGetEndpointsFromConfiguration(Configuration config)
        {
            Dictionary<string, List<EndpointConfig>> endpointConfigs = new Dictionary<string, List<EndpointConfig>>();

            ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config);
            ServiceElementCollection serviceColl;

            try
            {
                serviceColl = sg.Services.Services;
            }
            catch (System.Configuration.ConfigurationErrorsException e)
            {
                ToolConsole.WriteWarning(e.Message);
                ToolConsole.WriteWarning(SR.GetString(SR.ConfigFileSkipped, e.Filename));

                return endpointConfigs;
            }

            foreach (ServiceElement se in serviceColl)
            {
                string serviceType = se.Name;
                Guid clsid = Guid.Empty;
                Guid appId = Guid.Empty;

                string[] serviceParams = serviceType.Split(',');
                if (serviceParams.Length != 2)
                {
                    continue;
                }

                try
                {
                    appId = new Guid(serviceParams[0]);
                    clsid = new Guid(serviceParams[1]);

                }
                catch (FormatException)
                {
                    // Only Guid serviceTypes are of interest to us - those are the ones our listener picks up
                    continue;
                }


                List<EndpointConfig> list = null;
                if (endpointConfigs.ContainsKey(serviceType))
                {
                    list = endpointConfigs[serviceType];
                }
                else
                {
                    list = new List<EndpointConfig>();
                    endpointConfigs[serviceType] = list;
                }

                foreach (ServiceEndpointElement ee in se.Endpoints)
                {
                    EndpointConfig ec = null;
                    if (!IsMetaDataEndpoint(ee))
                    {
                        Guid contractType;
                        try
                        {
                            contractType = new Guid(ee.Contract);
                        }
                        catch (FormatException)
                        {
                            continue;
                        }
                        ec = new EndpointConfig(Guid.Empty,
                                                               clsid,
                                                               contractType,
                                                               ee.Binding,
                                                               ee.BindingConfiguration,
                                                               ee.Address,
                                                               false, 
                                                               new List<string>());
                    }
                    else
                    {
                        ec = new EndpointConfig(Guid.Empty,
                                                               clsid,
                                                               typeof(IMetadataExchange).GUID,
                                                               ee.Binding,
                                                               ee.BindingConfiguration,
                                                               ee.Address,
                                                               true, new List<string>());
                    }
                    list.Add(ec);
                }
            }
            return endpointConfigs;
        }
예제 #5
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;
        }
예제 #6
0
 public abstract List<string> GetBaseAddresses(EndpointConfig config);
        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;
        }
 public override List<string> GetBaseAddresses(EndpointConfig config)
 {
     return new List<string>();
 }
예제 #9
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);
        }
예제 #10
0
 public abstract List <string> GetBaseAddresses(EndpointConfig config);
예제 #11
0
파일: Tool.cs 프로젝트: JianwenSun/cc
 static bool ShouldDelete(EndpointConfig endpointConfig, IList<ComponentDefinition<Guid>> guidComponents)
 {
     foreach (ComponentDefinition<Guid> component in guidComponents)
     {
         if (component.Component == endpointConfig.Clsid)
         {
             foreach (InterfaceDefination<Guid> interfaceDef in component.Interfaces)
             {
                 if (interfaceDef.Interface == endpointConfig.Iid)
                 {
                     endpointConfig.Methods = interfaceDef.Methods;
                     return true;
                 }
             }
         }
     }
     return false;
 }
예제 #12
0
파일: Tool.cs 프로젝트: JianwenSun/cc
        static void DisplayEndpointConfig(EndpointConfig config)
        {
            List<string> baseAddresses = null;

            if (config.Container != null)
            {
                baseAddresses = config.Container.GetBaseAddresses(config);
            }

            if (null == baseAddresses || 0 == baseAddresses.Count)
            {
                if (config.IsMexEndpoint)
                    ToolConsole.WriteQueryLine("          " + SR.GetString(SR.MexEndpointExposed, config.Address));
                else
                {
                    ToolConsole.WriteQueryLine("             " + SR.GetString(SR.BindingType, config.BindingType));
                    ToolConsole.WriteQueryLine("             " + SR.GetString(SR.BindingConfigurationName, config.BindingName));
                    ToolConsole.WriteQueryLine("             " + SR.GetString(SR.Address, config.Address));
                }
            }
            else
            {
                foreach (string s in baseAddresses)
                {
                    string addr = s + @"/" + config.Address;

                    if (config.IsMexEndpoint)
                        ToolConsole.WriteQueryLine("          " + SR.GetString(SR.MexEndpointExposed, addr));
                    else
                    {
                        ToolConsole.WriteQueryLine("             " + SR.GetString(SR.BindingType, config.BindingType));
                        ToolConsole.WriteQueryLine("             " + SR.GetString(SR.BindingConfigurationName, config.BindingName));
                        ToolConsole.WriteQueryLine("             " + SR.GetString(SR.Address, addr));
                    }
                }
            }

        }
예제 #13
0
파일: Tool.cs 프로젝트: JianwenSun/cc
        static void DoInstall()
        {
            ValidateAddParams();
            ComAdminAppInfo appInfo = ComAdminWrapper.GetAppInfo(options.Application);
            if (appInfo == null)
            {
                throw CreateArgumentException(Cmd.Application, options.Application, SR.GetString(SR.ApplicationNotFound, options.Application), null);
            }

            ValidateApplication(appInfo, options.Hosting);
            Guid sourceAppId = appInfo.ID;

            EndpointConfigContainer container = null;


            if (options.Hosting == Hosting.Complus)
            {
                container = ComplusEndpointConfigContainer.Get(options.Application, true);
                if (container == null)
                {
                    throw CreateArgumentException(Cmd.Application, options.Application, SR.GetString(SR.ApplicationNotFound, options.Application), null);
                }
            }
            else if (options.Hosting == Hosting.Was)
            {
                string webServer = null;
                if (options.WebServer != null)
                {
                    webServer = options.WebServer;
                }
                else
                {
                    webServer = WasEndpointConfigContainer.DefaultWebServer;
                }

                container = WasEndpointConfigContainer.Get(webServer, options.WebDirectory, options.Application);
                if (container == null)
                {
                    throw CreateArgumentException(Cmd.WebDirectory, options.WebDirectory, SR.GetString(SR.WebDirectoryNotFound, options.WebDirectory), null);
                }
            }

            IList<ComponentDefinition<Guid>> guidComponents = null;
            if (options.AllComponents)
            {
                GetAllComponentsForAdd(appInfo, options.Mex, out guidComponents);
            }
            else
            {
                GetComponentsFromInputForAdd(appInfo, options.Components, options.Mex, container.HasEndpointsForApplication(sourceAppId), out guidComponents);
            }

            if (guidComponents.Count == 0)
            {
                if (String.Empty != options.MexOnlyComponent)
                    throw Tool.CreateException(SR.GetString(SR.MexOnlyComponentHasNoExposedInterface, options.MexOnlyComponent), null);
                else
                    throw Tool.CreateException(SR.GetString(SR.NoneOfTheComponentsSatisfiedTheAddCriteria), null);
            }

            List<EndpointConfig> endpointConfigs = new List<EndpointConfig>();

            foreach (ComponentDefinition<Guid> component in guidComponents)
            {
                ComAdminClassInfo componentInfo = appInfo.FindClass(component.Component.ToString("B"));
                Debug.Assert(componentInfo != null, "No component Found");
                string bindingType = null;
                string bindingName = null;
                if (!componentInfo.SupportsTransactionFlow)
                {
                    bindingType = container.DefaultBindingType;
                    bindingName = container.DefaultBindingName;
                }
                else
                {
                    bindingType = container.DefaultTransactionalBindingType;
                    bindingName = container.DefaultTransactionalBindingName;
                }
                foreach (InterfaceDefination<Guid> iInterface in component.Interfaces)
                {
                    Guid iid = iInterface.Interface;
                    EndpointConfig ec = null;
                    if (iid != typeof(IMetadataExchange).GUID)
                    {
                        string address = container.DefaultEndpointAddress(sourceAppId, component.Component, iid);
                        ec = new EndpointConfig(sourceAppId,
                                                               component.Component,
                                                               iid,
                                                               bindingType,
                                                               bindingName,
                                                               new Uri(address, UriKind.RelativeOrAbsolute),
                                                               false,
                                                               (List<string>)iInterface.Methods);
                    }
                    else
                    {
                        ec = new EndpointConfig(sourceAppId,
                                                           component.Component,
                                                           typeof(IMetadataExchange).GUID,
                                                           container.DefaultMexBindingType,
                                                           container.DefaultMexBindingName,
                                                           new Uri(container.DefaultMexAddress(sourceAppId, component.Component), UriKind.RelativeOrAbsolute),
                                                           true,
                                                           null);
                    }

                    endpointConfigs.Add(ec);
                }

            }



            try
            {
                container.Add(endpointConfigs);
                container.PrepareChanges();         // containers can throw from this                
            }
            catch (Exception e)
            {
                if (e is NullReferenceException || e is SEHException)
                {
                    throw;
                }
                container.AbortChanges();
                throw CreateException(SR.GetString(SR.ErrorDuringAdd, options.Application), e);
            }

            container.CommitChanges();
        }
예제 #14
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;
        }
예제 #15
0
        // NOTE that all EndpointConfigs returned by this guy have Guid.Empty as the appid, caller needs to fix that up
        protected Dictionary <string, List <EndpointConfig> > BaseGetEndpointsFromConfiguration(Configuration config)
        {
            Dictionary <string, List <EndpointConfig> > endpointConfigs = new Dictionary <string, List <EndpointConfig> >();

            ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config);
            ServiceElementCollection serviceColl;

            try
            {
                serviceColl = sg.Services.Services;
            }
            catch (System.Configuration.ConfigurationErrorsException e)
            {
                ToolConsole.WriteWarning(e.Message);
                ToolConsole.WriteWarning(SR.GetString(SR.ConfigFileSkipped, e.Filename));

                return(endpointConfigs);
            }

            foreach (ServiceElement se in serviceColl)
            {
                string serviceType = se.Name;
                Guid   clsid       = Guid.Empty;
                Guid   appId       = Guid.Empty;

                string[] serviceParams = serviceType.Split(',');
                if (serviceParams.Length != 2)
                {
                    continue;
                }

                try
                {
                    appId = new Guid(serviceParams[0]);
                    clsid = new Guid(serviceParams[1]);
                }
                catch (FormatException)
                {
                    // Only Guid serviceTypes are of interest to us - those are the ones our listener picks up
                    continue;
                }


                List <EndpointConfig> list = null;
                if (endpointConfigs.ContainsKey(serviceType))
                {
                    list = endpointConfigs[serviceType];
                }
                else
                {
                    list = new List <EndpointConfig>();
                    endpointConfigs[serviceType] = list;
                }

                foreach (ServiceEndpointElement ee in se.Endpoints)
                {
                    EndpointConfig ec = null;
                    if (!IsMetaDataEndpoint(ee))
                    {
                        Guid contractType;
                        try
                        {
                            contractType = new Guid(ee.Contract);
                        }
                        catch (FormatException)
                        {
                            continue;
                        }
                        ec = new EndpointConfig(Guid.Empty,
                                                clsid,
                                                contractType,
                                                ee.Binding,
                                                ee.BindingConfiguration,
                                                ee.Address,
                                                false,
                                                new List <string>());
                    }
                    else
                    {
                        ec = new EndpointConfig(Guid.Empty,
                                                clsid,
                                                typeof(IMetadataExchange).GUID,
                                                ee.Binding,
                                                ee.BindingConfiguration,
                                                ee.Address,
                                                true, new List <string>());
                    }
                    list.Add(ec);
                }
            }
            return(endpointConfigs);
        }
예제 #16
0
 // returns true if removed successfully, or false if didnt remove due to missing.
 protected bool BaseRemoveEndpointConfig(Configuration config, EndpointConfig endpointConfig)
 {
     if ((endpointConfig.Methods != null) && (!endpointConfig.IsMexEndpoint))
     {
         bool removeContract = RemoveComContractMethods(config, endpointConfig.Iid.ToString("B"), endpointConfig.Methods);
         if (removeContract)
             RemoveAllServicesForContract(config, endpointConfig.Iid.ToString("B"));
         return true;
     }
     else
         return RemoveEndpointFromServiceOnly(config, endpointConfig);
 }
 public override List <string> GetBaseAddresses(EndpointConfig config)
 {
     return(new List <string>());
 }