示例#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
        public List <string> GetServiceNamesFromConfigFile()
        {
            List <string>            ServiceNames = null;
            Configuration            appConfig    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);
            ServicesSection          services     = serviceModel.Services;
            ServiceElementCollection sec          = services.Services;

            if (sec.Count > 0)
            {
                ServiceNames   = new List <string>();
                m_serviceTypes = new Dictionary <string, Type>();
                foreach (ServiceElement se in sec)
                {
                    ServiceNames.Add(se.Name);

                    Type t = Type.GetType(se.Name);
                    if (t == null)
                    {
                        string[] sa = se.Name.Split('.');
                        System.Reflection.Assembly a = System.Reflection.Assembly.LoadFrom(sa[0] + ".dll");
                        t = a.GetType(se.Name);
                    }

                    m_serviceTypes.Add(se.Name, t);
                }
            }
            return(ServiceNames);
        }
        public void GetServicesTest()
        {
            ServiceElementCollection services = LoadManager().GetServices();

            Assert.IsNotNull(services);
            Assert.IsTrue(services.Count > 0);
        }
        int NumEndpointsForClsid(Configuration config, Guid clsid, Guid appId)
        {
            ServiceModelSectionGroup sg          = ServiceModelSectionGroup.GetSectionGroup(config);
            ServiceElementCollection serviceColl = sg.Services.Services;

            foreach (ServiceElement se in serviceColl)
            {
                string[] serviceParams = se.Name.Split(',');
                if (serviceParams.Length != 2)
                {
                    continue;
                }

                Guid serviceAppId;
                Guid serviceClsid;

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

                if (serviceClsid == clsid && serviceAppId == appId)
                {
                    return(se.Endpoints.Count);
                }
            }

            return(0);
        }
示例#5
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);
        }
示例#6
0
        /// <summary>
        /// The try generate service file.
        /// </summary>
        /// <param name="serviceType">
        /// The service type.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected virtual bool TryGenerateServiceFile(Type serviceType)
        {
            if (serviceType == null)
            {
                return(false);
            }

            lock (ServicesToContracts)
            {
                if (ServicesToContracts.ContainsKey(serviceType))
                {
                    return(true);
                }

                ServiceElementCollection services = WCFUtil.GetServices();
                if (services != null)
                {
                    foreach (ServiceElement element in services)
                    {
                        if ((element.Name == serviceType.FullName) && this.ExistsPureWCFEndpoint(element.Endpoints))
                        {
                            string path = Paths.GetWebORBPath() + Path.DirectorySeparatorChar + ServicesDirectory;
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            Type   type        = TypeLoader.LoadType(element.Endpoints[0].Contract);
                            string serviceFile = string.Concat(new object[] { path, Path.DirectorySeparatorChar, serviceType.FullName, ServiceExtension });
                            ServicesToContracts[serviceType] = type;
                            if (!File.Exists(serviceFile))
                            {
                                TextWriter writer = new StreamWriter(serviceFile);
                                writer.WriteLine("<%@ ServiceHost Language='C#' Service='{0}'%>", serviceType.FullName);
                                writer.Close();
                                if (Log.isLogging(LoggingConstants.INFO))
                                {
                                    Log.log(LoggingConstants.INFO, string.Format("SVC file was generated for service {0}", serviceType.FullName));
                                }
                            }

                            return(true);
                        }
                    }

                    if (Log.isLogging(LoggingConstants.INFO))
                    {
                        Log.log(LoggingConstants.INFO, "Object " + serviceType.FullName + " has no WCF contract implemented");
                    }
                }

                return(false);
            }
        }
