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;
30 using System.Net.Security;
31 using System.ServiceModel.Channels;
32 using System.ServiceModel.Description;
33 using System.ServiceModel.Security.Tokens;
37 namespace System.ServiceModel
40 public class NetTcpBinding : Binding, IBindingRuntimePreferences
42 HostNameComparisonMode comparison_mode;
47 OptionalReliableSession reliable_session;
48 NetTcpSecurity security;
49 XmlDictionaryReaderQuotas reader_quotas;
50 EnvelopeVersion soap_version;
51 bool transaction_flow;
52 TransactionProtocol transaction_protocol;
53 TransferMode transfer_mode;
54 TcpTransportBindingElement transport = new TcpTransportBindingElement ();
56 public NetTcpBinding ()
57 : this (SecurityMode.Message)
61 public NetTcpBinding (SecurityMode securityMode)
62 : this (securityMode, false)
66 public NetTcpBinding (SecurityMode securityMode,
67 bool reliableSessionEnabled)
69 security = new NetTcpSecurity (securityMode);
72 public HostNameComparisonMode HostNameComparisonMode {
73 get { return comparison_mode; }
74 set { comparison_mode = value; }
77 public int ListenBacklog {
78 get { return transport.ListenBacklog; }
79 set { transport.ListenBacklog = value; }
82 public long MaxBufferPoolSize {
83 get { return max_pool_size; }
84 set { max_pool_size = value; }
87 public int MaxBufferSize {
88 get { return max_buf_size; }
89 set { max_buf_size = value; }
92 public int MaxConnections {
93 get { return max_conn; }
94 set { max_conn = value; }
97 public long MaxReceivedMessageSize {
98 get { return max_msg_size; }
99 set { max_msg_size = value; }
102 public bool PortSharingEnabled {
103 get { return transport.PortSharingEnabled; }
104 set { transport.PortSharingEnabled = value; }
107 public OptionalReliableSession ReliableSession {
108 get { return reliable_session; }
111 public XmlDictionaryReaderQuotas ReaderQuotas {
112 get { return reader_quotas; }
113 set { reader_quotas = value; }
116 public NetTcpSecurity Security {
117 get { return security; }
120 public EnvelopeVersion EnvelopeVersion {
121 get { return soap_version; }
124 public TransferMode TransferMode {
125 get { return transfer_mode; }
126 set { transfer_mode = value; }
129 public bool TransactionFlow {
130 get { return transaction_flow; }
131 set { transaction_flow = value; }
134 public TransactionProtocol TransactionProtocol {
135 get { return transaction_protocol; }
136 set { transaction_protocol = value; }
141 public override string Scheme {
142 get { return "net.tcp"; }
145 public override BindingElementCollection CreateBindingElements ()
147 BindingElement tx = new TransactionFlowBindingElement (TransactionProtocol.WSAtomicTransactionOctober2004);
148 SecurityBindingElement sec = CreateMessageSecurity ();
149 BindingElement msg = new BinaryMessageEncodingBindingElement ();
150 BindingElement tr = GetTransport ();
151 List<BindingElement> list = new List<BindingElement> ();
158 return new BindingElementCollection (list.ToArray ());
161 BindingElement GetTransport ()
163 return transport.Clone ();
166 // based on WSHttpBinding.CreateMessageSecurity()
167 SecurityBindingElement CreateMessageSecurity ()
169 if (Security.Mode == SecurityMode.Transport ||
170 Security.Mode == SecurityMode.None)
173 SymmetricSecurityBindingElement element =
174 new SymmetricSecurityBindingElement ();
176 element.MessageSecurityVersion = MessageSecurityVersion.Default;
178 element.SetKeyDerivation (false);
180 switch (Security.Message.ClientCredentialType) {
181 case MessageCredentialType.Certificate:
182 element.EndpointSupportingTokenParameters.Endorsing.Add (
183 new X509SecurityTokenParameters ());
185 case MessageCredentialType.IssuedToken:
186 IssuedSecurityTokenParameters istp =
187 new IssuedSecurityTokenParameters ();
188 // FIXME: issuer binding must be secure.
189 istp.IssuerBinding = new CustomBinding (
190 new TextMessageEncodingBindingElement (),
192 element.EndpointSupportingTokenParameters.Endorsing.Add (istp);
194 case MessageCredentialType.UserName:
195 element.EndpointSupportingTokenParameters.SignedEncrypted.Add (
196 new UserNameSecurityTokenParameters ());
198 case MessageCredentialType.Windows:
199 element.ProtectionTokenParameters =
200 new KerberosSecurityTokenParameters ();
202 default: // including .None
203 X509SecurityTokenParameters p =
204 new X509SecurityTokenParameters ();
205 p.X509ReferenceStyle = X509KeyIdentifierClauseType.Thumbprint;
206 element.ProtectionTokenParameters = p;
213 bool IBindingRuntimePreferences.ReceiveSynchronously {
214 get { throw new NotImplementedException (); }