/// <summary> /// wcf服务端常量设置文件 /// </summary> /// <param name="doc"></param> public WcfConstantSettingConfig(XmlDocument doc) { mlist = new List <WcfServerBinding>(); try { foreach (XmlElement elems in XmlHelper.Children(doc.DocumentElement, "Servers")) { foreach (XmlElement elem in XmlHelper.Children(elems, "Binding")) { WcfServerBinding wcfServerBind = new WcfServerBinding(); XmlElement xe = XmlHelper.Child(elem, "readerQuotas"); wcfServerBind.MaxDepth = int.Parse(xe.GetAttribute("maxDepth")); wcfServerBind.MaxStringContentLength = int.Parse(xe.GetAttribute("maxStringContentLength")); wcfServerBind.MaxArrayLength = int.Parse(xe.GetAttribute("maxArrayLength")); wcfServerBind.MaxBytesPerRead = int.Parse(xe.GetAttribute("maxBytesPerRead")); wcfServerBind.MaxNameTableCharCount = int.Parse(xe.GetAttribute("maxNameTableCharCount")); XmlElement xea = XmlHelper.Child(elem, "reliableSession"); wcfServerBind.ReliableSessionEnabled = Boolean.Parse(xea.GetAttribute("enabled")); wcfServerBind.ReliableSessionOrdered = Boolean.Parse(xea.GetAttribute("ordered")); wcfServerBind.ReliableSessionInactivityTimeout = TimeSpan.Parse(xea.GetAttribute("inactivityTimeout")); XmlElement xe1 = XmlHelper.Child(elem, "host"); wcfServerBind.BaseAddress = new Uri(xe1.GetAttribute("baseAddress")); switch (xe1.GetAttribute("binding").ToLower()) { case "netTcpBinding": wcfServerBind.Binding = new NetTcpBinding(); break; } XmlElement xe2 = XmlHelper.Child(elem, "behaviors"); wcfServerBind.CloseTimeout = TimeSpan.Parse(xe2.GetAttribute("closeTimeout")); wcfServerBind.OpenTimeout = TimeSpan.Parse(xe2.GetAttribute("openTimeout")); wcfServerBind.ReceiveTimeout = TimeSpan.Parse(xe2.GetAttribute("receiveTimeout")); wcfServerBind.SendTimeout = TimeSpan.Parse(xe2.GetAttribute("sendTimeout")); wcfServerBind.TransactionFlow = Boolean.Parse(xe2.GetAttribute("transactionFlow")); wcfServerBind.TransferMode = (TransferMode)Enum.Parse(typeof(TransferMode), xe2.GetAttribute("transferMode")); switch (xe2.GetAttribute("transactionProtocol").ToLower()) { case "oletransactions": wcfServerBind.TransactionProtocol = TransactionProtocol.OleTransactions; break; case "wsatomictransaction11": wcfServerBind.TransactionProtocol = TransactionProtocol.WSAtomicTransaction11; break; case "wsatomictransactionoctober2004": wcfServerBind.TransactionProtocol = TransactionProtocol.WSAtomicTransactionOctober2004; break; default: wcfServerBind.TransactionProtocol = TransactionProtocol.Default; break; } wcfServerBind.HostNameComparisonMode = (HostNameComparisonMode)Enum.Parse(typeof(HostNameComparisonMode), xe2.GetAttribute("hostNameComparisonMode")); wcfServerBind.ListenBacklog = int.Parse(xe2.GetAttribute("listenBacklog")); wcfServerBind.MaxBufferPoolSize = int.Parse(xe2.GetAttribute("maxBufferPoolSize")); wcfServerBind.MaxBufferSize = int.Parse(xe2.GetAttribute("maxBufferSize")); wcfServerBind.MaxConnections = int.Parse(xe2.GetAttribute("maxConnections")); wcfServerBind.MaxReceivedMessageSize = int.Parse(xe2.GetAttribute("maxReceivedMessageSize")); wcfServerBind.PortSharingEnabled = bool.Parse(xe2.GetAttribute("portSharingEnabled")); wcfServerBind.Securitymode = (SecurityMode)Enum.Parse(typeof(SecurityMode), xe2.GetAttribute("securitymode")); wcfServerBind.ClientCredentialType = (MessageCredentialType)Enum.Parse(typeof(MessageCredentialType), xe2.GetAttribute("clientCredentialType")); //_enableBinaryFormatterBehavior = bool.Parse(xe2.GetAttribute("enableBinaryFormatterBehavior")); XmlElement xe3 = XmlHelper.Child(elem, "serviceDebug"); wcfServerBind.IncludeExceptionDetailInFaults = bool.Parse(xe3.GetAttribute("includeExceptionDetailInFaults")); XmlElement xe4 = XmlHelper.Child(elem, "serviceThrottling"); wcfServerBind.MaxConcurrentCalls = int.Parse(xe4.GetAttribute("maxConcurrentCalls")); wcfServerBind.MaxConcurrentInstances = int.Parse(xe4.GetAttribute("maxConcurrentInstances")); wcfServerBind.MaxConcurrentSessions = int.Parse(xe4.GetAttribute("maxConcurrentSessions")); //XmlElement xe5 = XmlHelper.Child(elem, "dataContractSerializer"); //int.TryParse(xe5.GetAttribute("maxItemsInObjectGraph"), out _maxItemsInObjectGraph); mlist.Add(wcfServerBind); } } } catch (Exception oe) { throw new ArgumentException(oe.Message); } }
/// <summary> /// wcf服务端常量设置文件 /// </summary> /// <param name="doc"></param> public WcfConstantSettingConfig(XmlDocument doc) { mlist=new List<WcfServerBinding>(); try { foreach (XmlElement elems in XmlHelper.Children(doc.DocumentElement, "Servers")) { foreach (XmlElement elem in XmlHelper.Children(elems, "Binding")) { WcfServerBinding wcfServerBind = new WcfServerBinding(); XmlElement xe = XmlHelper.Child(elem, "readerQuotas"); wcfServerBind.MaxDepth=int.Parse(xe.GetAttribute("maxDepth")); wcfServerBind.MaxStringContentLength = int.Parse(xe.GetAttribute("maxStringContentLength")); wcfServerBind.MaxArrayLength = int.Parse(xe.GetAttribute("maxArrayLength")); wcfServerBind.MaxBytesPerRead = int.Parse(xe.GetAttribute("maxBytesPerRead")); wcfServerBind.MaxNameTableCharCount = int.Parse(xe.GetAttribute("maxNameTableCharCount")); XmlElement xea = XmlHelper.Child(elem, "reliableSession"); wcfServerBind.ReliableSessionEnabled = Boolean.Parse(xea.GetAttribute("enabled")); wcfServerBind.ReliableSessionOrdered = Boolean.Parse(xea.GetAttribute("ordered")); wcfServerBind.ReliableSessionInactivityTimeout = TimeSpan.Parse(xea.GetAttribute("inactivityTimeout")); XmlElement xe1 = XmlHelper.Child(elem, "host"); wcfServerBind.BaseAddress = new Uri(xe1.GetAttribute("baseAddress")); switch (xe1.GetAttribute("binding").ToLower()) { case "netTcpBinding": wcfServerBind.Binding = new NetTcpBinding(); break; } XmlElement xe2 = XmlHelper.Child(elem, "behaviors"); wcfServerBind.CloseTimeout = TimeSpan.Parse(xe2.GetAttribute("closeTimeout")); wcfServerBind.OpenTimeout = TimeSpan.Parse(xe2.GetAttribute("openTimeout")); wcfServerBind.ReceiveTimeout = TimeSpan.Parse(xe2.GetAttribute("receiveTimeout")); wcfServerBind.SendTimeout = TimeSpan.Parse(xe2.GetAttribute("sendTimeout")); wcfServerBind.TransactionFlow = Boolean.Parse(xe2.GetAttribute("transactionFlow")); wcfServerBind.TransferMode = (TransferMode)Enum.Parse(typeof(TransferMode), xe2.GetAttribute("transferMode")); switch (xe2.GetAttribute("transactionProtocol").ToLower()) { case "oletransactions": wcfServerBind.TransactionProtocol = TransactionProtocol.OleTransactions; break; case "wsatomictransaction11": wcfServerBind.TransactionProtocol = TransactionProtocol.WSAtomicTransaction11; break; case "wsatomictransactionoctober2004": wcfServerBind.TransactionProtocol = TransactionProtocol.WSAtomicTransactionOctober2004; break; default: wcfServerBind.TransactionProtocol = TransactionProtocol.Default; break; } wcfServerBind.HostNameComparisonMode = (HostNameComparisonMode)Enum.Parse(typeof(HostNameComparisonMode), xe2.GetAttribute("hostNameComparisonMode")); wcfServerBind.ListenBacklog = int.Parse(xe2.GetAttribute("listenBacklog")); wcfServerBind.MaxBufferPoolSize = int.Parse(xe2.GetAttribute("maxBufferPoolSize")); wcfServerBind.MaxBufferSize = int.Parse(xe2.GetAttribute("maxBufferSize")); wcfServerBind.MaxConnections = int.Parse(xe2.GetAttribute("maxConnections")); wcfServerBind.MaxReceivedMessageSize = int.Parse(xe2.GetAttribute("maxReceivedMessageSize")); wcfServerBind.PortSharingEnabled = bool.Parse(xe2.GetAttribute("portSharingEnabled")); wcfServerBind.Securitymode = (SecurityMode)Enum.Parse(typeof(SecurityMode), xe2.GetAttribute("securitymode")); wcfServerBind.ClientCredentialType = (MessageCredentialType)Enum.Parse(typeof(MessageCredentialType), xe2.GetAttribute("clientCredentialType")); //_enableBinaryFormatterBehavior = bool.Parse(xe2.GetAttribute("enableBinaryFormatterBehavior")); XmlElement xe3 = XmlHelper.Child(elem, "serviceDebug"); wcfServerBind.IncludeExceptionDetailInFaults = bool.Parse(xe3.GetAttribute("includeExceptionDetailInFaults")); XmlElement xe4 = XmlHelper.Child(elem, "serviceThrottling"); wcfServerBind.MaxConcurrentCalls = int.Parse(xe4.GetAttribute("maxConcurrentCalls")); wcfServerBind.MaxConcurrentInstances = int.Parse(xe4.GetAttribute("maxConcurrentInstances")); wcfServerBind.MaxConcurrentSessions = int.Parse(xe4.GetAttribute("maxConcurrentSessions")); //XmlElement xe5 = XmlHelper.Child(elem, "dataContractSerializer"); //int.TryParse(xe5.GetAttribute("maxItemsInObjectGraph"), out _maxItemsInObjectGraph); mlist.Add(wcfServerBind); } } } catch (Exception oe) { throw new ArgumentException(oe.Message); } }