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 using WS = System.Web.Services.Description;
38 namespace System.ServiceModel.Channels
41 public abstract class ConnectionOrientedTransportBindingElement
42 : TransportBindingElement, IPolicyExportExtension, IWsdlExportExtension
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;
51 internal ConnectionOrientedTransportBindingElement ()
55 internal ConnectionOrientedTransportBindingElement (
56 ConnectionOrientedTransportBindingElement other)
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;
68 public TimeSpan ChannelInitializationTimeout {
69 get { return ch_init_timeout; }
70 set { ch_init_timeout = value; }
73 public int ConnectionBufferSize {
74 get { return connection_buf_size; }
75 set { connection_buf_size = value; }
78 public HostNameComparisonMode HostNameComparisonMode {
79 get { return host_cmp_mode; }
80 set { host_cmp_mode = value; }
83 public int MaxBufferSize {
84 get { return max_buf_size; }
85 set { max_buf_size = value; }
88 public int MaxPendingConnections {
89 get { return max_pending_conn; }
90 set { max_pending_conn = value; }
93 public TimeSpan MaxOutputDelay {
94 get { return max_output_delay; }
95 set { max_output_delay = value; }
98 public int MaxPendingAccepts {
99 get { return max_pending_accepts; }
100 set { max_pending_accepts = value; }
103 public TransferMode TransferMode {
104 get { return transfer_mode; }
105 set { transfer_mode = value; }
108 public override bool CanBuildChannelFactory<TChannel> (
109 BindingContext context)
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);
122 public override bool CanBuildChannelListener<TChannel> (
123 BindingContext context)
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);
136 public override T GetProperty<T> (BindingContext context)
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);
144 void IWsdlExportExtension.ExportContract (WsdlExporter exporter,
145 WsdlContractConversionContext context)
150 void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter,
151 WsdlEndpointConversionContext context)
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);
158 var address = context.Endpoint.Address;
159 var uri = address.Uri.AbsoluteUri;
161 var soap_address = new WS.Soap12AddressBinding ();
162 soap_address.Location = uri;
163 context.WsdlPort.Extensions.Add (soap_address);
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);
175 void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter, PolicyConversionContext context)
177 if (exporter == null)
178 throw new ArgumentNullException ("exporter");
180 throw new ArgumentNullException ("context");
182 PolicyAssertionCollection assertions = context.GetBindingAssertions ();
183 XmlDocument doc = new XmlDocument ();
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"));
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"));