New tests.
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel / WSHttpBindingBase.cs
1 //
2 // WSHttpBindingBase.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005-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.Generic;
30 using System.Net.Security;
31 using System.ServiceModel.Channels;
32 using System.ServiceModel.Configuration;
33 using System.ServiceModel.Description;
34 using System.Text;
35 using System.Xml;
36
37 namespace System.ServiceModel
38 {
39         [MonoTODO]
40         public abstract class WSHttpBindingBase : Binding, 
41                 IBindingRuntimePreferences
42         {
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;
52                 Uri proxy_address;
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;
61
62                 ReliableSessionBindingElement rel_element =
63                         new ReliableSessionBindingElement ();
64
65                 protected WSHttpBindingBase ()
66                         : this (false)
67                 {
68                 }
69
70                 protected WSHttpBindingBase (bool reliableSessionEnabled)
71                 {
72                         reliable_session = new OptionalReliableSession (rel_element);
73                         reliable_session.Enabled = reliableSessionEnabled;
74                 }
75
76                 internal WSHttpBindingBase (WSHttpBindingBaseElement config)
77                         : this (config.ReliableSession.Enabled)
78                 {
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;
86
87                         TextEncoding = config.TextEncoding;
88                         TransactionFlow = config.TransactionFlow;
89                         UseDefaultWebProxy = config.UseDefaultWebProxy;
90                         throw new NotImplementedException ();
91                 }
92
93                 public bool BypassProxyOnLocal {
94                         get { return bypass_proxy_on_local; }
95                         set { bypass_proxy_on_local = value; }
96                 }
97
98                 public HostNameComparisonMode HostNameComparisonMode {
99                         get { return host_name_comparison_mode; }
100                         set { host_name_comparison_mode = value; }
101                 }
102
103                 public long MaxBufferPoolSize {
104                         get { return max_buffer_pool_size; }
105                         set { max_buffer_pool_size = value; }
106                 }
107
108                 public long MaxReceivedMessageSize {
109                         get { return max_recv_msg_size; }
110                         set { max_recv_msg_size = value; }
111                 }
112
113                 public WSMessageEncoding MessageEncoding {
114                         get { return message_encoding; }
115                         set { message_encoding = value; }
116                 }
117
118                 public Uri ProxyAddress {
119                         get { return proxy_address; }
120                         set { proxy_address = value; }
121                 }
122
123                 public XmlDictionaryReaderQuotas ReaderQuotas {
124                         get { return reader_quotas; }
125                         set { reader_quotas = value; }
126                 }
127
128                 public override string Scheme {
129                         get { return GetTransport ().Scheme; }
130                 }
131
132                 public OptionalReliableSession ReliableSession {
133                         get { return reliable_session; }
134                 }
135
136                 public EnvelopeVersion EnvelopeVersion {
137                         get { return env_version; }
138                 }
139
140                 public Encoding TextEncoding {
141                         get { return text_encoding; }
142                         set { text_encoding = value; }
143                 }
144
145                 public bool TransactionFlow {
146                         get { return transaction_flow; }
147                         set { transaction_flow = value; }
148                 }
149
150                 public bool UseDefaultWebProxy {
151                         get { return use_default_web_proxy; }
152                         set { use_default_web_proxy = value; }
153                 }
154
155                 [MonoTODO]
156                 public override BindingElementCollection
157                         CreateBindingElements ()
158                 {
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);
166                                 break;
167                         case WSMessageEncoding.Text:
168                                 msg = new TextMessageEncodingBindingElement (msgver, TextEncoding);
169                                 break;
170                         default:
171                                 throw new NotImplementedException ("mhm, another WSMessageEncoding?");
172                         }
173                         BindingElement tr = GetTransport ();
174                         List<BindingElement> list = new List<BindingElement> ();
175                         list.Add (tx); // it is always added.
176                         if (sec != null)
177                                 list.Add (sec);
178                         list.Add (msg);
179                         if (tr != null)
180                                 list.Add (tr);
181                         // FIXME: add ReliableSessionBindingElement
182                         return new BindingElementCollection (list.ToArray ());
183                 }
184
185                 protected abstract SecurityBindingElement CreateMessageSecurity ();
186
187                 protected abstract TransportBindingElement GetTransport ();
188
189                 // explicit interface implementations
190
191                 bool IBindingRuntimePreferences.ReceiveSynchronously {
192                         get { return false; }
193                 }
194         }
195 }