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 // FIXME: this is a (similar) workaround for bug 571907.
39 public class DuplexServiceRuntimeChannel
: ServiceRuntimeChannel
, IDuplexContextChannel
41 public DuplexServiceRuntimeChannel (IChannel channel
, DispatchRuntime runtime
)
42 : base (channel
, runtime
)
44 // setup callback ClientRuntimeChannel.
45 var crt
= runtime
.CallbackClientRuntime
;
46 var cd
= ContractDescriptionGenerator
.GetCallbackContract (runtime
.Type
, crt
.CallbackClientType
);
47 client
= new ClientRuntimeChannel (crt
, cd
, this.DefaultOpenTimeout
, this.DefaultCloseTimeout
, channel
, null,
48 runtime
.ChannelDispatcher
.MessageVersion
, this.RemoteAddress
, null);
51 ClientRuntimeChannel client
;
53 public override bool AllowOutputBatching
{
54 get { return client.AllowOutputBatching; }
55 set { client.AllowOutputBatching = value; }
58 public virtual TimeSpan OperationTimeout
{
59 get { return client.OperationTimeout; }
60 set { client.OperationTimeout = value; }
63 public bool AutomaticInputSessionShutdown
{
64 get { throw new NotImplementedException (); }
65 set { throw new NotImplementedException (); }
68 public InstanceContext CallbackInstance { get; set; }
70 Action
<TimeSpan
> session_shutdown_delegate
;
72 public void CloseOutputSession (TimeSpan timeout
)
74 throw new NotImplementedException ();
77 public IAsyncResult
BeginCloseOutputSession (TimeSpan timeout
, AsyncCallback callback
, object state
)
79 if (session_shutdown_delegate
== null)
80 session_shutdown_delegate
= new Action
<TimeSpan
> (CloseOutputSession
);
81 return session_shutdown_delegate
.BeginInvoke (timeout
, callback
, state
);
84 public void EndCloseOutputSession (IAsyncResult result
)
86 session_shutdown_delegate
.EndInvoke (result
);
89 // proxy base implementation.
91 public IAsyncResult
BeginProcess (MethodBase method
, string operationName
, object [] parameters
, AsyncCallback callback
, object asyncState
)
93 return client
.BeginProcess (method
, operationName
, parameters
, callback
, asyncState
);
96 public object EndProcess (MethodBase method
, string operationName
, object [] parameters
, IAsyncResult result
)
98 return client
.EndProcess (method
, operationName
, parameters
, result
);
101 public object Process (MethodBase method
, string operationName
, object [] parameters
)
103 return client
.Process (method
, operationName
, parameters
);
107 // FIXME: this is a (similar) workaround for bug 571907.
108 public class ServiceRuntimeChannel
: CommunicationObject
, IServiceChannel
110 IExtensionCollection
<IContextChannel
> extensions
;
111 readonly IChannel channel
;
112 readonly DispatchRuntime runtime
;
114 public ServiceRuntimeChannel (IChannel channel
, DispatchRuntime runtime
)
116 this.channel
= channel
;
117 this.runtime
= runtime
;
120 #region IContextChannel
123 public virtual bool AllowOutputBatching { get; set; }
125 public IInputSession InputSession
{
127 var ch
= channel
as ISessionChannel
<IInputSession
>;
130 var dch
= channel
as ISessionChannel
<IDuplexSession
>;
131 return dch
!= null ? dch
.Session
: null;
135 public EndpointAddress LocalAddress
{
137 if (channel
is IReplyChannel
)
138 return ((IReplyChannel
) channel
).LocalAddress
;
139 if (channel
is IInputChannel
)
140 return ((IInputChannel
) channel
).LocalAddress
;
146 public virtual TimeSpan OperationTimeout { get; set; }
148 public IOutputSession OutputSession
{
150 var dch
= channel
as ISessionChannel
<IDuplexSession
>;
151 return dch
!= null ? dch
.Session
: null;
155 public EndpointAddress RemoteAddress
{
157 if (channel
is IDuplexChannel
)
158 return ((IDuplexChannel
) channel
).RemoteAddress
;
163 public string SessionId
{
164 get { return InputSession != null ? InputSession.Id : null; }
169 // CommunicationObject
170 protected internal override TimeSpan DefaultOpenTimeout
{
171 get { return runtime.ChannelDispatcher.DefaultOpenTimeout; }
174 protected internal override TimeSpan DefaultCloseTimeout
{
175 get { return runtime.ChannelDispatcher.DefaultCloseTimeout; }
178 protected override void OnAbort ()
183 protected override IAsyncResult
OnBeginClose (
184 TimeSpan timeout
, AsyncCallback callback
, object state
)
186 return channel
.BeginClose (timeout
, callback
, state
);
189 protected override void OnEndClose (IAsyncResult result
)
191 channel
.EndClose (result
);
194 protected override void OnClose (TimeSpan timeout
)
196 channel
.Close (timeout
);
199 protected override IAsyncResult
OnBeginOpen (
200 TimeSpan timeout
, AsyncCallback callback
, object state
)
202 return channel
.BeginOpen (timeout
, callback
, state
);
205 protected override void OnEndOpen (IAsyncResult result
)
207 channel
.EndOpen (result
);
210 protected override void OnOpen (TimeSpan timeout
)
212 channel
.Open (timeout
);
216 public T GetProperty
<T
> () where T
: class
218 return channel
.GetProperty
<T
> ();
221 // IExtensibleObject<IContextChannel>
222 public IExtensionCollection
<IContextChannel
> Extensions
{
224 if (extensions
== null)
225 extensions
= new ExtensionCollection
<IContextChannel
> (this);
230 public Uri ListenUri
{
231 get { return runtime.ChannelDispatcher.Listener.Uri; }
234 #region IDisposable Members
236 public void Dispose ()