2 // TcpTransportBindingElementTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2008 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
.ObjectModel
;
32 using System
.Net
.Security
;
33 using System
.ServiceModel
;
34 using System
.ServiceModel
.Channels
;
35 using System
.ServiceModel
.Description
;
36 using System
.Threading
;
38 using NUnit
.Framework
;
40 namespace MonoTests
.System
.ServiceModel
.Channels
43 public class TcpTransportBindingElementTest
45 static BindingParameterCollection empty_params
=
46 new BindingParameterCollection ();
49 public void DefaultValues ()
51 TcpTransportBindingElement be
=
52 new TcpTransportBindingElement ();
53 Assert
.AreEqual (TimeSpan
.FromSeconds (5), be
.ChannelInitializationTimeout
, "#1");
54 Assert
.AreEqual (0x2000, be
.ConnectionBufferSize
, "#2");
55 Assert
.AreEqual (HostNameComparisonMode
.StrongWildcard
, be
.HostNameComparisonMode
, "#3");
56 Assert
.AreEqual (0x10000, be
.MaxBufferSize
, "#4");
57 Assert
.AreEqual (TimeSpan
.FromMilliseconds (200), be
.MaxOutputDelay
, "#5");
58 Assert
.AreEqual (1, be
.MaxPendingAccepts
, "#6");
59 Assert
.AreEqual (10, be
.MaxPendingConnections
, "#7");
60 Assert
.AreEqual (TransferMode
.Buffered
, be
.TransferMode
, "#8");
62 Assert
.AreEqual (10, be
.ListenBacklog
, "#9");
63 Assert
.IsFalse (be
.PortSharingEnabled
, "#10");
64 Assert
.AreEqual ("net.tcp", be
.Scheme
, "#11");
65 Assert
.IsFalse (be
.TeredoEnabled
, "#12");
66 TcpConnectionPoolSettings pool
= be
.ConnectionPoolSettings
;
67 Assert
.IsNotNull (pool
, "#13");
68 Assert
.AreEqual ("default", pool
.GroupName
, "#14");
69 Assert
.AreEqual (TimeSpan
.FromSeconds (120), pool
.IdleTimeout
, "#15");
70 Assert
.AreEqual (TimeSpan
.FromSeconds (300), pool
.LeaseTimeout
, "#16");
71 Assert
.AreEqual (10, pool
.MaxOutboundConnectionsPerEndpoint
, "#17");
75 public void CanBuildChannelFactory ()
77 TcpTransportBindingElement be
=
78 new TcpTransportBindingElement ();
79 BindingContext ctx
= new BindingContext (
80 new CustomBinding (), empty_params
);
81 Assert
.IsFalse (be
.CanBuildChannelFactory
<IRequestChannel
> (ctx
), "#1");
82 Assert
.IsFalse (be
.CanBuildChannelFactory
<IInputChannel
> (ctx
), "#2");
83 Assert
.IsFalse (be
.CanBuildChannelFactory
<IReplyChannel
> (ctx
), "#3");
84 Assert
.IsFalse (be
.CanBuildChannelFactory
<IOutputChannel
> (ctx
), "#4");
86 Assert
.IsFalse (be
.CanBuildChannelFactory
<IRequestSessionChannel
> (ctx
), "#5");
87 Assert
.IsFalse (be
.CanBuildChannelFactory
<IInputSessionChannel
> (ctx
), "#6");
88 Assert
.IsFalse (be
.CanBuildChannelFactory
<IReplySessionChannel
> (ctx
), "#7");
89 Assert
.IsFalse (be
.CanBuildChannelFactory
<IOutputSessionChannel
> (ctx
), "#8");
91 // IServiceChannel is not supported
92 Assert
.IsFalse (be
.CanBuildChannelFactory
<IServiceChannel
> (ctx
), "#9");
93 Assert
.IsFalse (be
.CanBuildChannelFactory
<IClientChannel
> (ctx
), "#10");
95 Assert
.IsFalse (be
.CanBuildChannelFactory
<IDuplexChannel
> (ctx
), "#11");
96 Assert
.IsTrue (be
.CanBuildChannelFactory
<IDuplexSessionChannel
> (ctx
), "#12");
100 public void CanBuildChannelListener ()
102 TcpTransportBindingElement be
=
103 new TcpTransportBindingElement ();
104 BindingContext ctx
= new BindingContext (
105 new CustomBinding (), empty_params
);
106 Assert
.IsFalse (be
.CanBuildChannelListener
<IReplyChannel
> (ctx
), "#1");
107 Assert
.IsFalse (be
.CanBuildChannelListener
<IOutputChannel
> (ctx
), "#2");
108 Assert
.IsFalse (be
.CanBuildChannelListener
<IRequestChannel
> (ctx
), "#3");
109 Assert
.IsFalse (be
.CanBuildChannelListener
<IInputChannel
> (ctx
), "#4");
111 Assert
.IsFalse (be
.CanBuildChannelListener
<IReplySessionChannel
> (ctx
), "#5");
112 Assert
.IsFalse (be
.CanBuildChannelListener
<IOutputSessionChannel
> (ctx
), "#6");
113 Assert
.IsFalse (be
.CanBuildChannelListener
<IRequestSessionChannel
> (ctx
), "#7");
114 Assert
.IsFalse (be
.CanBuildChannelListener
<IInputSessionChannel
> (ctx
), "#8");
116 // IServiceChannel is not supported
117 Assert
.IsFalse (be
.CanBuildChannelListener
<IServiceChannel
> (ctx
), "#9");
118 Assert
.IsFalse (be
.CanBuildChannelListener
<IClientChannel
> (ctx
), "#10");
120 Assert
.IsFalse (be
.CanBuildChannelListener
<IDuplexChannel
> (ctx
), "#11");
121 Assert
.IsTrue (be
.CanBuildChannelListener
<IDuplexSessionChannel
> (ctx
), "#12");
125 public void CanBuildChannelListener2 ()
127 TcpTransportBindingElement be
=
128 new TcpTransportBindingElement ();
129 be
.TransferMode
= TransferMode
.Streamed
;
130 BindingContext ctx
= new BindingContext (
131 new CustomBinding (), empty_params
);
132 Assert
.IsTrue (be
.CanBuildChannelListener
<IReplyChannel
> (ctx
), "#1");
133 Assert
.IsFalse (be
.CanBuildChannelListener
<IOutputChannel
> (ctx
), "#2");
134 Assert
.IsFalse (be
.CanBuildChannelListener
<IRequestChannel
> (ctx
), "#3");
135 Assert
.IsFalse (be
.CanBuildChannelListener
<IInputChannel
> (ctx
), "#4");
137 Assert
.IsFalse (be
.CanBuildChannelListener
<IReplySessionChannel
> (ctx
), "#5");
138 Assert
.IsFalse (be
.CanBuildChannelListener
<IOutputSessionChannel
> (ctx
), "#6");
139 Assert
.IsFalse (be
.CanBuildChannelListener
<IRequestSessionChannel
> (ctx
), "#7");
140 Assert
.IsFalse (be
.CanBuildChannelListener
<IInputSessionChannel
> (ctx
), "#8");
142 // IServiceChannel is not supported
143 Assert
.IsFalse (be
.CanBuildChannelListener
<IServiceChannel
> (ctx
), "#9");
144 Assert
.IsFalse (be
.CanBuildChannelListener
<IClientChannel
> (ctx
), "#10");
146 Assert
.IsFalse (be
.CanBuildChannelListener
<IDuplexChannel
> (ctx
), "#11");
147 Assert
.IsFalse (be
.CanBuildChannelListener
<IDuplexSessionChannel
> (ctx
), "#12");
151 public void GetPrpertyBindingDeliveryCapabilities ()
153 var be
= new TcpTransportBindingElement ();
154 var dc
= be
.GetProperty
<IBindingDeliveryCapabilities
> (new BindingContext (new CustomBinding (), new BindingParameterCollection ()));
155 Assert
.IsTrue (dc
.AssuresOrderedDelivery
, "#1");
156 Assert
.IsFalse (dc
.QueuedDelivery
, "#2");
160 public void GetPropertySecurityCapabilities ()
162 var b
= new TcpTransportBindingElement ();
163 var s
= b
.GetProperty
<ISecurityCapabilities
> (new BindingContext (new CustomBinding (), new BindingParameterCollection ()));
164 Assert
.IsNull (s
, "#1");
168 public void SimpleDuplexBuffered () // sample[svc|cli]4.exe
170 ServiceHost host
= new ServiceHost (typeof (Foo
));
171 var bindingS
= new CustomBinding (new BindingElement
[] {
172 new BinaryMessageEncodingBindingElement (),
173 new TcpTransportBindingElement () });
174 bindingS
.ReceiveTimeout
= TimeSpan
.FromSeconds (5);
175 bindingS
.OpenTimeout
= TimeSpan
.FromSeconds (20);
176 host
.AddServiceEndpoint (typeof (IFoo
),
177 bindingS
, new Uri ("net.tcp://localhost:37564"));
178 host
.Description
.Behaviors
.Find
<ServiceBehaviorAttribute
> ().IncludeExceptionDetailInFaults
= true;
182 for (int i
= 0; i
< 2; i
++) {
183 var bindingC
= new NetTcpBinding ();
184 bindingC
.Security
.Mode
= SecurityMode
.None
;
185 IFooChannel proxy
= new ChannelFactory
<IFooChannel
> (bindingC
, new EndpointAddress ("net.tcp://localhost:37564/")).CreateChannel ();
188 Assert
.AreEqual ("TEST FOR ECHO", proxy
.Echo ("TEST FOR ECHO"), "#1");
189 var sid
= proxy
.SessionId
;
190 Assert
.AreEqual (3000, proxy
.Add (1000, 2000), "#2");
191 Assert
.AreEqual (sid
, proxy
.SessionId
, "#3");
196 } catch (Exception ex
) {
197 Console
.Error
.WriteLine (ex
);
204 [Category ("NotWorking")]
205 // FIXME: To enable this, we must fix the "request-reply TCP channel must close the connection" issue.
206 // It is strange, but the standalone test just works.
207 public void SimpleDuplexStreamed () // sample[svc|cli]5.exe
209 ServiceHost host
= new ServiceHost (typeof (Foo
));
210 NetTcpBinding bindingS
= new NetTcpBinding ();
211 bindingS
.TransferMode
= TransferMode
.Streamed
;
212 bindingS
.Security
.Mode
= SecurityMode
.None
;
213 bindingS
.ReceiveTimeout
= TimeSpan
.FromSeconds (5);
214 bindingS
.OpenTimeout
= TimeSpan
.FromSeconds (20);
215 host
.AddServiceEndpoint (typeof (IFoo
),
216 bindingS
, new Uri ("net.tcp://localhost:37564"));
217 host
.Description
.Behaviors
.Find
<ServiceBehaviorAttribute
> ().IncludeExceptionDetailInFaults
= true;
221 for (int i
= 0; i
< 2; i
++) {
222 var bindingC
= new NetTcpBinding ();
223 bindingS
.TransferMode
= TransferMode
.Streamed
;
224 bindingC
.Security
.Mode
= SecurityMode
.None
;
225 IFooChannel proxy
= new ChannelFactory
<IFooChannel
> (bindingC
, new EndpointAddress ("net.tcp://localhost:37564/")).CreateChannel ();
228 Assert
.AreEqual ("TEST FOR ECHO", proxy
.Echo ("TEST FOR ECHO"), "#1");
229 Assert
.AreEqual (3000, proxy
.Add (1000, 2000), "#2");
240 public interface IFoo
243 string Echo (string msg
);
246 uint Add (uint v1
, uint v2
);
249 public interface IFooChannel
: IFoo
, IClientChannel
255 public string Echo (string msg
)
260 public uint Add (uint v1
, uint v2
)