/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/BindingsSection.cs

https://github.com/t-ashula/mono · C# · 179 lines · 131 code · 20 blank · 28 comment · 12 complexity · 7df170655aa1b6b24dc99d2e19862b26 MD5 · raw file

  1. //
  2. // BindingsSection.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <atsushi@ximian.com>
  6. //
  7. // Copyright (C) 2006 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Collections.ObjectModel;
  32. using System.ComponentModel;
  33. using System.Configuration;
  34. using System.Net;
  35. using System.Net.Security;
  36. using System.Reflection;
  37. using System.Security.Cryptography.X509Certificates;
  38. using System.Security.Principal;
  39. using System.IdentityModel.Claims;
  40. using System.IdentityModel.Policy;
  41. using System.IdentityModel.Tokens;
  42. using System.ServiceModel;
  43. using System.ServiceModel.Channels;
  44. using System.ServiceModel.Description;
  45. using System.ServiceModel.Diagnostics;
  46. using System.ServiceModel.Dispatcher;
  47. using System.ServiceModel.MsmqIntegration;
  48. using System.ServiceModel.PeerResolvers;
  49. using System.ServiceModel.Security;
  50. using System.Runtime.Serialization;
  51. using System.Text;
  52. using System.Xml;
  53. namespace System.ServiceModel.Configuration
  54. {
  55. public sealed class BindingsSection
  56. : ConfigurationSection
  57. {
  58. ConfigurationPropertyCollection _properties;
  59. List<BindingCollectionElement> _collections;
  60. // Properties
  61. [ConfigurationProperty ("basicHttpBinding",
  62. Options = ConfigurationPropertyOptions.None)]
  63. public BasicHttpBindingCollectionElement BasicHttpBinding {
  64. get { return (BasicHttpBindingCollectionElement) this ["basicHttpBinding"]; }
  65. }
  66. [ConfigurationProperty ("basicHttpsBinding",
  67. Options = ConfigurationPropertyOptions.None)]
  68. public BasicHttpsBindingCollectionElement BasicHttpsBinding {
  69. get { return (BasicHttpsBindingCollectionElement) this ["basicHttpsBinding"]; }
  70. }
  71. public List<BindingCollectionElement> BindingCollections {
  72. get {
  73. if (_collections != null)
  74. return _collections;
  75. _collections = new List<BindingCollectionElement> ();
  76. foreach (PropertyInformation prop in ElementInformation.Properties) {
  77. var element = prop.Value as BindingCollectionElement;
  78. if (element != null)
  79. _collections.Add (element);
  80. }
  81. return _collections;
  82. }
  83. }
  84. [ConfigurationProperty ("customBinding",
  85. Options = ConfigurationPropertyOptions.None)]
  86. public CustomBindingCollectionElement CustomBinding {
  87. get { return (CustomBindingCollectionElement) this ["customBinding"]; }
  88. }
  89. [ConfigurationProperty ("msmqIntegrationBinding",
  90. Options = ConfigurationPropertyOptions.None)]
  91. public MsmqIntegrationBindingCollectionElement MsmqIntegrationBinding {
  92. get { return (MsmqIntegrationBindingCollectionElement) this ["msmqIntegrationBinding"]; }
  93. }
  94. [ConfigurationProperty ("netMsmqBinding",
  95. Options = ConfigurationPropertyOptions.None)]
  96. public NetMsmqBindingCollectionElement NetMsmqBinding {
  97. get { return (NetMsmqBindingCollectionElement) this ["netMsmqBinding"]; }
  98. }
  99. [ConfigurationProperty ("netNamedPipeBinding",
  100. Options = ConfigurationPropertyOptions.None)]
  101. public NetNamedPipeBindingCollectionElement NetNamedPipeBinding {
  102. get { return (NetNamedPipeBindingCollectionElement) this ["netNamedPipeBinding"]; }
  103. }
  104. [ConfigurationProperty ("netPeerTcpBinding",
  105. Options = ConfigurationPropertyOptions.None)]
  106. public NetPeerTcpBindingCollectionElement NetPeerTcpBinding {
  107. get { return (NetPeerTcpBindingCollectionElement) this ["netPeerTcpBinding"]; }
  108. }
  109. [ConfigurationProperty ("netTcpBinding",
  110. Options = ConfigurationPropertyOptions.None)]
  111. public NetTcpBindingCollectionElement NetTcpBinding {
  112. get { return (NetTcpBindingCollectionElement) this ["netTcpBinding"]; }
  113. }
  114. protected override ConfigurationPropertyCollection Properties {
  115. get {
  116. if (_properties == null) {
  117. _properties = new ConfigurationPropertyCollection ();
  118. ExtensionElementCollection extensions = ((ExtensionsSection) EvaluationContext.GetSection ("system.serviceModel/extensions")).BindingExtensions;
  119. for (int i = 0; i < extensions.Count; i++) {
  120. ExtensionElement extension = extensions [i];
  121. _properties.Add (new ConfigurationProperty (extension.Name, Type.GetType (extension.Type), null, null, null, ConfigurationPropertyOptions.None));
  122. }
  123. }
  124. return _properties;
  125. }
  126. }
  127. [ConfigurationProperty ("wsDualHttpBinding",
  128. Options = ConfigurationPropertyOptions.None)]
  129. public WSDualHttpBindingCollectionElement WSDualHttpBinding {
  130. get { return (WSDualHttpBindingCollectionElement) this ["wsDualHttpBinding"]; }
  131. }
  132. [ConfigurationProperty ("wsFederationHttpBinding",
  133. Options = ConfigurationPropertyOptions.None)]
  134. public WSFederationHttpBindingCollectionElement WSFederationHttpBinding {
  135. get { return (WSFederationHttpBindingCollectionElement) this ["wsFederationHttpBinding"]; }
  136. }
  137. [ConfigurationProperty ("wsHttpBinding",
  138. Options = ConfigurationPropertyOptions.None)]
  139. public WSHttpBindingCollectionElement WSHttpBinding {
  140. get { return (WSHttpBindingCollectionElement) this ["wsHttpBinding"]; }
  141. }
  142. public static BindingsSection GetSection (System.Configuration.Configuration config) {
  143. ServiceModelSectionGroup sm = ServiceModelSectionGroup.GetSectionGroup (config);
  144. if (sm == null)
  145. throw new SystemException ("Could not retrieve configuration section group 'system.serviceModel'");
  146. if (sm.Bindings == null)
  147. throw new SystemException ("Could not retrieve configuration sub section group 'bindings' in 'system.serviceModel'");
  148. return sm.Bindings;
  149. }
  150. public new BindingCollectionElement this [string name] {
  151. get {
  152. object element = base [name];
  153. if (element is BindingCollectionElement)
  154. return (BindingCollectionElement) element;
  155. throw new NotImplementedException (String.Format ("Could not find {0}", name));
  156. }
  157. }
  158. }
  159. }