* Methods.cs: Set the correct element name and namespace for headers (those
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Protocols / WebServiceHandlerFactory.cs
1 // 
2 // System.Web.Services.Protocols.WebServiceHandlerFactory.cs
3 //
4 // Authors:
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)
9 //
10 // Copyright (C) Tim Coleman, 2002
11 // Copyright (c) 2003 Ximian, Inc. (http://www.ximian.com)
12 //
13
14 using System.IO;
15 using System.Web.Services;
16 using System.Web.Services.Configuration;
17 using System.Web.UI;
18 using System.Collections.Specialized;
19
20 namespace System.Web.Services.Protocols
21 {
22         class DummyHttpHandler : IHttpHandler
23         {
24                 bool IHttpHandler.IsReusable {
25                         get { return false; }
26                 }
27
28                 void IHttpHandler.ProcessRequest (HttpContext context)
29                 {
30                         // Do nothing
31                 }
32         }
33         
34         public class WebServiceHandlerFactory : IHttpHandlerFactory
35         {
36
37                 #region Constructors
38
39                 public WebServiceHandlerFactory () 
40                 {
41                 }
42                 
43                 #endregion // Constructors
44
45                 #region Methods
46
47                 public IHttpHandler GetHandler (HttpContext context, string verb, string url, string filePath)
48                 {
49                         Type type = WebServiceParser.GetCompiledType (filePath, context);
50
51                         WSProtocol protocol = GuessProtocol (context, verb);
52                         IHttpHandler handler = null;
53
54                         if (!WSConfig.IsSupported (protocol))
55                                 return new DummyHttpHandler ();
56
57                         switch (protocol) {
58                         case WSProtocol.HttpSoap:
59                                 handler = new HttpSoapWebServiceHandler (type);
60                                 break;
61                         case WSProtocol.HttpPost:
62                                 handler = new HttpPostWebServiceHandler (type);
63                                 break;
64                         case WSProtocol.HttpGet:
65                                 handler = new HttpGetWebServiceHandler (type);
66                                 break;
67                         case WSProtocol.Documentation:
68                                 handler = new SoapDocumentationHandler (type, context);
69                                 break;
70                         }
71
72                         return handler;
73                 }
74
75                 static WSProtocol GuessProtocol (HttpContext context, string verb)
76                 {
77                         if (context.Request.PathInfo == null || context.Request.PathInfo == "")
78                         {
79                                 if (context.Request.RequestType == "GET")
80                                         return WSProtocol.Documentation;
81                                 else
82                                         return WSProtocol.HttpSoap;
83                         }
84                         else
85                         {
86                                 if (context.Request.RequestType == "GET")
87                                         return WSProtocol.HttpGet;
88                                 else
89                                         return WSProtocol.HttpPost;
90                         }
91                 }
92
93                 public void ReleaseHandler (IHttpHandler handler)
94                 {
95                 }
96
97                 #endregion // Methods
98         }
99 }