protected internal void DeployAppConfig() { IOUtil.FindAndWriteResourceToFile(this.GetType().Assembly, "app.config", ExecutablePath + ".config"); Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ExecutablePath); #if !ClientSKUFramework if (AstoriaTestProperties.Host == Host.WebServiceHost) { 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 -> security ->transport WebHttpSecurityElement webHttpSecurityElement = webHttpBindingElement.Security; switch (AstoriaTestProperties.HostAuthenicationMethod.ToLower()) { case "windows": webHttpSecurityElement.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows; webHttpSecurityElement.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.Windows; break; default: webHttpSecurityElement.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None; webHttpSecurityElement.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; break; } } } } } #endif if (Database != null) { // fixup config files config.ConnectionStrings.ConnectionStrings.Clear(); config.ConnectionStrings.ConnectionStrings.Add(this.Workspace.GetConnectionStringSettingsForProvider(this, this.Database.DatabaseConnectionString)); } config.Save(); if (AstoriaTestProperties.WebServiceHostTargetFramework != null) { //Would rather do this through the API but unsure how string contents = File.ReadAllText(ExecutablePath + ".config"); int configurationPos = contents.IndexOf("<configuration>"); string startupStr = string.Format("<startup><supportedRuntime version=\"{0}\"/></startup>", AstoriaTestProperties.WebServiceHostTargetFramework); contents = contents.Insert(configurationPos + 16, startupStr); File.WriteAllText(ExecutablePath + ".config", contents); } }
// 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 }