/// <summary> /// Sets the system.serviceModel/serviceHostingEnvironment multipleSiteBindingsEnabled property to the /// specified value. /// </summary> /// <param name="enabled">The value to set for the multipleSiteBindingsEnabled property.</param> public void SetMultipleSiteBindingsEnabled(bool enabled) { ServiceHostingEnvironmentSection section = this._configuration.GetSection(ServiceHostingEnvironmentFullSectionName) as ServiceHostingEnvironmentSection; if (section != null) { section.MultipleSiteBindingsEnabled = enabled; } }
/// <summary> /// Sets the system.serviceModel/serviceHostingEnvironment aspNetCompatibilityEnabled property to the /// specified value. /// </summary> /// <param name="enabled">The value to set for the aspNetCompatibilityEnabled property.</param> public void SetAspNetCompatibilityEnabled(bool enabled) { ServiceHostingEnvironmentSection section = this._configuration.GetSection(ServiceHostingEnvironmentFullSectionName) as ServiceHostingEnvironmentSection; if (section != null) { section.AspNetCompatibilityEnabled = enabled; } }
private void UpdateServiceActivations(ServiceHostingEnvironmentSection serviceHostingEnvironmentSection) { var serviceHostTypes = TestDefinitionHelper.GetAttributedServiceHostTypes(); foreach (var sht in serviceHostTypes) { foreach (TestServiceDefinitionAttribute attr in sht.GetCustomAttributes(typeof(TestServiceDefinitionAttribute), false)) { var sae = new ServiceActivationElement(attr.BasePath, sht.AssemblyQualifiedName, "WcfService.ActivationServiceHostFactory, __Code"); serviceHostingEnvironmentSection.ServiceActivations.Add(sae); } } }
void AddHostedTransportConfigurationIis7(string protocol) { HostedTransportConfiguration configuration = null; try { ServiceHostingEnvironmentSection section = ServiceHostingEnvironmentSection.GetSection(); if (section.TransportConfigurationTypes.ContainsKey(protocol)) { TransportConfigurationTypeElement element = section.TransportConfigurationTypes[protocol]; Debug.Print("HostedTransportConfigurationManager.AddHostedTransportConfigurationIis7() found TransportConfigurationTypes for protocol: " + protocol + " name: " + element.TransportConfigurationType); Type type = Type.GetType(element.TransportConfigurationType); configuration = Activator.CreateInstance(type) as HostedTransportConfiguration; configurations.Add(protocol, configuration); } else { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.Hosting_ProtocolNoConfiguration(protocol))); } } catch (Exception exception) { if (!Fx.IsFatal(exception)) { Debug.Print("HostedTransportConfigurationManager.AddHostedTransportConfigurationIis7() caught exception: " + exception); if (DiagnosticUtility.ShouldTraceError) { TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.WebHostProtocolMisconfigured, SR.TraceCodeWebHostProtocolMisconfigured, new StringTraceRecord("Protocol", protocol), this, exception); } } throw; } }
private void AddHostedTransportConfigurationIis7(string protocol) { HostedTransportConfiguration configuration = null; try { ServiceHostingEnvironmentSection section = ServiceHostingEnvironmentSection.GetSection(); if (!section.TransportConfigurationTypes.ContainsKey(protocol)) { throw FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activation.SR.Hosting_ProtocolNoConfiguration(protocol))); } TransportConfigurationTypeElement element = section.TransportConfigurationTypes[protocol]; configuration = Activator.CreateInstance(Type.GetType(element.TransportConfigurationType)) as HostedTransportConfiguration; this.configurations.Add(protocol, configuration); } catch (Exception exception) { if (!Fx.IsFatal(exception) && DiagnosticUtility.ShouldTraceError) { System.ServiceModel.Activation.Diagnostics.TraceUtility.TraceEvent(TraceEventType.Error, 0x90006, System.ServiceModel.Activation.SR.TraceCodeWebHostProtocolMisconfigured, new StringTraceRecord("Protocol", protocol), this, exception); } throw; } }
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); } }
// update the configuration options in <system.serviceModel> section public virtual void SystemServiceModel() { #if !ClientSKUFramework ServiceHostingEnvironmentSection serviceHostingEnvironmentSection = config.GetSection("system.serviceModel/serviceHostingEnvironment") as ServiceHostingEnvironmentSection; // serviceHostingEnvironment -> aspNetCompatibilityEnabled serviceHostingEnvironmentSection.AspNetCompatibilityEnabled = _AspNetCompatibilityEnabled; BindingsSection bindingsSection = config.GetSection("system.serviceModel/bindings") as BindingsSection; WebHttpBindingCollectionElement webHttpBindingCollectionElement; WebHttpBindingElement webHttpBindingElement; foreach (BindingCollectionElement bindingCollectionElement in bindingsSection.BindingCollections) { // find WebHttpBinding element "higherMessageSize" and modify its settings if (bindingCollectionElement.BindingType.ToString().Equals("System.ServiceModel.WebHttpBinding")) { webHttpBindingCollectionElement = bindingCollectionElement as WebHttpBindingCollectionElement; webHttpBindingElement = webHttpBindingCollectionElement.Bindings["higherMessageSize"]; if (webHttpBindingElement != null) { // webHttpBinding -> binding -> transferMode switch (_TransferMode.ToLower()) { case "streamed": webHttpBindingElement.TransferMode = System.ServiceModel.TransferMode.Streamed; break; case "streamedrequest": webHttpBindingElement.TransferMode = System.ServiceModel.TransferMode.StreamedRequest; break; case "streamedresponse": webHttpBindingElement.TransferMode = System.ServiceModel.TransferMode.StreamedResponse; break; default: webHttpBindingElement.TransferMode = System.ServiceModel.TransferMode.Buffered; break; } // webHttpBinding -> binding -> MaxBufferSize, MaxReceivedMessageSize, and timeout's webHttpBindingElement.MaxBufferSize = _MaxBufferSize; webHttpBindingElement.MaxReceivedMessageSize = _MaxReceivedMessageSize; webHttpBindingElement.CloseTimeout = TimeSpan.Parse(_CloseTimeout); webHttpBindingElement.OpenTimeout = TimeSpan.Parse(_OpenTimeout); webHttpBindingElement.ReceiveTimeout = TimeSpan.Parse(_ReceiveTimeout); webHttpBindingElement.SendTimeout = TimeSpan.Parse(_SendTimeout); // webHttpBinding -> binding -> security mode switch (_TransportSecurityMode.ToLower()) { case "none": webHttpBindingElement.Security.Mode = System.ServiceModel.WebHttpSecurityMode.None; break; case "transport": webHttpBindingElement.Security.Mode = System.ServiceModel.WebHttpSecurityMode.Transport; break; default: webHttpBindingElement.Security.Mode = System.ServiceModel.WebHttpSecurityMode.TransportCredentialOnly; break; } // webHttpBinding -> binding -> security ->transport WebHttpSecurityElement webHttpSecurityElement = webHttpBindingElement.Security; switch (_AuthMode.ToLower()) { case "windows": webHttpSecurityElement.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; webHttpSecurityElement.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.Windows; break; case "ntlm": webHttpSecurityElement.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Ntlm; webHttpSecurityElement.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.Ntlm; break; case "basic": webHttpSecurityElement.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic; webHttpSecurityElement.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.Basic; break; case "digest": webHttpSecurityElement.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Digest; webHttpSecurityElement.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.Digest; break; default: webHttpSecurityElement.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None; webHttpSecurityElement.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; break; } } } } #endif }
/// <summary> /// Determines whether system.serviceModel/serviceHostingEnvironment multipleSiteBindingsEnabled property /// is properly configured to support our domain service. /// </summary> /// <returns><c>true</c> means the aspNetCompatibilityEnabled property is set in the configuration.</returns> public bool IsMultipleSiteBindingsEnabled() { ServiceHostingEnvironmentSection section = this._configuration.GetSection(ServiceHostingEnvironmentFullSectionName) as ServiceHostingEnvironmentSection; return(section != null && section.MultipleSiteBindingsEnabled); }
/// <summary> /// Determines whether system.serviceModel/serviceHostingEnvironment aspNetCompatibilityEnabled property /// is properly configured to support our domain service. /// </summary> /// <returns><c>true</c> means the aspNetCompatibilityEnabled property is set in the configuration.</returns> public bool IsAspNetCompatibilityEnabled() { ServiceHostingEnvironmentSection section = this._configuration.GetSection(ServiceHostingEnvironmentFullSectionName) as ServiceHostingEnvironmentSection; return(section != null && section.AspNetCompatibilityEnabled); }