2 // WSHttpBindingBase.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using System.Collections.Generic;
30 using System.Net.Security;
31 using System.ServiceModel.Channels;
32 using System.ServiceModel.Configuration;
33 using System.ServiceModel.Description;
37 namespace System.ServiceModel
40 public abstract class WSHttpBindingBase : Binding,
41 IBindingRuntimePreferences
43 bool bypass_proxy_on_local, reliable_session_enabled;
44 HostNameComparisonMode host_name_comparison_mode
45 = HostNameComparisonMode.StrongWildcard;
46 // FIXME: could be configurable
47 long max_buffer_pool_size = 0x80000;
48 // FIXME: could be configurable
49 long max_recv_msg_size = 0x10000;
50 WSMessageEncoding message_encoding
51 = WSMessageEncoding.Text;
53 XmlDictionaryReaderQuotas reader_quotas
54 = new XmlDictionaryReaderQuotas ();
55 OptionalReliableSession reliable_session;
56 // FIXME: could be configurable.
57 EnvelopeVersion env_version = EnvelopeVersion.Soap12;
58 Encoding text_encoding = new UTF8Encoding ();
59 bool transaction_flow;
60 bool use_default_web_proxy = true;
62 ReliableSessionBindingElement rel_element =
63 new ReliableSessionBindingElement ();
65 protected WSHttpBindingBase ()
70 protected WSHttpBindingBase (bool reliableSessionEnabled)
72 reliable_session = new OptionalReliableSession (rel_element);
73 reliable_session.Enabled = reliableSessionEnabled;
76 internal WSHttpBindingBase (WSHttpBindingBaseElement config)
77 : this (config.ReliableSession.Enabled)
79 BypassProxyOnLocal = config.BypassProxyOnLocal;
80 HostNameComparisonMode = config.HostNameComparisonMode;
81 MaxBufferPoolSize = config.MaxBufferPoolSize;
82 MaxReceivedMessageSize = config.MaxReceivedMessageSize;
83 MessageEncoding = config.MessageEncoding;
84 ProxyAddress = config.ProxyAddress;
85 // ReaderQuotas = config.ReaderQuotas;
87 TextEncoding = config.TextEncoding;
88 TransactionFlow = config.TransactionFlow;
89 UseDefaultWebProxy = config.UseDefaultWebProxy;
90 throw new NotImplementedException ();
93 public bool BypassProxyOnLocal {
94 get { return bypass_proxy_on_local; }
95 set { bypass_proxy_on_local = value; }
98 public HostNameComparisonMode HostNameComparisonMode {
99 get { return host_name_comparison_mode; }
100 set { host_name_comparison_mode = value; }
103 public long MaxBufferPoolSize {
104 get { return max_buffer_pool_size; }
105 set { max_buffer_pool_size = value; }
108 public long MaxReceivedMessageSize {
109 get { return max_recv_msg_size; }
110 set { max_recv_msg_size = value; }
113 public WSMessageEncoding MessageEncoding {
114 get { return message_encoding; }
115 set { message_encoding = value; }
118 public Uri ProxyAddress {
119 get { return proxy_address; }
120 set { proxy_address = value; }
123 public XmlDictionaryReaderQuotas ReaderQuotas {
124 get { return reader_quotas; }
125 set { reader_quotas = value; }
128 public override string Scheme {
129 get { return GetTransport ().Scheme; }
132 public OptionalReliableSession ReliableSession {
133 get { return reliable_session; }
136 public EnvelopeVersion EnvelopeVersion {
137 get { return env_version; }
140 public Encoding TextEncoding {
141 get { return text_encoding; }
142 set { text_encoding = value; }
145 public bool TransactionFlow {
146 get { return transaction_flow; }
147 set { transaction_flow = value; }
150 public bool UseDefaultWebProxy {
151 get { return use_default_web_proxy; }
152 set { use_default_web_proxy = value; }
156 public override BindingElementCollection
157 CreateBindingElements ()
159 BindingElement tx = new TransactionFlowBindingElement (TransactionProtocol.WSAtomicTransactionOctober2004);
160 SecurityBindingElement sec = CreateMessageSecurity ();
161 BindingElement msg = null;
162 MessageVersion msgver = MessageVersion.CreateVersion (EnvelopeVersion, AddressingVersion.WSAddressing10);
163 switch (MessageEncoding) {
164 case WSMessageEncoding.Mtom:
165 msg = new MtomMessageEncodingBindingElement (msgver, TextEncoding);
167 case WSMessageEncoding.Text:
168 msg = new TextMessageEncodingBindingElement (msgver, TextEncoding);
171 throw new NotImplementedException ("mhm, another WSMessageEncoding?");
173 BindingElement tr = GetTransport ();
174 List<BindingElement> list = new List<BindingElement> ();
175 list.Add (tx); // it is always added.
181 // FIXME: add ReliableSessionBindingElement
182 return new BindingElementCollection (list.ToArray ());
185 protected abstract SecurityBindingElement CreateMessageSecurity ();
187 protected abstract TransportBindingElement GetTransport ();
189 // explicit interface implementations
191 bool IBindingRuntimePreferences.ReceiveSynchronously {
192 get { return false; }