예제 #1
0
        /// <summary>
        /// Determines whether system.serviceModel/domainServices has an endpoint
        /// declared of the given name.
        /// </summary>
        /// <param name="endpointName">The name of the endpoint to check.</param>
        /// <returns><c>true</c> means there is an endpoint with that name declared.</returns>
        public bool IsEndpointDeclared(string endpointName)
        {
            Debug.Assert(!string.IsNullOrEmpty(endpointName), "endpointName cannot be empty");

            DomainServicesSection domainServicesSection = this._configuration.GetSection(DomainServicesFullSectionName) as DomainServicesSection;

            return((domainServicesSection != null) &&
                   domainServicesSection.Endpoints.OfType <ProviderSettings>().Any(p => string.Equals(p.Name, endpointName, StringComparison.OrdinalIgnoreCase)));
        }
예제 #2
0
        public override void Init()
        {
            base.Init();
            DomainServiceHttpModule.Init(this);

            DomainServicesSection config = DomainServicesSection.Current;

            config.Endpoints.Add(new System.Configuration.ProviderSettings("json", typeof(JsonEndpointFactory).AssemblyQualifiedName));
            config.Endpoints.Add(new System.Configuration.ProviderSettings("soap", typeof(SoapXmlEndpointFactory).AssemblyQualifiedName));
        }
        public void DomainServicesSection_Initialize()
        {
            DomainServicesSection s = new DomainServicesSection();

            s.InitializeDefaultInternal();
            Assert.AreEqual(1, s.Endpoints.Count, "Default endpoint not added.");

            // Calling it again is safe.
            s.InitializeDefaultInternal();
            Assert.AreEqual(1, s.Endpoints.Count, "Default endpoint not added.");
        }
