2 // HttpChannelListener.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005 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.Collections.ObjectModel;
32 using System.Net.Security;
33 using System.ServiceModel;
34 using System.ServiceModel.Description;
35 using System.ServiceModel.Security;
38 namespace System.ServiceModel.Channels
40 internal class HttpChannelListener<TChannel> : ChannelListenerBase<TChannel>
41 where TChannel : class, IChannel
43 HttpTransportBindingElement source;
44 BindingContext context;
46 List<IChannel> channels = new List<IChannel> ();
47 MessageEncoder encoder;
48 HttpChannelManager<TChannel> httpChannelManager;
50 public HttpChannelListener (HttpTransportBindingElement source,
51 BindingContext context)
52 : base (context.Binding)
54 // FIXME: consider ListenUriMode
55 // FIXME: there should be some way to post-provide Uri in case of null listenerUri in context.
56 listen_uri = context.ListenUriBaseAddress != null ?
57 new Uri (context.ListenUriBaseAddress, context.ListenUriRelativeAddress) : null;
58 foreach (BindingElement be in context.RemainingBindingElements) {
59 MessageEncodingBindingElement mbe = be as MessageEncodingBindingElement;
61 encoder = mbe.CreateMessageEncoderFactory ().Encoder;
66 encoder = new TextMessageEncoder (MessageVersion.Default, Encoding.UTF8);
69 public HttpListener Http {
70 get { return httpChannelManager.HttpListener; }
73 public MessageEncoder MessageEncoder {
74 get { return encoder; }
77 public override Uri Uri {
78 get { return listen_uri; }
81 protected override TChannel OnAcceptChannel (TimeSpan timeout)
83 TChannel ch = PopulateChannel (timeout);
88 TChannel PopulateChannel (TimeSpan timeout)
90 if (typeof (TChannel) == typeof (IReplyChannel)) {
91 if (ServiceHostingEnvironment.InAspNet)
92 return (TChannel) (object) new AspNetReplyChannel (
93 (HttpChannelListener<IReplyChannel>) (object) this, timeout);
95 return (TChannel) (object) new HttpReplyChannel (
96 (HttpChannelListener<IReplyChannel>) (object) this, timeout);
99 // FIXME: implement more
101 throw new NotImplementedException ();
104 protected override IAsyncResult OnBeginAcceptChannel (
105 TimeSpan timeout, AsyncCallback callback,
108 throw new NotImplementedException ();
111 protected override TChannel OnEndAcceptChannel (IAsyncResult result)
113 throw new NotImplementedException ();
116 protected override IAsyncResult OnBeginWaitForChannel (
117 TimeSpan timeout, AsyncCallback callback, object state)
119 throw new NotImplementedException ();
122 protected override bool OnEndWaitForChannel (IAsyncResult result)
124 throw new NotImplementedException ();
127 protected override bool OnWaitForChannel (TimeSpan timeout)
129 throw new NotImplementedException ();
132 void StartListening (TimeSpan timeout)
134 httpChannelManager = new HttpChannelManager<TChannel> (this);
135 httpChannelManager.Open (timeout);
138 protected override void OnOpen (TimeSpan timeout)
140 if (ServiceHostingEnvironment.InAspNet)
143 StartListening (timeout);
146 protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
147 AsyncCallback callback, object state)
149 throw new NotImplementedException ();
152 protected override void OnEndOpen (IAsyncResult result)
154 throw new NotImplementedException ();
157 protected override void OnClose (TimeSpan timeout)
159 if (ServiceHostingEnvironment.InAspNet)
162 foreach (TChannel ch in channels)
164 httpChannelManager.Stop ();
168 protected override IAsyncResult OnBeginClose (TimeSpan timeout,
169 AsyncCallback callback, object state)
171 throw new NotImplementedException ();
175 protected override void OnEndClose (IAsyncResult result)
177 throw new NotImplementedException ();
180 [MonoTODO ("find out what to do here.")]
181 protected override void OnAbort ()