示例#7
0
        protected bool RemoveAllServicesForContract(Configuration config, string interfaceID)
        {
            ServiceModelSectionGroup sg          = ServiceModelSectionGroup.GetSectionGroup(config);
            ServiceElementCollection serviceColl = sg.Services.Services;
            bool removed = false;
            // Iterate over every serviceElement
            // in the services collection
            // and delete the specific interface
            ServiceElementCollection svcColl = new ServiceElementCollection();

            foreach (ServiceElement el in serviceColl)
            {
                ServiceEndpointElementCollection endpointCollection = new ServiceEndpointElementCollection();
                foreach (ServiceEndpointElement ee in el.Endpoints)
                {
                    if (interfaceID.ToUpperInvariant() == ee.Contract.ToUpperInvariant())
                    {
                        // found it !
                        removed = true;
                        endpointCollection.Add(ee);
                    }
                }
                foreach (ServiceEndpointElement elementEndpoint in endpointCollection)
                {
                    el.Endpoints.Remove(elementEndpoint);
                    if (el.Endpoints.Count == 1)
                    {
                        if (el.Endpoints[0].Contract == ServiceMetadataBehavior.MexContractName)
                        {
                            el.Endpoints.Remove(el.Endpoints[0]); // if Mex endpoint remove it.
                        }
                    }
                    if (el.Endpoints.Count == 0)
                    {
                        svcColl.Add(el);
                    }
                }
            }
            foreach (ServiceElement service in svcColl)
            {
                sg.Services.Services.Remove(service);
            }
            if (serviceColl.Count == 0)
            {
                EnsureComMetaDataExchangeBehaviorRemoved(config);
                RemoveBinding(config);
            }
            return(removed);
        }
示例#8
0
        protected bool RemoveComContractIfNotUsedByAnyService(Configuration config, string interfaceID)
        {
            ServiceModelSectionGroup sg          = ServiceModelSectionGroup.GetSectionGroup(config);
            ServiceElementCollection serviceColl = sg.Services.Services;
            Guid iidInterface = new Guid(interfaceID);

            // Find serviceElement
            foreach (ServiceElement el in serviceColl)
            {
                // Now, check if endpoint already exists..
                foreach (ServiceEndpointElement ee in el.Endpoints)
                {
                    try
                    {
                        if (!IsMetaDataEndpoint(ee))
                        {
                            Guid Iid = new Guid(ee.Contract);
                            if (iidInterface == Iid)
                            {
                                return(false);
                            }
                        }
                    }
                    catch (FormatException)
                    {
                    }
                }
            }
            ComContractElementCollection contractCollection = sg.ComContracts.ComContracts;

            foreach (ComContractElement element in contractCollection)
            {
                try
                {
                    Guid contract = new Guid(element.Contract);
                    if (contract == iidInterface)
                    {
                        contractCollection.Remove(element);
                        return(true);
                    }
                }
                catch (FormatException)
                {
                }
            }
            return(false);
        }
示例#9
0
        /// <summary>
        /// Recherche un point d'accès serveur dans la configuration WCF.
        /// </summary>
        /// <param name="serviceType">Type du service.</param>
        /// <param name="contractType">Type du contrat.</param>
        /// <returns>Retourne le point d'accès.</returns>
        private ServiceEndpointElement HasWcfServerEndPoint(Type serviceType, Type contractType)
        {
            if (_serviceModelSection == null)
            {
                return(null);
            }

            ServiceElementCollection coll = _serviceModelSection.Services.Services;

            if (coll.ContainsKey(serviceType.FullName))
            {
                ServiceElement element = coll[serviceType.FullName];
                return(element.Endpoints.Cast <ServiceEndpointElement>().FirstOrDefault(sep => sep.Contract.Equals(contractType.FullName)));
            }

            return(null);
        }
