public BasicHttpBinding(string configurationName) : this() { BindingsSection bindingsSection = Configuration.ConfigUtil.BindingsSection; BasicHttpBindingElement el = bindingsSection.BasicHttpBinding.Bindings[configurationName]; el.ApplyConfiguration(this); }
public void CanGetDefaultStandardBindingWithNullBindingName() { BasicHttpBindingElement defaultElement = new BasicHttpBindingElement("NewBinding"); BasicHttpBindingElement element = LoadManager().GetStandardBinding <BasicHttpBinding, BasicHttpBindingElement>(null); Assert.IsTrue(string.IsNullOrEmpty(element.Name)); Assert.AreEqual(defaultElement.Security, element.Security); }
private BasicHttpBindingElement CreateBasicHttpBinding(string name, BasicHttpSecurityMode mode, HttpClientCredentialType credentialType) { BasicHttpBindingElement basicHttpBinding = new BasicHttpBindingElement(); basicHttpBinding.Name = name; basicHttpBinding.Security.Mode = mode; basicHttpBinding.Security.Transport.ClientCredentialType = credentialType; return(basicHttpBinding); }
private void ApplyConfiguration(string configurationName) { BasicHttpBindingElement element2 = BasicHttpBindingCollectionElement.GetBindingCollectionElement().Bindings[configurationName]; if (element2 == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidBindingConfigurationName", new object[] { configurationName, "basicHttpBinding" }))); } element2.ApplyConfiguration(this); }
public void DefaultTextEncoding() { var b1 = new BasicHttpBinding(); var b2 = new BasicHttpBinding(); Assert.AreEqual(b1.TextEncoding, b2.TextEncoding, "#1"); var element = new BasicHttpBindingElement(); Assert.AreEqual(element.TextEncoding, b1.TextEncoding, "#2"); }
public void AddStandardBindingTest() { BasicHttpBindingElement element = new BasicHttpBindingElement("newBasicBinding"); ServiceModelConfigurationManager manager = LoadManager(); manager.AddStandardBinding <BasicHttpBinding, BasicHttpBindingElement>(element); BasicHttpBindingElement addedElement = manager.GetStandardBinding <BasicHttpBinding, BasicHttpBindingElement>(element.Name); Assert.AreEqual(element.Name, addedElement.Name); }
private BasicHttpBinding CreateBindingFromConfig() { ServiceModelSectionGroup config = (ServiceModelSectionGroup)ConfigurationManager.OpenExeConfiguration("Test/config/basicHttpBinding").GetSectionGroup("system.serviceModel"); BindingsSection section = (BindingsSection)config.Bindings; BasicHttpBindingElement el = section.BasicHttpBinding.Bindings ["BasicHttpBinding2_Service"]; BasicHttpBinding b = new BasicHttpBinding(); el.ApplyConfiguration(b); return(b); }
private void CheckRuleForBasicBinding(BasicHttpBindingElement basicHttpBinding) { if (basicHttpBinding != null && (basicHttpBinding.Security.Mode == BasicHttpSecurityMode.None || (basicHttpBinding.Security.Mode == BasicHttpSecurityMode.Message && basicHttpBinding.Security.Message.ClientCredentialType == BasicHttpMessageCredentialType.UserName) ) ) { AddProblem(basicHttpBinding.Name); } }
public void ConfiguredBindings() { Poker poker = new Poker(); Assert.AreEqual(0, poker.ConfiguredBindings.Count, "Count #1"); BasicHttpBindingElement elem = new BasicHttpBindingElement("my_binding"); poker.Bindings.Add(elem); Assert.AreEqual(1, poker.ConfiguredBindings.Count, "Count #2"); Assert.AreEqual(elem, poker.ConfiguredBindings [0], "Instance"); }
public void BasicHttpBinding() { ServiceModelSectionGroup config = (ServiceModelSectionGroup)ConfigurationManager.OpenExeConfiguration("Test/config/basicHttpBinding").GetSectionGroup("system.serviceModel"); BasicHttpBindingCollectionElement basicHttpBinding = config.Bindings.BasicHttpBinding; Assert.AreEqual(2, basicHttpBinding.Bindings.Count, "count"); BasicHttpBindingElement binding = basicHttpBinding.Bindings [0]; Assert.AreEqual("BasicHttpBinding_Service", binding.Name, "Name"); Assert.AreEqual(Encoding.UTF8, binding.TextEncoding, "Name"); Assert.AreEqual(SecurityAlgorithmSuite.Default, binding.Security.Message.AlgorithmSuite, "Name"); }
void ApplyConfiguration(string configurationName) { BasicHttpBindingCollectionElement section = BasicHttpBindingCollectionElement.GetBindingCollectionElement(); BasicHttpBindingElement element = section.Bindings[configurationName]; if (element == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException( SR.GetString(SR.ConfigInvalidBindingConfigurationName, configurationName, ConfigurationStrings.BasicHttpBindingCollectionElementName))); } else { element.ApplyConfiguration(this); } }
public void BindingSection_WithBasicHttpBindingTest() { string expectedName = "basicHttpBindingConfig"; long expectedMaxReceivedMessageSize = 1073741824; long expectedMaxBufferSize = 1073741824; int expectedMaxDepth = 2147483647; TimeSpan expectedReceiveTimeout = TimeSpan.FromMinutes(10); BasicHttpSecurityMode expectedSecurityMode = BasicHttpSecurityMode.TransportWithMessageCredential; string xml = $@" <configuration> <configSections> <sectionGroup name=""system.serviceModel"" type=""CoreWCF.Configuration.ServiceModelSectionGroup, CoreWCF.ConfigurationManager""> <section name=""bindings"" type=""CoreWCF.Configuration.BindingsSection, CoreWCF.ConfigurationManager"" /> </sectionGroup> </configSections> <system.serviceModel> <bindings> <basicHttpBinding> <binding name=""{expectedName}"" maxReceivedMessageSize=""{expectedMaxReceivedMessageSize}"" maxBufferSize=""{expectedMaxBufferSize}"" receiveTimeout=""{expectedReceiveTimeout}""> <security mode=""{expectedSecurityMode}""/> <readerQuotas maxDepth=""{expectedMaxDepth}"" /> </binding> </basicHttpBinding> </bindings> </system.serviceModel> </configuration>"; using (var fs = TemporaryFileStream.Create(xml)) { ServiceModelSectionGroup section = GetSectionFromXml(fs); BasicHttpBindingElement actualBinding = section.Bindings.BasicHttpBinding.Bindings.Cast <BasicHttpBindingElement>().First(); Assert.Equal(expectedName, actualBinding.Name); Assert.Equal(expectedMaxReceivedMessageSize, actualBinding.MaxReceivedMessageSize); Assert.Equal(expectedMaxBufferSize, actualBinding.MaxBufferSize); Assert.Equal(expectedReceiveTimeout, actualBinding.ReceiveTimeout); Assert.Equal(expectedSecurityMode, actualBinding.Security.Mode); Assert.Equal(expectedMaxDepth, actualBinding.ReaderQuotas.MaxDepth); } }
internal static Binding CreateBinding(string type, string xml) { Binding binding = null; StandardBindingElement element = null; switch (type) { case "NetTcpBinding": binding = new NetTcpBinding(); element = new NetTcpBindingElement(); break; case "BasicHttpBinding": binding = new BasicHttpBinding(); element = new BasicHttpBindingElement(); break; case "WSHttpBinding": binding = new WSHttpBinding(); element = new WSHttpBindingElement(); break; case "NetNamedPipeBinding": binding = new NetNamedPipeBinding(); element = new NetNamedPipeBindingElement(); break; case "NetMsmqBinding": binding = new NetMsmqBinding(); element = new NetMsmqBindingElement(); break; default: binding = new NetTcpBinding(); element = new NetTcpBindingElement(); break; } Deserialize(xml, element); element.ApplyConfiguration(binding); return(binding); }
/// <summary> /// 生成Binding对象 /// <code> /// WCFMateHelper.BindingFactory(config, e) /// </code> /// </summary> /// <param name="config"></param> /// <param name="chanelEndpoint"></param> /// <returns></returns> public static Binding BindingFactory(System.Configuration.Configuration config, ChannelEndpointElement chanelEndpoint) { BindingsSection bindings = config.GetSection("system.serviceModel/bindings") as BindingsSection; BindingCollectionElement bc = bindings[chanelEndpoint.Binding]; //chanelEndpoint. if (chanelEndpoint.Binding != "") { switch (chanelEndpoint.Binding.ToLower()) { case "nettcpbinding": { NetTcpBinding ntb = new NetTcpBinding(); NetTcpBindingElement bce = bc.ConfiguredBindings.FirstOrDefault(o => o.Name == chanelEndpoint.BindingConfiguration) as NetTcpBindingElement; if (bce != null) { ntb.CloseTimeout = bce.CloseTimeout; ntb.OpenTimeout = bce.OpenTimeout; ntb.ReceiveTimeout = bce.ReceiveTimeout; ntb.SendTimeout = bce.SendTimeout; ntb.MaxBufferPoolSize = bce.MaxBufferPoolSize; ntb.HostNameComparisonMode = bce.HostNameComparisonMode; ntb.ListenBacklog = (bce.ListenBacklog != 0 ? bce.ListenBacklog : ntb.ListenBacklog); ntb.MaxBufferSize = bce.MaxBufferSize; ntb.MaxConnections = (bce.MaxConnections == 0 ? ntb.MaxConnections : bce.MaxConnections); ntb.MaxReceivedMessageSize = bce.MaxReceivedMessageSize; ntb.PortSharingEnabled = bce.PortSharingEnabled; ntb.ReaderQuotas.MaxArrayLength = (bce.ReaderQuotas.MaxArrayLength != 0 ? bce.ReaderQuotas.MaxArrayLength : ntb.ReaderQuotas.MaxArrayLength); ntb.ReaderQuotas.MaxDepth = (bce.ReaderQuotas.MaxDepth != 0 ? bce.ReaderQuotas.MaxDepth : ntb.ReaderQuotas.MaxDepth); ntb.ReaderQuotas.MaxBytesPerRead = (bce.ReaderQuotas.MaxBytesPerRead != 0 ? bce.ReaderQuotas.MaxBytesPerRead : ntb.ReaderQuotas.MaxBytesPerRead); ntb.ReaderQuotas.MaxNameTableCharCount = (bce.ReaderQuotas.MaxNameTableCharCount != 0 ? bce.ReaderQuotas.MaxNameTableCharCount : ntb.ReaderQuotas.MaxNameTableCharCount); ntb.ReaderQuotas.MaxStringContentLength = (bce.ReaderQuotas.MaxStringContentLength != 0 ? bce.ReaderQuotas.MaxStringContentLength : ntb.ReaderQuotas.MaxStringContentLength); ntb.ReliableSession = new OptionalReliableSession() { Enabled = bce.ReliableSession.Enabled, InactivityTimeout = bce.ReliableSession.InactivityTimeout, Ordered = bce.ReliableSession.Ordered }; ntb.Security = new NetTcpSecurity() { Mode = SecurityMode.None }; ntb.TransactionFlow = bce.TransactionFlow; ntb.TransactionProtocol = bce.TransactionProtocol; ntb.TransferMode = bce.TransferMode; } return(ntb); } case "basichttpbinding": { BasicHttpBinding bhb = new BasicHttpBinding(BasicHttpSecurityMode.None); BasicHttpBindingElement bce = bc.ConfiguredBindings.FirstOrDefault(o => o.Name == chanelEndpoint.BindingConfiguration) as BasicHttpBindingElement; if (bce != null) { bhb.AllowCookies = bce.AllowCookies; bhb.BypassProxyOnLocal = bce.BypassProxyOnLocal; bhb.CloseTimeout = bce.CloseTimeout; bhb.HostNameComparisonMode = bce.HostNameComparisonMode; bhb.MaxBufferPoolSize = bce.MaxBufferPoolSize; bhb.MaxBufferSize = bce.MaxBufferSize; bhb.MaxReceivedMessageSize = bce.MaxReceivedMessageSize; bhb.MessageEncoding = bce.MessageEncoding; bhb.OpenTimeout = bce.OpenTimeout; bhb.ProxyAddress = bce.ProxyAddress; bhb.ReaderQuotas.MaxArrayLength = (bce.ReaderQuotas.MaxArrayLength != 0 ? bce.ReaderQuotas.MaxArrayLength : bhb.ReaderQuotas.MaxArrayLength); bhb.ReaderQuotas.MaxDepth = (bce.ReaderQuotas.MaxDepth != 0 ? bce.ReaderQuotas.MaxDepth : bhb.ReaderQuotas.MaxDepth); bhb.ReaderQuotas.MaxBytesPerRead = (bce.ReaderQuotas.MaxBytesPerRead != 0 ? bce.ReaderQuotas.MaxBytesPerRead : bhb.ReaderQuotas.MaxBytesPerRead); bhb.ReaderQuotas.MaxNameTableCharCount = (bce.ReaderQuotas.MaxNameTableCharCount != 0 ? bce.ReaderQuotas.MaxNameTableCharCount : bhb.ReaderQuotas.MaxNameTableCharCount); bhb.ReaderQuotas.MaxStringContentLength = (bce.ReaderQuotas.MaxStringContentLength != 0 ? bce.ReaderQuotas.MaxStringContentLength : bhb.ReaderQuotas.MaxStringContentLength); bhb.ReceiveTimeout = bce.ReceiveTimeout; bhb.SendTimeout = bce.SendTimeout; bhb.TextEncoding = bce.TextEncoding; bhb.TransferMode = bce.TransferMode; bhb.UseDefaultWebProxy = bce.UseDefaultWebProxy; } return(bhb); } case "wshttpbinding": { WSHttpBinding bhb = new WSHttpBinding(SecurityMode.None); WSHttpBindingElement bce = bc.ConfiguredBindings.FirstOrDefault(o => o.Name == chanelEndpoint.BindingConfiguration) as WSHttpBindingElement; if (bce != null) { bhb.AllowCookies = bce.AllowCookies; bhb.BypassProxyOnLocal = bce.BypassProxyOnLocal; bhb.CloseTimeout = bce.CloseTimeout; bhb.HostNameComparisonMode = bce.HostNameComparisonMode; bhb.MaxBufferPoolSize = bce.MaxBufferPoolSize; bhb.MaxReceivedMessageSize = bce.MaxReceivedMessageSize; bhb.MessageEncoding = bce.MessageEncoding; bhb.OpenTimeout = bce.OpenTimeout; bhb.ProxyAddress = bce.ProxyAddress; bhb.ReaderQuotas.MaxArrayLength = (bce.ReaderQuotas.MaxArrayLength != 0 ? bce.ReaderQuotas.MaxArrayLength : bhb.ReaderQuotas.MaxArrayLength); bhb.ReaderQuotas.MaxDepth = (bce.ReaderQuotas.MaxDepth != 0 ? bce.ReaderQuotas.MaxDepth : bhb.ReaderQuotas.MaxDepth); bhb.ReaderQuotas.MaxBytesPerRead = (bce.ReaderQuotas.MaxBytesPerRead != 0 ? bce.ReaderQuotas.MaxBytesPerRead : bhb.ReaderQuotas.MaxBytesPerRead); bhb.ReaderQuotas.MaxNameTableCharCount = (bce.ReaderQuotas.MaxNameTableCharCount != 0 ? bce.ReaderQuotas.MaxNameTableCharCount : bhb.ReaderQuotas.MaxNameTableCharCount); bhb.ReaderQuotas.MaxStringContentLength = (bce.ReaderQuotas.MaxStringContentLength != 0 ? bce.ReaderQuotas.MaxStringContentLength : bhb.ReaderQuotas.MaxStringContentLength); bhb.ReceiveTimeout = bce.ReceiveTimeout; bhb.SendTimeout = bce.SendTimeout; bhb.TextEncoding = bce.TextEncoding; bhb.TransactionFlow = bce.TransactionFlow; bhb.UseDefaultWebProxy = bce.UseDefaultWebProxy; } return(bhb); } } } throw new BindingNotFoundException(Resources.BindingNotFoundException); }
public static void AddConfigKeys(EnvDTE.Project project, string sqlServerName, string btsDTADb, string btsMgmtDb) { Configuration conf = null; foreach (EnvDTE.ProjectItem item in project.ProjectItems) { if (item.Name.ToLower() == "app.config") { ExeConfigurationFileMap map = new ExeConfigurationFileMap { ExeConfigFilename = item.FileNames[0] }; conf = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); break; } } if (conf == null) { XmlDocument appConfigXml = new XmlDocument(); string configPath = Path.Combine(new FileInfo(project.FullName).Directory.FullName, "App.config"); appConfigXml.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><configuration></configuration>"); appConfigXml.Save(configPath); project.ProjectItems.AddFromFile(configPath); ExeConfigurationFileMap map = new ExeConfigurationFileMap { ExeConfigFilename = configPath }; conf = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); } if (conf.AppSettings.Settings["BizTalkDbServer"] == null) { conf.AppSettings.Settings.Add("BizTalkDbServer", sqlServerName); } if (conf.AppSettings.Settings["BizTalkDTADb"] == null) { conf.AppSettings.Settings.Add("BizTalkDTADb", btsDTADb); } if (conf.AppSettings.Settings["BizTalkMgmtDb"] == null) { conf.AppSettings.Settings.Add("BizTalkMgmtDb", btsMgmtDb); } if (conf.AppSettings.Settings["TrackedMessageCopyJobName"] == null) { conf.AppSettings.Settings.Add("TrackedMessageCopyJobName", "TrackedMessages_Copy_" + btsMgmtDb); } if (conf.AppSettings.Settings["MaxHistory"] == null) { conf.AppSettings.Settings.Add("MaxHistory", "100"); } if (conf.ConnectionStrings.ConnectionStrings["BizTalkDTADbEntities"] == null) { conf.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("BizTalkDTADbEntities", String.Format("metadata=res://*/BizTalk.Entities.BizTalkDTAModel.csdl|res://*/BizTalk.Entities.BizTalkDTAModel.ssdl|res://*/BizTalk.Entities.BizTalkDTAModel.msl;provider=System.Data.SqlClient;provider connection string=\";Data Source={0};Initial Catalog={1};Integrated Security=True;MultipleActiveResultSets=True\"", sqlServerName, btsDTADb), "System.Data.EntityClient")); } ServiceModelSectionGroup serviceModel = (ServiceModelSectionGroup)conf.GetSectionGroup("system.serviceModel"); BasicHttpBindingElement oneWayBinding = new BasicHttpBindingElement("BasicHttpBinding_ITwoWayAsyncVoid"); oneWayBinding.Security.Mode = BasicHttpSecurityMode.None; oneWayBinding.TextEncoding = Encoding.UTF8; oneWayBinding.AllowCookies = false; oneWayBinding.BypassProxyOnLocal = false; oneWayBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; oneWayBinding.MessageEncoding = WSMessageEncoding.Text; oneWayBinding.TransferMode = TransferMode.Buffered; oneWayBinding.UseDefaultWebProxy = true; oneWayBinding.ReaderQuotas.MaxDepth = 32; oneWayBinding.ReaderQuotas.MaxStringContentLength = 8192; oneWayBinding.ReaderQuotas.MaxArrayLength = 16384; oneWayBinding.ReaderQuotas.MaxBytesPerRead = 4096; oneWayBinding.ReaderQuotas.MaxNameTableCharCount = 16384; serviceModel.Bindings.BasicHttpBinding.Bindings.Add(oneWayBinding); BasicHttpBindingElement twoWayBinding = new BasicHttpBindingElement("BasicHttpBinding_ITwoWayAsync"); twoWayBinding.Security.Mode = BasicHttpSecurityMode.None; twoWayBinding.TextEncoding = Encoding.UTF8; twoWayBinding.AllowCookies = false; twoWayBinding.BypassProxyOnLocal = false; twoWayBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; twoWayBinding.MessageEncoding = WSMessageEncoding.Text; twoWayBinding.TransferMode = TransferMode.Buffered; twoWayBinding.UseDefaultWebProxy = true; twoWayBinding.ReaderQuotas.MaxDepth = 32; twoWayBinding.ReaderQuotas.MaxStringContentLength = 8192; twoWayBinding.ReaderQuotas.MaxArrayLength = 16384; twoWayBinding.ReaderQuotas.MaxBytesPerRead = 4096; twoWayBinding.ReaderQuotas.MaxNameTableCharCount = 16384; serviceModel.Bindings.BasicHttpBinding.Bindings.Add(twoWayBinding); ChannelEndpointElement ep1Way = new ChannelEndpointElement(new EndpointAddress("http://localhost:9000/BizWTF.Testing.Ports.IN.OneWay"), "BizTalk1WayReference.ITwoWayAsyncVoid"); ep1Way.Binding = "basicHttpBinding"; ep1Way.Name = "BasicHttpBinding_ITwoWayAsyncVoid"; ep1Way.BindingConfiguration = "BasicHttpBinding_ITwoWayAsyncVoid"; serviceModel.Client.Endpoints.Add(ep1Way); ChannelEndpointElement ep2Way = new ChannelEndpointElement(new EndpointAddress("http://localhost:9000/BizWTF.Testing.Ports.IN.TwoWay"), "BizTalk2WayReference.ITwoWayAsync"); ep2Way.Binding = "basicHttpBinding"; ep2Way.Name = "BasicHttpBinding_ITwoWayAsync"; ep2Way.BindingConfiguration = "BasicHttpBinding_ITwoWayAsync"; serviceModel.Client.Endpoints.Add(ep2Way); //conf.SectionGroups.Add("system.serviceModel", serviceModel); conf.Save(ConfigurationSaveMode.Minimal, true); }
public void ThrowOnGetStandardBindingThatNotExistsTest() { BasicHttpBindingElement addedElement = LoadManager().GetStandardBinding <BasicHttpBinding, BasicHttpBindingElement>("NotExist"); }
public void GetStandardBindingTest() { BasicHttpBindingElement element = LoadManager().GetStandardBinding <BasicHttpBinding, BasicHttpBindingElement>(Constants.ServiceBindingName); Assert.AreEqual(Constants.ServiceBindingName, element.Name); }