2 // ConnectionOrientedTransportBindingElement.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
6 // Martin Baulig <martin.baulig@xamarin.com>
8 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
9 // Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
31 using System.Collections.Generic;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Description;
36 #if !MOBILE && !XAMMAC_4_5
37 using WS = System.Web.Services.Description;
40 namespace System.ServiceModel.Channels
43 public abstract class ConnectionOrientedTransportBindingElement
44 : TransportBindingElement, IPolicyExportExtension, IWsdlExportExtension
46 int connection_buf_size = 0x2000, max_buf_size = 0x10000,
47 max_pending_conn = 10, max_pending_accepts = 1;
48 HostNameComparisonMode host_cmp_mode = HostNameComparisonMode.StrongWildcard;
49 TimeSpan max_output_delay = TimeSpan.FromMilliseconds (200);
50 TimeSpan ch_init_timeout = TimeSpan.FromSeconds (5);
51 TransferMode transfer_mode = TransferMode.Buffered;
53 internal ConnectionOrientedTransportBindingElement ()
57 internal ConnectionOrientedTransportBindingElement (
58 ConnectionOrientedTransportBindingElement other)
61 connection_buf_size = other.connection_buf_size;
62 max_buf_size = other.max_buf_size;
63 max_pending_conn = other.max_pending_conn;
64 max_pending_accepts = other.max_pending_accepts;
65 host_cmp_mode = other.host_cmp_mode;
66 max_output_delay = other.max_output_delay;
67 transfer_mode = other.transfer_mode;
70 public TimeSpan ChannelInitializationTimeout {
71 get { return ch_init_timeout; }
72 set { ch_init_timeout = value; }
75 public int ConnectionBufferSize {
76 get { return connection_buf_size; }
77 set { connection_buf_size = value; }
80 public HostNameComparisonMode HostNameComparisonMode {
81 get { return host_cmp_mode; }
82 set { host_cmp_mode = value; }
85 public int MaxBufferSize {
86 get { return max_buf_size; }
87 set { max_buf_size = value; }
90 public int MaxPendingConnections {
91 get { return max_pending_conn; }
92 set { max_pending_conn = value; }
95 public TimeSpan MaxOutputDelay {
96 get { return max_output_delay; }
97 set { max_output_delay = value; }
100 public int MaxPendingAccepts {
101 get { return max_pending_accepts; }
102 set { max_pending_accepts = value; }
105 public TransferMode TransferMode {
106 get { return transfer_mode; }
107 set { transfer_mode = value; }
110 public override bool CanBuildChannelFactory<TChannel> (
111 BindingContext context)
113 switch (TransferMode) {
114 case TransferMode.Buffered:
115 case TransferMode.StreamedResponse:
116 return typeof (TChannel) == typeof (IDuplexSessionChannel);
117 case TransferMode.Streamed:
118 case TransferMode.StreamedRequest:
119 return typeof (TChannel) == typeof (IRequestChannel);
124 #if !MOBILE && !XAMMAC_4_5
125 public override bool CanBuildChannelListener<TChannel> (
126 BindingContext context)
128 switch (TransferMode) {
129 case TransferMode.Buffered:
130 case TransferMode.StreamedRequest:
131 return typeof (TChannel) == typeof (IDuplexSessionChannel);
132 case TransferMode.Streamed:
133 case TransferMode.StreamedResponse:
134 return typeof (TChannel) == typeof (IReplyChannel);
140 public override T GetProperty<T> (BindingContext context)
142 // since this class cannot be derived (internal .ctor
143 // only), we cannot examine what this should do.
144 // So, handle all properties in the derived types.
145 return base.GetProperty<T> (context);
148 #if !MOBILE && !XAMMAC_4_5
149 void IWsdlExportExtension.ExportContract (WsdlExporter exporter,
150 WsdlContractConversionContext context)
155 void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter,
156 WsdlEndpointConversionContext context)
158 var soap_binding = new WS.Soap12Binding ();
159 soap_binding.Transport = "http://schemas.microsoft.com/soap/tcp";
160 soap_binding.Style = WS.SoapBindingStyle.Document;
161 context.WsdlBinding.Extensions.Add (soap_binding);
163 var address = context.Endpoint.Address;
164 var uri = address.Uri.AbsoluteUri;
166 var soap_address = new WS.Soap12AddressBinding ();
167 soap_address.Location = uri;
168 context.WsdlPort.Extensions.Add (soap_address);
170 var doc = new XmlDocument ();
171 var endpoint_ref = doc.CreateElement (
172 "EndpointReference", AddressingVersion.WSAddressing10.Namespace);
173 var endpoint_addr = doc.CreateElement (
174 "Address", AddressingVersion.WSAddressing10.Namespace);
175 endpoint_addr.InnerText = uri;
176 endpoint_ref.AppendChild (endpoint_addr);
177 context.WsdlPort.Extensions.Add (endpoint_ref);
180 void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter, PolicyConversionContext context)
182 if (exporter == null)
183 throw new ArgumentNullException ("exporter");
185 throw new ArgumentNullException ("context");
187 PolicyAssertionCollection assertions = context.GetBindingAssertions ();
188 XmlDocument doc = new XmlDocument ();
190 var messageEncodingElement = ExportAddressingPolicy (context);
191 if (messageEncodingElement == null)
192 assertions.Add (doc.CreateElement (
193 "msb", "BinaryEncoding",
194 "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
196 if (transfer_mode == TransferMode.Streamed || transfer_mode == TransferMode.StreamedRequest ||
197 transfer_mode == TransferMode.StreamedResponse)
198 assertions.Add (doc.CreateElement ("msf", "Streamed", "http://schemas.microsoft.com/ws/2006/05/framing/policy"));