示例#10
0
        // Token: 0x060002BB RID: 699 RVA: 0x000125D0 File Offset: 0x000107D0
        internal AutodiscoverWebConfiguration()
        {
            Configuration            config   = WebConfigurationManager.OpenWebConfiguration("~/web.config");
            ServiceElementCollection services = ServiceModelSectionGroup.GetSectionGroup(config).Services.Services;

            foreach (object obj in services)
            {
                ServiceElement serviceElement = (ServiceElement)obj;
                foreach (object obj2 in serviceElement.Endpoints)
                {
                    ServiceEndpointElement serviceEndpointElement = (ServiceEndpointElement)obj2;
                    if (!string.IsNullOrEmpty(serviceEndpointElement.BindingConfiguration) && serviceEndpointElement.Contract.Equals(Common.EndpointContract, StringComparison.OrdinalIgnoreCase))
                    {
                        if (serviceEndpointElement.Address.OriginalString.Equals("wssecurity/symmetrickey", StringComparison.OrdinalIgnoreCase))
                        {
                            this.wsSecuritySymmetricKeyEndpointEnabled = true;
                        }
                        else if (serviceEndpointElement.Address.OriginalString.Equals("wssecurity/x509cert", StringComparison.OrdinalIgnoreCase))
                        {
                            this.wsSecurityX509CertEndpointEnabled = true;
                        }
                        else if (serviceEndpointElement.Address.OriginalString.Equals("wssecurity", StringComparison.OrdinalIgnoreCase))
                        {
                            this.wsSecurityEndpointEnabled = true;
                        }
                        else if (serviceEndpointElement.Address.OriginalString.Equals(AutodiscoverWebConfiguration.soapAddress, StringComparison.OrdinalIgnoreCase))
                        {
                            this.soapEndpointEnabled = true;
                        }
                    }
                }
            }
            this.oAuthEndpointEnabled             = OAuthHttpModule.IsModuleLoaded.Value;
            this.mySiteServiceUrlTemplate         = WebConfigurationManager.AppSettings["mySiteServiceUrlTemplate"];
            this.mySiteLocationUrlTemplate        = WebConfigurationManager.AppSettings["mySiteLocationUrlTemplate"];
            this.projectSiteServiceUrl            = WebConfigurationManager.AppSettings["projectSiteServiceUrl"];
            this.projectSiteLocationUrl           = WebConfigurationManager.AppSettings["projectSiteLocationUrl"];
            this.documentTypesSupportedForSharing = WebConfigurationManager.AppSettings["documentTypesSupportedForSharing"];
        }
示例#11
0
        protected bool RemoveAllServicesForContract(Configuration config, string interfaceID)
        {
            ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config);
            ServiceElementCollection serviceColl = sg.Services.Services;
            bool removed = false;
            // Iterate over every serviceElement 
            // in the services collection
            // and delete the specific interface
            ServiceElementCollection svcColl = new ServiceElementCollection();
            foreach (ServiceElement el in serviceColl)
            {
                ServiceEndpointElementCollection endpointCollection = new ServiceEndpointElementCollection();
                foreach (ServiceEndpointElement ee in el.Endpoints)
                {
                    if (interfaceID.ToUpperInvariant() == ee.Contract.ToUpperInvariant())
                    {
                        // found it !
                        removed = true;
                        endpointCollection.Add(ee);
                    }
                }
                foreach (ServiceEndpointElement elementEndpoint in endpointCollection)
                {
                    el.Endpoints.Remove(elementEndpoint);
                    if (el.Endpoints.Count == 1)
                        if (el.Endpoints[0].Contract == ServiceMetadataBehavior.MexContractName)
                            el.Endpoints.Remove(el.Endpoints[0]); // if Mex endpoint remove it.
                    if (el.Endpoints.Count == 0)
                        svcColl.Add(el);
                }

            }
            foreach (ServiceElement service in svcColl)
            {
                sg.Services.Services.Remove(service);
            }
            if (serviceColl.Count == 0)
            {
                EnsureComMetaDataExchangeBehaviorRemoved(config);
                RemoveBinding(config);
            }
            return removed;
        }
示例#12
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);
        }
示例#13
0
 public void Setup()
 {
     collection = new ServiceElementCollection();
 }