예제 #4
0
        /// <summary>
        /// Adds the specified endpoint to the "system.serviceModel/domainServices" endpoint collection.
        /// </summary>
        /// <param name="endpointName">The name of the new endpoint to add.</param>
        /// <param name="endpointFactoryTypeName">The fully qualified type name of the endpoint factory type.</param>
        public void AddEndpointDeclaration(string endpointName, string endpointFactoryTypeName)
        {
            Debug.Assert(!string.IsNullOrEmpty(endpointName), "endpointName cannot be empty");
            Debug.Assert(!string.IsNullOrEmpty(endpointFactoryTypeName), "endpointFactoryTypeName cannot be empty");

            if (!string.IsNullOrEmpty(endpointName) && !string.IsNullOrEmpty(endpointFactoryTypeName))
            {
                bool createdDomainServicesSection           = false;
                DomainServicesSection domainServicesSection = this.GetOrCreateDomainServicesSection(out createdDomainServicesSection);
                if (domainServicesSection != null)
                {
                    // If the DomainServicesSection existed, just add the new endpoint
                    if (!createdDomainServicesSection)
                    {
                        domainServicesSection.Endpoints.Add(new ProviderSettings(endpointName, endpointFactoryTypeName));
                    }
                    else
                    {
                        // However, if we created it manually, we need to insert the new endpoint manually,
                        // otherwise the configuration logic believes we are overriding the defaults
                        // and emits extra <remove> elements.
                        string rawXml = domainServicesSection.SectionInformation.GetRawXml();
                        if (string.IsNullOrEmpty(rawXml))
                        {
                            rawXml = "<domainServices><endpoints /></domainServices>";
                        }
                        XDocument xdoc = WebConfigUtil.CreateXDoc(rawXml);

                        XElement xelem         = xdoc.Element("domainServices");
                        XElement endpointsElem = xelem == null ? null : xelem.Element("endpoints");
                        if (endpointsElem != null)
                        {
                            // Add a new <add name="xxx" type="yyy" /> element to the endpoints collection
                            XElement newEndpointElem = new XElement("add");
                            newEndpointElem.Add(new XAttribute("name", endpointName));
                            newEndpointElem.Add(new XAttribute("type", endpointFactoryTypeName));
                            endpointsElem.Add(newEndpointElem);
                            rawXml = WebConfigUtil.CreateRawXml(xdoc);
                            domainServicesSection.SectionInformation.SetRawXml(rawXml);
                        }
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Returns the <see cref="DomainServicesSection"/> for the "system.serviceModel/domainServices"
        /// section.  If it does not exist, a new default one will be created.
        /// </summary>
        /// <param name="created">Output parameter that is set to <c>true</c> if the section did not exist and was created here.</param>
        /// <returns>A new or existing <see cref="DomainServicesSection"/>.</returns>
        public DomainServicesSection GetOrCreateDomainServicesSection(out bool created)
        {
            created = false;
            DomainServicesSection domainServicesSection = this._configuration.GetSection(DomainServicesFullSectionName) as DomainServicesSection;

            if (domainServicesSection == null)
            {
                ServiceModelSectionGroup serviceModelSectionGroup = this.GetOrCreateServiceModelSectionGroup();

                domainServicesSection = this._configuration.GetSection(DomainServicesFullSectionName) as DomainServicesSection;
                if (domainServicesSection == null)
                {
                    domainServicesSection = new DomainServicesSection();
                    domainServicesSection.SectionInformation.AllowDefinition   = ConfigurationAllowDefinition.MachineToApplication;
                    domainServicesSection.SectionInformation.RequirePermission = false;
                    serviceModelSectionGroup.Sections.Add(DomainServicesSectionName, domainServicesSection);
                    created = true;
                }
            }
            return(domainServicesSection);
        }
예제 #6
0
        public void WebConfigUtil_UpdateConfiguration()
        {
            string tempConfigFile = Path.GetTempFileName();

            try
            {
                File.WriteAllText(tempConfigFile, EmptyConfig);
                System.Configuration.Configuration cfg = ConfigurationManager.OpenExeConfiguration(tempConfigFile);
                WebConfigUtil webConfigUtil            = new WebConfigUtil(cfg);

                // Verify that none of the sections we wat to set are present
                Assert.IsFalse(webConfigUtil.IsAspNetCompatibilityEnabled(), "Blank config should not have AspNetCompatibility");
                Assert.IsFalse(webConfigUtil.IsMultipleSiteBindingsEnabled(), "Blank config should not have MultiSiteBinding");
                Assert.IsFalse(webConfigUtil.IsEndpointDeclared(BusinessLogicClassConstants.ODataEndpointName), "Blank config should not have OData endpoint");
                Assert.IsTrue(webConfigUtil.DoWeNeedToValidateIntegratedModeToWebServer(), "Blank config should not have validate integrated mode");
                Assert.IsTrue(webConfigUtil.DoWeNeedToAddHttpModule(), "Blank config should not have http module");
                Assert.IsTrue(webConfigUtil.DoWeNeedToAddModuleToWebServer(), "Blank config should not have http module to web server");

                string domainServiceFactoryName = WebConfigUtil.GetDomainServiceModuleTypeName();
                Assert.IsFalse(string.IsNullOrEmpty(domainServiceFactoryName), "Could not find domain service factory name");

                // ------------------------------------
                // Set everything we set from the wizard
                // ------------------------------------
                webConfigUtil.SetAspNetCompatibilityEnabled(true);
                webConfigUtil.SetMultipleSiteBindingsEnabled(true);
                webConfigUtil.AddValidateIntegratedModeToWebServer();
                webConfigUtil.AddHttpModule(domainServiceFactoryName);
                webConfigUtil.AddModuleToWebServer(domainServiceFactoryName);

                // ------------------------------------
                // Verify API's see the changes
                // ------------------------------------
                Assert.IsTrue(webConfigUtil.IsAspNetCompatibilityEnabled(), "Failed to set AspNetCompatibility");
                Assert.IsTrue(webConfigUtil.IsMultipleSiteBindingsEnabled(), "Failed to set MultiSiteBinding");
                Assert.IsFalse(webConfigUtil.DoWeNeedToValidateIntegratedModeToWebServer(), "Failed to set validate integrated mode");
                Assert.IsFalse(webConfigUtil.DoWeNeedToAddHttpModule(), "Failed to set http module");
                Assert.IsFalse(webConfigUtil.DoWeNeedToAddModuleToWebServer(), "Failed to set http module to web server");

                // ------------------------------------
                // Independently verify those changes
                // ------------------------------------
                // AspNetCompat
                ServiceHostingEnvironmentSection section = cfg.GetSection("system.serviceModel/serviceHostingEnvironment") as ServiceHostingEnvironmentSection;
                Assert.IsTrue(section != null && section.AspNetCompatibilityEnabled, "AspNetCompat did not set correct section");

                // MultisiteBindings
                Assert.IsTrue(section != null && section.MultipleSiteBindingsEnabled, "MultisiteBinding did not set correct section");

                // Http modules
                System.Web.Configuration.HttpModulesSection httpModulesSection = cfg.GetSection("system.web/httpModules") as System.Web.Configuration.HttpModulesSection;
                HttpModuleAction module = (httpModulesSection == null)
                                            ? null
                                            : httpModulesSection.Modules.OfType <HttpModuleAction>()
                                          .FirstOrDefault(a => String.Equals(a.Name, BusinessLogicClassConstants.DomainServiceModuleName, StringComparison.OrdinalIgnoreCase));
                Assert.IsNotNull(module, "Did not find httpModule");

                // ------------------------------------
                // Set and verify OData endpoint
                // ------------------------------------
                webConfigUtil.AddEndpointDeclaration(BusinessLogicClassConstants.ODataEndpointName, WebConfigUtil.GetODataEndpointFactoryTypeName());
                Assert.IsTrue(webConfigUtil.IsEndpointDeclared(BusinessLogicClassConstants.ODataEndpointName), "Failed to set OData endpoint");

                DomainServicesSection domainServicesSection = cfg.GetSection("system.serviceModel/domainServices") as DomainServicesSection;
                Assert.IsNotNull(domainServicesSection, "system.serviceModel/domainServices section not found");
                Assert.AreEqual(ConfigurationAllowDefinition.MachineToApplication, domainServicesSection.SectionInformation.AllowDefinition, "AllowDefinition s/b MachineToApplication");
                Assert.IsFalse(domainServicesSection.SectionInformation.RequirePermission, "RequirePermission s/b false");

                ProviderSettings setting = (domainServicesSection == null)
                                            ? null
                                            : domainServicesSection.Endpoints.OfType <ProviderSettings>().FirstOrDefault(p => string.Equals(p.Name, BusinessLogicClassConstants.ODataEndpointName, StringComparison.OrdinalIgnoreCase));
                Assert.IsNotNull(setting, "Did not find OData endpoint in config");

                // ValidateIntegratedMode
                this.CheckValidateIntegratedMode(cfg);

                // WebServer module
                this.CheckWebServerModule(cfg, WebConfigUtil.GetDomainServiceModuleTypeName());
            }
            catch (Exception ex)
            {
                Assert.Fail("Did not expect exception " + ex);
            }
            finally
            {
                File.Delete(tempConfigFile);
            }
        }