2 // ConnectionOrientedTransportBindingElement.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005 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;
31 using System.ServiceModel.Channels;
32 using System.ServiceModel.Description;
35 namespace System.ServiceModel.Channels
38 public abstract class ConnectionOrientedTransportBindingElement
39 : TransportBindingElement, IPolicyExportExtension
41 int connection_buf_size = 0x2000, max_buf_size = 0x10000,
42 max_pending_conn = 10, max_pending_accepts = 1;
43 HostNameComparisonMode host_cmp_mode = HostNameComparisonMode.StrongWildcard;
44 TimeSpan max_output_delay = TimeSpan.FromMilliseconds (200);
45 TimeSpan ch_init_timeout = TimeSpan.FromSeconds (5);
46 TransferMode transfer_mode = TransferMode.Buffered;
48 internal ConnectionOrientedTransportBindingElement ()
52 internal ConnectionOrientedTransportBindingElement (
53 ConnectionOrientedTransportBindingElement other)
56 connection_buf_size = other.connection_buf_size;
57 max_buf_size = other.max_buf_size;
58 max_pending_conn = other.max_pending_conn;
59 max_pending_accepts = other.max_pending_accepts;
60 host_cmp_mode = other.host_cmp_mode;
61 max_output_delay = other.max_output_delay;
62 transfer_mode = other.transfer_mode;
65 public TimeSpan ChannelInitializationTimeout {
66 get { return ch_init_timeout; }
67 set { ch_init_timeout = value; }
70 public int ConnectionBufferSize {
71 get { return connection_buf_size; }
72 set { connection_buf_size = value; }
75 public HostNameComparisonMode HostNameComparisonMode {
76 get { return host_cmp_mode; }
77 set { host_cmp_mode = value; }
80 public int MaxBufferSize {
81 get { return max_buf_size; }
82 set { max_buf_size = value; }
85 public int MaxPendingConnections {
86 get { return max_pending_conn; }
87 set { max_pending_conn = value; }
90 public TimeSpan MaxOutputDelay {
91 get { return max_output_delay; }
92 set { max_output_delay = value; }
95 public int MaxPendingAccepts {
96 get { return max_pending_accepts; }
97 set { max_pending_accepts = value; }
100 public TransferMode TransferMode {
101 get { return transfer_mode; }
102 set { transfer_mode = value; }
105 public override bool CanBuildChannelFactory<TChannel> (
106 BindingContext context)
108 switch (TransferMode) {
109 case TransferMode.Buffered:
110 case TransferMode.StreamedResponse:
111 return typeof (TChannel) == typeof (IDuplexSessionChannel);
112 case TransferMode.Streamed:
113 case TransferMode.StreamedRequest:
114 return typeof (TChannel) == typeof (IRequestChannel);
119 public override bool CanBuildChannelListener<TChannel> (
120 BindingContext context)
122 switch (TransferMode) {
123 case TransferMode.Buffered:
124 case TransferMode.StreamedRequest:
125 return typeof (TChannel) == typeof (IDuplexSessionChannel);
126 case TransferMode.Streamed:
127 case TransferMode.StreamedResponse:
128 return typeof (TChannel) == typeof (IReplyChannel);
133 public override T GetProperty<T> (BindingContext context)
135 // since this class cannot be derived (internal .ctor
136 // only), we cannot examine what this should do.
137 // So, handle all properties in the derived types.
138 return base.GetProperty<T> (context);
141 void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter, PolicyConversionContext context)
143 if (exporter == null)
144 throw new ArgumentNullException ("exporter");
146 throw new ArgumentNullException ("context");
148 PolicyAssertionCollection assertions = context.GetBindingAssertions ();
149 XmlDocument doc = new XmlDocument ();
151 assertions.Add (doc.CreateElement ("wsaw", "UsingAddressing", "http://www.w3.org/2006/05/addressing/wsdl"));
152 assertions.Add (doc.CreateElement ("msb", "BinaryEncoding", "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
154 if (transfer_mode == TransferMode.Streamed || transfer_mode == TransferMode.StreamedRequest ||
155 transfer_mode == TransferMode.StreamedResponse)
156 assertions.Add (doc.CreateElement ("msf", "Streamed", "http://schemas.microsoft.com/ws/2006/05/framing/policy"));