2 // System.Web.Services.Protocols.WebServiceHandlerFactory.cs
5 // Tim Coleman (tim@timcoleman.com)
6 // Dave Bettin (dave@opendotnet.com)
7 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // Lluis Sanchez Gual (lluis@ximian.com)
10 // Copyright (C) Tim Coleman, 2002
11 // Copyright (c) 2003 Ximian, Inc. (http://www.ximian.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Web.Services;
37 using System.Web.Services.Configuration;
38 using System.Web.SessionState;
40 using System.Collections.Specialized;
42 namespace System.Web.Services.Protocols
44 class DummyHttpHandler : IHttpHandler
46 bool IHttpHandler.IsReusable {
50 void IHttpHandler.ProcessRequest (HttpContext context)
56 class SessionWrapperHandler : IHttpHandler, IRequiresSessionState
60 public SessionWrapperHandler (IHttpHandler handler)
62 this.handler = handler;
65 public bool IsReusable {
66 get { return handler.IsReusable; }
69 public void ProcessRequest (HttpContext context)
71 handler.ProcessRequest (context);
75 class ReadOnlySessionWrapperHandler : IHttpHandler, IRequiresSessionState, IReadOnlySessionState
79 public ReadOnlySessionWrapperHandler (IHttpHandler handler)
81 this.handler = handler;
84 public bool IsReusable {
85 get { return handler.IsReusable; }
88 public void ProcessRequest (HttpContext context)
90 handler.ProcessRequest (context);
93 public class WebServiceHandlerFactory : IHttpHandlerFactory
98 public WebServiceHandlerFactory ()
102 #endregion // Constructors
106 public IHttpHandler GetHandler (HttpContext context, string verb, string url, string filePath)
108 Type type = WebServiceParser.GetCompiledType (filePath, context);
110 WSProtocol protocol = GuessProtocol (context, verb);
111 IHttpHandler handler = null;
113 if (!WSConfig.IsSupported (protocol))
114 return new DummyHttpHandler ();
117 case WSProtocol.HttpSoap:
118 handler = GetTypeHandler (context, new HttpSoapWebServiceHandler (type));
120 case WSProtocol.HttpPost:
121 case WSProtocol.HttpGet:
122 handler = GetTypeHandler (context, new HttpSimpleWebServiceHandler (type, protocol.ToString ()));
124 case WSProtocol.Documentation:
125 SoapDocumentationHandler soapHandler;
126 soapHandler = new SoapDocumentationHandler (type, context);
127 if (soapHandler.PageHandler is IRequiresSessionState) {
128 if (soapHandler.PageHandler is IReadOnlySessionState)
129 handler = new ReadOnlySessionWrapperHandler (soapHandler);
131 handler = new SessionWrapperHandler (soapHandler);
133 handler = soapHandler;
141 IHttpHandler GetTypeHandler (HttpContext context, WebServiceHandler handler)
143 MethodStubInfo method = handler.GetRequestMethod (context);
144 if (method == null) return null;
146 if (method.MethodInfo.EnableSession)
147 return new SessionWrapperHandler (handler);
152 static WSProtocol GuessProtocol (HttpContext context, string verb)
154 if (context.Request.PathInfo == null || context.Request.PathInfo == "")
156 if (context.Request.RequestType == "GET")
157 return WSProtocol.Documentation;
159 return WSProtocol.HttpSoap;
163 if (context.Request.RequestType == "GET")
164 return WSProtocol.HttpGet;
166 return WSProtocol.HttpPost;
170 public void ReleaseHandler (IHttpHandler handler)
174 #endregion // Methods