1 //------------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------------------------
4 
5 namespace System.ServiceModel.Configuration
6 {
7     using System.Configuration;
8     using System.ServiceModel;
9     using System.Globalization;
10     using System.ServiceModel.Security;
11     using System.ComponentModel;
12     using System.Text;
13     using System.ServiceModel.Channels;
14 
15     public abstract partial class WSHttpBindingBaseElement : StandardBindingElement
16     {
WSHttpBindingBaseElement(string name)17         protected WSHttpBindingBaseElement(string name)
18             : base(name)
19         {
20         }
21 
WSHttpBindingBaseElement()22         protected WSHttpBindingBaseElement()
23             : this(null)
24         {
25         }
26 
27         [ConfigurationProperty(ConfigurationStrings.BypassProxyOnLocal, DefaultValue = HttpTransportDefaults.BypassProxyOnLocal)]
28         public bool BypassProxyOnLocal
29         {
30             get { return (bool)base[ConfigurationStrings.BypassProxyOnLocal]; }
31             set { base[ConfigurationStrings.BypassProxyOnLocal] = value; }
32         }
33 
34         [ConfigurationProperty(ConfigurationStrings.TransactionFlow, DefaultValue = TransactionFlowDefaults.Transactions)]
35         public bool TransactionFlow
36         {
37             get { return (bool)base[ConfigurationStrings.TransactionFlow]; }
38             set { base[ConfigurationStrings.TransactionFlow] = value; }
39         }
40 
41         [ConfigurationProperty(ConfigurationStrings.HostNameComparisonMode, DefaultValue = HttpTransportDefaults.HostNameComparisonMode)]
42         [ServiceModelEnumValidator(typeof(HostNameComparisonModeHelper))]
43         public HostNameComparisonMode HostNameComparisonMode
44         {
45             get { return (HostNameComparisonMode)base[ConfigurationStrings.HostNameComparisonMode]; }
46             set { base[ConfigurationStrings.HostNameComparisonMode] = value; }
47         }
48 
49         [ConfigurationProperty(ConfigurationStrings.MaxBufferPoolSize, DefaultValue = TransportDefaults.MaxBufferPoolSize)]
50         [LongValidator(MinValue = 0)]
51         public long MaxBufferPoolSize
52         {
53             get { return (long)base[ConfigurationStrings.MaxBufferPoolSize]; }
54             set { base[ConfigurationStrings.MaxBufferPoolSize] = value; }
55         }
56 
57         [ConfigurationProperty(ConfigurationStrings.MaxReceivedMessageSize, DefaultValue = TransportDefaults.MaxReceivedMessageSize)]
58         [LongValidator(MinValue = 1)]
59         public long MaxReceivedMessageSize
60         {
61             get { return (long)base[ConfigurationStrings.MaxReceivedMessageSize]; }
62             set { base[ConfigurationStrings.MaxReceivedMessageSize] = value; }
63         }
64 
65         [ConfigurationProperty(ConfigurationStrings.MessageEncoding, DefaultValue = WSHttpBindingDefaults.MessageEncoding)]
66         [ServiceModelEnumValidator(typeof(WSMessageEncodingHelper))]
67         public WSMessageEncoding MessageEncoding
68         {
69             get { return (WSMessageEncoding)base[ConfigurationStrings.MessageEncoding]; }
70             set { base[ConfigurationStrings.MessageEncoding] = value; }
71         }
72 
73         [ConfigurationProperty(ConfigurationStrings.ProxyAddress, DefaultValue = HttpTransportDefaults.ProxyAddress)]
74         public Uri ProxyAddress
75         {
76             get { return (Uri)base[ConfigurationStrings.ProxyAddress]; }
77             set { base[ConfigurationStrings.ProxyAddress] = value; }
78         }
79 
80         [ConfigurationProperty(ConfigurationStrings.ReaderQuotas)]
81         public XmlDictionaryReaderQuotasElement ReaderQuotas
82         {
83             get { return (XmlDictionaryReaderQuotasElement)base[ConfigurationStrings.ReaderQuotas]; }
84         }
85 
86         [ConfigurationProperty(ConfigurationStrings.ReliableSession)]
87         public StandardBindingOptionalReliableSessionElement ReliableSession
88         {
89             get { return (StandardBindingOptionalReliableSessionElement)base[ConfigurationStrings.ReliableSession]; }
90         }
91 
92         [ConfigurationProperty(ConfigurationStrings.TextEncoding, DefaultValue = TextEncoderDefaults.EncodingString)]
93         [TypeConverter(typeof(EncodingConverter))]
94         public Encoding TextEncoding
95         {
96             get { return (Encoding)base[ConfigurationStrings.TextEncoding]; }
97             set { base[ConfigurationStrings.TextEncoding] = value; }
98         }
99 
100         [ConfigurationProperty(ConfigurationStrings.UseDefaultWebProxy, DefaultValue = HttpTransportDefaults.UseDefaultWebProxy)]
101         public bool UseDefaultWebProxy
102         {
103             get { return (bool)base[ConfigurationStrings.UseDefaultWebProxy]; }
104             set { base[ConfigurationStrings.UseDefaultWebProxy] = value; }
105         }
106 
InitializeFrom(Binding binding)107         protected internal override void InitializeFrom(Binding binding)
108         {
109             base.InitializeFrom(binding);
110             WSHttpBindingBase wspBinding = (WSHttpBindingBase)binding;
111 
112             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.BypassProxyOnLocal, wspBinding.BypassProxyOnLocal);
113             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.TransactionFlow, wspBinding.TransactionFlow);
114             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.HostNameComparisonMode, wspBinding.HostNameComparisonMode);
115             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxBufferPoolSize, wspBinding.MaxBufferPoolSize);
116             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxReceivedMessageSize, wspBinding.MaxReceivedMessageSize);
117             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MessageEncoding, wspBinding.MessageEncoding);
118             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ProxyAddress, wspBinding.ProxyAddress);
119             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.TextEncoding, wspBinding.TextEncoding);
120             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.UseDefaultWebProxy, wspBinding.UseDefaultWebProxy);
121             this.ReaderQuotas.InitializeFrom(wspBinding.ReaderQuotas);
122             this.ReliableSession.InitializeFrom(wspBinding.ReliableSession);
123         }
124 
OnApplyConfiguration(Binding binding)125         protected override void OnApplyConfiguration(Binding binding)
126         {
127             WSHttpBindingBase wspBinding = (WSHttpBindingBase)binding;
128 
129             wspBinding.BypassProxyOnLocal = this.BypassProxyOnLocal;
130             wspBinding.TransactionFlow = this.TransactionFlow;
131             wspBinding.HostNameComparisonMode = this.HostNameComparisonMode;
132             wspBinding.MaxBufferPoolSize = this.MaxBufferPoolSize;
133             wspBinding.MaxReceivedMessageSize = this.MaxReceivedMessageSize;
134             wspBinding.MessageEncoding = this.MessageEncoding;
135             if (this.ProxyAddress != null)
136                 wspBinding.ProxyAddress = this.ProxyAddress;
137             wspBinding.TextEncoding = this.TextEncoding;
138             wspBinding.UseDefaultWebProxy = this.UseDefaultWebProxy;
139             this.ReaderQuotas.ApplyConfiguration(wspBinding.ReaderQuotas);
140             this.ReliableSession.ApplyConfiguration(wspBinding.ReliableSession);
141         }
142     }
143 
144 }
145