2009-05-13 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Dispatcher / ChannelDispatcher.cs
index 1e16268ce0344877df715dd134717e5331e86aad..802cd394064705a7214e17f8aed4b548a3ecb546 100644 (file)
@@ -45,7 +45,7 @@ namespace System.ServiceModel.Dispatcher
                Collection<IErrorHandler> error_handlers
                        = new Collection<IErrorHandler> ();
                IChannelListener listener;
-               IDefaultCommunicationTimeouts timeouts;
+               internal IDefaultCommunicationTimeouts timeouts; // FIXME: remove internal
                MessageVersion message_version;
                bool receive_sync, include_exception_detail_in_faults,
                        manual_addressing, is_tx_receive;
@@ -64,17 +64,14 @@ namespace System.ServiceModel.Dispatcher
                SynchronizedCollection<EndpointDispatcher> endpoints;
 
                [MonoTODO ("get binding info from config")]
-               public ChannelDispatcher (IChannelListener listener)                    
+               public ChannelDispatcher (IChannelListener listener)
+                       : this (listener, null)
                {
-                       if (listener == null)
-                               throw new ArgumentNullException ("listener");
-                       Init (listener, null, null);
                }
 
                public ChannelDispatcher (
                        IChannelListener listener, string bindingName)
-                       : this (listener, bindingName, 
-                               DefaultCommunicationTimeouts.Instance)
+                       : this (listener, bindingName, null)
                {
                }
 
@@ -84,10 +81,6 @@ namespace System.ServiceModel.Dispatcher
                {
                        if (listener == null)
                                throw new ArgumentNullException ("listener");
-                       if (bindingName == null)
-                               throw new ArgumentNullException ("bindingName");
-                       if (timeouts == null)
-                               throw new ArgumentNullException ("timeouts");
                        Init (listener, bindingName, timeouts);
                }
 
@@ -96,7 +89,9 @@ namespace System.ServiceModel.Dispatcher
                {
                        this.listener = listener;
                        this.binding_name = bindingName;
-                       this.timeouts = timeouts;
+                       // IChannelListener is often a ChannelListenerBase
+                       // which implements IDefaultCommunicationTimeouts.
+                       this.timeouts = timeouts ?? listener as IDefaultCommunicationTimeouts ?? DefaultCommunicationTimeouts.Instance;
                        endpoints = new SynchronizedCollection<EndpointDispatcher> ();
                }
 
@@ -430,6 +425,7 @@ namespace System.ServiceModel.Dispatcher
                                //3. Let the appropriate endpoint handle the request.
 
                                IChannel ch = channel_acceptor ();
+                               ch.Open (owner.timeouts.OpenTimeout);
                                reply = ch as IReplyChannel;
                                input = ch as IInputChannel;
 
@@ -467,7 +463,7 @@ namespace System.ServiceModel.Dispatcher
                                                throw new InvalidOperationException ("The reply channel didn't return RequestContext");
 
                                        EndpointDispatcher candidate = FindEndpointDispatcher (rc.RequestMessage);
-                                       new InputOrReplyRequestProcessor (candidate.DispatchRuntime, reply, owner.timeouts).
+                                       new InputOrReplyRequestProcessor (candidate.DispatchRuntime, reply).
                                                ProcessReply (rc);
                                }
                                catch (EndpointNotFoundException ex) {
@@ -482,7 +478,7 @@ namespace System.ServiceModel.Dispatcher
 
                                try {
                                        candidate = FindEndpointDispatcher (message);
-                                       new InputOrReplyRequestProcessor (candidate.DispatchRuntime, reply, owner.timeouts).
+                                       new InputOrReplyRequestProcessor (candidate.DispatchRuntime, input).
                                                ProcessInput(message);
                                }
                                catch (EndpointNotFoundException ex) {