2 // AspNetReplyChannel.cs
5 // Ankit Jain <jankit@novell.com>
7 // Copyright (C) 2006 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;
32 using System.ServiceModel;
34 using System.Threading;
37 namespace System.ServiceModel.Channels
39 internal class AspNetReplyChannel : HttpReplyChannel
41 HttpContext http_context;
44 public AspNetReplyChannel (HttpChannelListener<IReplyChannel> listener,
46 : base (listener, timeout)
51 public override bool TryReceiveRequest (TimeSpan timeout, out RequestContext context)
55 if (waiting.Count == 0 && !WaitForRequest (timeout))
57 HttpListenerContext ctx = null;
59 if (waiting.Count > 0) {
65 // Though as long as this instance is used
66 // synchronously, it should not happen.
71 if (http_context.Request.HttpMethod == "GET") {
72 if (http_context.Request.QueryString ["wsdl"] != null) {
73 msg = Message.CreateMessage (Encoder.MessageVersion,
74 "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get");
75 msg.Headers.To = http_context.Request.Url;
77 msg = Message.CreateMessage (Encoder.MessageVersion, null);
78 msg.Headers.To = http_context.Request.Url;
81 //FIXME: Do above stuff for HttpContext ?
82 int maxSizeOfHeaders = 0x10000;
84 msg = Encoder.ReadMessage (
85 http_context.Request.InputStream, maxSizeOfHeaders);
87 if (Encoder.MessageVersion.Envelope == EnvelopeVersion.Soap11) {
88 string action = GetHeaderItem (http_context.Request.Headers ["SOAPAction"]);
90 msg.Headers.Action = action;
93 context = new AspNetRequestContext (this, msg, http_context);
98 public HttpContext Context {
99 get { return http_context; }
100 set { http_context = value; }
103 public override bool WaitForRequest (TimeSpan timeout)
105 // FIXME: we might want to take other approaches.
106 if (timeout.Ticks > int.MaxValue)
107 timeout = TimeSpan.FromDays (20);
109 SvcHttpHandler h = SvcHttpHandlerFactory.GetHandler (uri.OriginalString.Replace ("file://", ""));
110 return h.WaitForRequest (this, timeout);
113 AutoResetEvent wait = new AutoResetEvent (false);
114 source.Http.BeginGetContext (HttpContextReceived, wait);
115 // FIXME: we might want to take other approaches.
116 if (timeout.Ticks > int.MaxValue)
117 timeout = TimeSpan.FromDays (20);
118 return wait.WaitOne (timeout, false);
122 void HttpContextReceived (IAsyncResult result)
124 throw new NotImplementedException ();
126 waiting.Add (source.Http.EndGetContext (result));
127 AutoResetEvent wait = (AutoResetEvent) result.AsyncState;