2 // ServiceRuntimeChannel.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2007 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.Reflection;
31 using System.ServiceModel.Channels;
32 using System.ServiceModel.Description;
33 using System.ServiceModel.Dispatcher;
34 using System.ServiceModel.MonoInternal;
36 namespace System.ServiceModel.MonoInternal
38 #if DISABLE_REAL_PROXY
39 // FIXME: this is a (similar) workaround for bug 571907.
42 class DuplexServiceRuntimeChannel : ServiceRuntimeChannel, IDuplexContextChannel, IInternalContextChannel
44 public DuplexServiceRuntimeChannel (IChannel channel, DispatchRuntime runtime)
45 : base (channel, runtime)
48 throw new ArgumentNullException ("channel");
49 // setup callback ClientRuntimeChannel.
50 var crt = runtime.CallbackClientRuntime;
52 throw new InvalidOperationException ("The DispatchRuntime does not have CallbackClientRuntime");
53 contract = ContractDescriptionGenerator.GetCallbackContract (runtime.Type, crt.CallbackClientType);
54 client = new ClientRuntimeChannel (crt, contract, this.DefaultOpenTimeout, this.DefaultCloseTimeout, channel, null,
55 runtime.ChannelDispatcher.MessageVersion, this.RemoteAddress, null);
58 ClientRuntimeChannel client;
59 ContractDescription contract;
61 public override bool AllowOutputBatching {
62 get { return client.AllowOutputBatching; }
63 set { client.AllowOutputBatching = value; }
66 public override TimeSpan OperationTimeout {
67 get { return client.OperationTimeout; }
68 set { client.OperationTimeout = value; }
71 public bool AutomaticInputSessionShutdown {
72 get { throw new NotImplementedException (); }
73 set { throw new NotImplementedException (); }
76 public InstanceContext CallbackInstance { get; set; }
78 public ContractDescription Contract {
79 get { return contract; }
82 public OperationContext Context {
86 Action<TimeSpan> session_shutdown_delegate;
88 public void CloseOutputSession (TimeSpan timeout)
90 throw new NotImplementedException ();
93 public IAsyncResult BeginCloseOutputSession (TimeSpan timeout, AsyncCallback callback, object state)
95 if (session_shutdown_delegate == null)
96 session_shutdown_delegate = new Action<TimeSpan> (CloseOutputSession);
97 return session_shutdown_delegate.BeginInvoke (timeout, callback, state);
100 public void EndCloseOutputSession (IAsyncResult result)
102 session_shutdown_delegate.EndInvoke (result);
105 // proxy base implementation.
107 public IAsyncResult BeginProcess (MethodBase method, string operationName, object [] parameters, AsyncCallback callback, object asyncState)
109 return client.BeginProcess (method, operationName, parameters, callback, asyncState);
112 public object EndProcess (MethodBase method, string operationName, object [] parameters, IAsyncResult result)
114 return client.EndProcess (method, operationName, parameters, result);
117 public object Process (MethodBase method, string operationName, object [] parameters)
119 return client.Process (method, operationName, parameters);
123 // Its lifetime is per-session.
124 // InputOrReplyRequestProcessor's lifetime is per-call.
125 #if DISABLE_REAL_PROXY
126 // FIXME: this is a (similar) workaround for bug 571907.
129 class ServiceRuntimeChannel : CommunicationObject, IServiceChannel, IDisposable
131 IExtensionCollection<IContextChannel> extensions;
132 readonly IChannel channel;
133 readonly DispatchRuntime runtime;
135 public ServiceRuntimeChannel (IChannel channel, DispatchRuntime runtime)
137 this.channel = channel;
138 this.runtime = runtime;
141 void OnChannelClose (object o, EventArgs e)
146 #region IContextChannel
149 public virtual bool AllowOutputBatching { get; set; }
151 public IInputSession InputSession {
153 var ch = channel as ISessionChannel<IInputSession>;
156 var dch = channel as ISessionChannel<IDuplexSession>;
157 return dch != null ? dch.Session : null;
161 public EndpointAddress LocalAddress {
163 if (channel is IReplyChannel)
164 return ((IReplyChannel) channel).LocalAddress;
165 if (channel is IInputChannel)
166 return ((IInputChannel) channel).LocalAddress;
172 public virtual TimeSpan OperationTimeout { get; set; }
174 public IOutputSession OutputSession {
176 var dch = channel as ISessionChannel<IDuplexSession>;
177 return dch != null ? dch.Session : null;
181 public EndpointAddress RemoteAddress {
183 if (channel is IDuplexChannel)
184 return ((IDuplexChannel) channel).RemoteAddress;
189 public string SessionId {
190 get { return InputSession != null ? InputSession.Id : null; }
195 // CommunicationObject
196 protected internal override TimeSpan DefaultOpenTimeout {
197 get { return runtime.ChannelDispatcher.DefaultOpenTimeout; }
200 protected internal override TimeSpan DefaultCloseTimeout {
201 get { return runtime.ChannelDispatcher.DefaultCloseTimeout; }
204 protected override void OnAbort ()
209 Action<TimeSpan> close_delegate;
211 protected override IAsyncResult OnBeginClose (
212 TimeSpan timeout, AsyncCallback callback, object state)
214 if (close_delegate == null)
215 close_delegate = new Action<TimeSpan> (OnClose);
216 return close_delegate.BeginInvoke (timeout, callback, state);
219 protected override void OnEndClose (IAsyncResult result)
221 close_delegate.EndInvoke (result);
224 protected override void OnClose (TimeSpan timeout)
226 channel.Closing -= OnChannelClose;
229 protected override IAsyncResult OnBeginOpen (
230 TimeSpan timeout, AsyncCallback callback, object state)
232 return channel.BeginOpen (timeout, callback, state);
235 protected override void OnEndOpen (IAsyncResult result)
237 channel.EndOpen (result);
240 protected override void OnOpen (TimeSpan timeout)
242 if (channel.State == CommunicationState.Created)
243 channel.Open (timeout);
247 public T GetProperty<T> () where T : class
249 return channel.GetProperty<T> ();
252 // IExtensibleObject<IContextChannel>
253 public IExtensionCollection<IContextChannel> Extensions {
255 if (extensions == null)
256 extensions = new ExtensionCollection<IContextChannel> (this);
261 public Uri ListenUri {
262 get { return runtime.ChannelDispatcher.Listener.Uri; }
265 #region IDisposable Members
267 public void Dispose ()