[runtime] Free rgctx_lazy_fetch_trampoline info
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / ConnectionOrientedTransportBindingElement.cs
1 //
2 // ConnectionOrientedTransportBindingElement.cs
3 //
4 // Authors:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //      Martin Baulig <martin.baulig@xamarin.com>
7 //
8 // Copyright (C) 2005 Novell, Inc.  http://www.novell.com
9 // Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 using System;
31 using System.Collections.Generic;
32 using System.Net;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Description;
35 using System.Xml;
36 using WS = System.Web.Services.Description;
37
38 namespace System.ServiceModel.Channels
39 {
40         [MonoTODO]
41         public abstract class ConnectionOrientedTransportBindingElement
42                 : TransportBindingElement, IPolicyExportExtension, IWsdlExportExtension
43         {
44                 int connection_buf_size = 0x2000, max_buf_size = 0x10000,
45                         max_pending_conn = 10, max_pending_accepts = 1;
46                 HostNameComparisonMode host_cmp_mode = HostNameComparisonMode.StrongWildcard;
47                 TimeSpan max_output_delay = TimeSpan.FromMilliseconds (200);
48                 TimeSpan ch_init_timeout = TimeSpan.FromSeconds (5);
49                 TransferMode transfer_mode = TransferMode.Buffered;
50
51                 internal ConnectionOrientedTransportBindingElement ()
52                 {
53                 }
54
55                 internal ConnectionOrientedTransportBindingElement (
56                         ConnectionOrientedTransportBindingElement other)
57                         : base (other)
58                 {
59                         connection_buf_size = other.connection_buf_size;
60                         max_buf_size = other.max_buf_size;
61                         max_pending_conn = other.max_pending_conn;
62                         max_pending_accepts = other.max_pending_accepts;
63                         host_cmp_mode = other.host_cmp_mode;
64                         max_output_delay = other.max_output_delay;
65                         transfer_mode = other.transfer_mode;
66                 }
67
68                 public TimeSpan ChannelInitializationTimeout {
69                         get { return ch_init_timeout; }
70                         set { ch_init_timeout = value; }
71                 }
72
73                 public int ConnectionBufferSize {
74                         get { return connection_buf_size; }
75                         set { connection_buf_size = value; }
76                 }
77
78                 public HostNameComparisonMode HostNameComparisonMode {
79                         get { return host_cmp_mode; }
80                         set { host_cmp_mode = value; }
81                 }
82
83                 public int MaxBufferSize {
84                         get { return max_buf_size; }
85                         set { max_buf_size = value; }
86                 }
87
88                 public int MaxPendingConnections {
89                         get { return max_pending_conn; }
90                         set { max_pending_conn = value; }
91                 }
92
93                 public TimeSpan MaxOutputDelay {
94                         get { return max_output_delay; }
95                         set { max_output_delay = value; }
96                 }
97
98                 public int MaxPendingAccepts {
99                         get { return max_pending_accepts; }
100                         set { max_pending_accepts = value; }
101                 }
102
103                 public TransferMode TransferMode {
104                         get { return transfer_mode; }
105                         set { transfer_mode = value; }
106                 }
107                 
108                 public override bool CanBuildChannelFactory<TChannel> (
109                         BindingContext context)
110                 {
111                         switch (TransferMode) {
112                         case TransferMode.Buffered:
113                         case TransferMode.StreamedResponse:
114                                 return typeof (TChannel) == typeof (IDuplexSessionChannel);
115                         case TransferMode.Streamed:
116                         case TransferMode.StreamedRequest:
117                                 return typeof (TChannel) == typeof (IRequestChannel);
118                         }
119                         return false;
120                 }
121
122                 public override bool CanBuildChannelListener<TChannel> (
123                         BindingContext context)
124                 {
125                         switch (TransferMode) {
126                         case TransferMode.Buffered:
127                         case TransferMode.StreamedRequest:
128                                 return typeof (TChannel) == typeof (IDuplexSessionChannel);
129                         case TransferMode.Streamed:
130                         case TransferMode.StreamedResponse:
131                                 return typeof (TChannel) == typeof (IReplyChannel);
132                         }
133                         return false;
134                 }
135
136                 public override T GetProperty<T> (BindingContext context)
137                 {
138                         // since this class cannot be derived (internal .ctor
139                         // only), we cannot examine what this should do.
140                         // So, handle all properties in the derived types.
141                         return base.GetProperty<T> (context);
142                 }
143
144                 void IWsdlExportExtension.ExportContract (WsdlExporter exporter,
145                                                           WsdlContractConversionContext context)
146                 {
147                         ;
148                 }
149                 
150                 void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter,
151                                                           WsdlEndpointConversionContext context)
152                 {
153                         var soap_binding = new WS.Soap12Binding ();
154                         soap_binding.Transport = "http://schemas.microsoft.com/soap/tcp";
155                         soap_binding.Style = WS.SoapBindingStyle.Document;
156                         context.WsdlBinding.Extensions.Add (soap_binding);
157
158                         var address = context.Endpoint.Address;
159                         var uri = address.Uri.AbsoluteUri;
160
161                         var soap_address = new WS.Soap12AddressBinding ();
162                         soap_address.Location = uri;
163                         context.WsdlPort.Extensions.Add (soap_address);
164
165                         var doc = new XmlDocument ();
166                         var endpoint_ref = doc.CreateElement (
167                                 "EndpointReference", AddressingVersion.WSAddressing10.Namespace);
168                         var endpoint_addr = doc.CreateElement (
169                                 "Address", AddressingVersion.WSAddressing10.Namespace);
170                         endpoint_addr.InnerText = uri;
171                         endpoint_ref.AppendChild (endpoint_addr);
172                         context.WsdlPort.Extensions.Add (endpoint_ref);
173                 }
174
175                 void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter, PolicyConversionContext context)
176                 {
177                         if (exporter == null)
178                                 throw new ArgumentNullException ("exporter");
179                         if (context == null)
180                                 throw new ArgumentNullException ("context");
181
182                         PolicyAssertionCollection assertions = context.GetBindingAssertions ();
183                         XmlDocument doc = new XmlDocument ();
184
185                         var messageEncodingElement = ExportAddressingPolicy (context);
186                         if (messageEncodingElement == null)
187                                 assertions.Add (doc.CreateElement (
188                                         "msb", "BinaryEncoding",
189                                         "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
190
191                         if (transfer_mode == TransferMode.Streamed || transfer_mode == TransferMode.StreamedRequest ||
192                                 transfer_mode == TransferMode.StreamedResponse)
193                                 assertions.Add (doc.CreateElement ("msf", "Streamed", "http://schemas.microsoft.com/ws/2006/05/framing/policy"));
194                 }
195         }
196 }