using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
using System.Net;
using System.Net.Security;
using System.ServiceModel;
get { return httpChannelManager.HttpListener; }
}
+ object creator_lock = new object ();
+
protected override TChannel CreateChannel (TimeSpan timeout)
+ {
+ lock (creator_lock) {
+ return CreateChannelCore (timeout);
+ }
+ }
+
+ TChannel CreateChannelCore (TimeSpan timeout)
{
if (typeof (TChannel) == typeof (IReplyChannel))
return (TChannel) (object) new HttpSimpleReplyChannel ((HttpSimpleChannelListener<IReplyChannel>) (object) this);
+ // FIXME: session channel support
+ if (typeof (TChannel) == typeof (IReplySessionChannel))
+ throw new NotImplementedException ();
- // FIXME: implement more
- throw new NotImplementedException ();
+ throw new NotSupportedException (String.Format ("Channel type {0} is not supported", typeof (TChannel)));
}
protected override void OnOpen (TimeSpan timeout)
StartListening (timeout);
}
+ protected override void OnAbort ()
+ {
+ httpChannelManager.Stop (true);
+ }
+
protected override void OnClose (TimeSpan timeout)
{
+ if (State == CommunicationState.Closed)
+ return;
base.OnClose (timeout);
- httpChannelManager.Stop ();
+ // FIXME: it is said that channels are not closed
+ // when the channel listener is closed.
+ // http://blogs.msdn.com/drnick/archive/2006/03/22/557642.aspx
+ httpChannelManager.Stop (false);
}
void StartListening (TimeSpan timeout)
{
}
+ SvcHttpHandler http_handler;
+ internal SvcHttpHandler HttpHandler {
+ get {
+ if (http_handler == null)
+ http_handler = SvcHttpHandlerFactory.GetHandlerForListener (this);
+ return http_handler;
+ }
+ }
+
protected override TChannel CreateChannel (TimeSpan timeout)
{
if (typeof (TChannel) == typeof (IReplyChannel))
return (TChannel) (object) new AspNetReplyChannel ((AspNetChannelListener<IReplyChannel>) (object) this);
+ // FIXME: session channel support
+ if (typeof (TChannel) == typeof (IReplySessionChannel))
+ throw new NotImplementedException ();
- // FIXME: implement more
- throw new NotImplementedException ();
+ throw new NotSupportedException (String.Format ("Channel type {0} is not supported", typeof (TChannel)));
+ }
+
+ protected override void OnAbort ()
+ {
+ HttpHandler.CloseServiceChannel ();
+ }
+
+ protected override void OnClose (TimeSpan timeout)
+ {
+ HttpHandler.CloseServiceChannel ();
+ base.OnClose (timeout);
}
}
- internal abstract class HttpChannelListenerBase<TChannel> : ChannelListenerBase<TChannel>
+ internal abstract class HttpChannelListenerBase<TChannel> : InternalChannelListenerBase<TChannel>
where TChannel : class, IChannel
{
HttpTransportBindingElement source;
BindingContext context;
- Uri listen_uri;
List<TChannel> channels = new List<TChannel> ();
MessageEncoder encoder;
public HttpChannelListenerBase (HttpTransportBindingElement source,
BindingContext context)
- : base (context.Binding)
+ : base (context)
{
- accept_channel_delegate = new Func<TimeSpan,TChannel> (OnAcceptChannel);
-
- // FIXME: consider ListenUriMode
- // FIXME: there should be some way to post-provide Uri in case of null listenerUri in context.
- listen_uri = context.ListenUriBaseAddress != null ?
- new Uri (context.ListenUriBaseAddress, context.ListenUriRelativeAddress) : null;
foreach (BindingElement be in context.RemainingBindingElements) {
MessageEncodingBindingElement mbe = be as MessageEncodingBindingElement;
if (mbe != null) {
get { return encoder; }
}
- public override Uri Uri {
- get { return listen_uri; }
- }
-
- protected IList<TChannel> Channels {
- get { return channels; }
- }
-
protected override TChannel OnAcceptChannel (TimeSpan timeout)
{
TChannel ch = CreateChannel (timeout);
- Channels.Add (ch);
return ch;
}
protected abstract TChannel CreateChannel (TimeSpan timeout);
- Func<TimeSpan,TChannel> accept_channel_delegate;
-
- protected override IAsyncResult OnBeginAcceptChannel (
- TimeSpan timeout, AsyncCallback callback,
- object asyncState)
- {
- return accept_channel_delegate.BeginInvoke (timeout, callback, asyncState);
- }
-
- protected override TChannel OnEndAcceptChannel (IAsyncResult result)
- {
- return accept_channel_delegate.EndInvoke (result);
- }
-
- protected override IAsyncResult OnBeginWaitForChannel (
- TimeSpan timeout, AsyncCallback callback, object state)
- {
- throw new NotImplementedException ();
- }
-
- protected override bool OnEndWaitForChannel (IAsyncResult result)
- {
- throw new NotImplementedException ();
- }
-
protected override bool OnWaitForChannel (TimeSpan timeout)
{
throw new NotImplementedException ();
}
- protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
- AsyncCallback callback, object state)
- {
- throw new NotImplementedException ();
- }
-
- protected override void OnEndOpen (IAsyncResult result)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- protected override IAsyncResult OnBeginClose (TimeSpan timeout,
- AsyncCallback callback, object state)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- protected override void OnEndClose (IAsyncResult result)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO ("find out what to do here.")]
protected override void OnAbort ()
{
+ OnClose (TimeSpan.Zero);
}
protected override void OnOpen (TimeSpan timeout)
protected override void OnClose (TimeSpan timeout)
{
- foreach (TChannel ch in Channels)
- ch.Close(timeout);
+ DateTime start = DateTime.Now;
+ base.OnClose (timeout - (DateTime.Now - start));
}
}
}