do not check order sequence if option /order was not used
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / ConnectionOrientedTransportBindingElement.cs
1 //
2 // ConnectionOrientedTransportBindingElement.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005 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;
31 using System.ServiceModel.Channels;
32 using System.ServiceModel.Description;
33 using System.Xml;
34
35 namespace System.ServiceModel.Channels
36 {
37         [MonoTODO]
38         public abstract class ConnectionOrientedTransportBindingElement
39                 : TransportBindingElement, IPolicyExportExtension
40         {
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;
47
48                 internal ConnectionOrientedTransportBindingElement ()
49                 {
50                 }
51
52                 internal ConnectionOrientedTransportBindingElement (
53                         ConnectionOrientedTransportBindingElement other)
54                         : base (other)
55                 {
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;
63                 }
64
65                 public TimeSpan ChannelInitializationTimeout {
66                         get { return ch_init_timeout; }
67                         set { ch_init_timeout = value; }
68                 }
69
70                 public int ConnectionBufferSize {
71                         get { return connection_buf_size; }
72                         set { connection_buf_size = value; }
73                 }
74
75                 public HostNameComparisonMode HostNameComparisonMode {
76                         get { return host_cmp_mode; }
77                         set { host_cmp_mode = value; }
78                 }
79
80                 public int MaxBufferSize {
81                         get { return max_buf_size; }
82                         set { max_buf_size = value; }
83                 }
84
85                 public int MaxPendingConnections {
86                         get { return max_pending_conn; }
87                         set { max_pending_conn = value; }
88                 }
89
90                 public TimeSpan MaxOutputDelay {
91                         get { return max_output_delay; }
92                         set { max_output_delay = value; }
93                 }
94
95                 public int MaxPendingAccepts {
96                         get { return max_pending_accepts; }
97                         set { max_pending_accepts = value; }
98                 }
99
100                 public TransferMode TransferMode {
101                         get { return transfer_mode; }
102                         set { transfer_mode = value; }
103                 }
104                 
105                 public override bool CanBuildChannelFactory<TChannel> (
106                         BindingContext context)
107                 {
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);
115                         }
116                         return false;
117                 }
118
119                 public override bool CanBuildChannelListener<TChannel> (
120                         BindingContext context)
121                 {
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);
129                         }
130                         return false;
131                 }
132
133                 public override T GetProperty<T> (BindingContext context)
134                 {
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);
139                 }
140
141                 void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter, PolicyConversionContext context)
142                 {
143                         if (exporter == null)
144                                 throw new ArgumentNullException ("exporter");
145                         if (context == null)
146                                 throw new ArgumentNullException ("context");
147
148                         PolicyAssertionCollection assertions = context.GetBindingAssertions ();
149                         XmlDocument doc = new XmlDocument ();
150
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"));
153
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"));
157                 }
158         }
159 }