WebServiceHandlerFactory.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // System.Web.Services.Protocols.WebServiceHandlerFactory.cs
  3. //
  4. // Authors:
  5. // Tim Coleman ([email protected])
  6. // Dave Bettin ([email protected])
  7. // Gonzalo Paniagua Javier ([email protected])
  8. // Lluis Sanchez Gual ([email protected])
  9. //
  10. // Copyright (C) Tim Coleman, 2002
  11. // Copyright (c) 2003 Ximian, Inc. (http://www.ximian.com)
  12. //
  13. using System.IO;
  14. using System.Web.Services;
  15. using System.Web.Services.Configuration;
  16. using System.Web.UI;
  17. using System.Collections.Specialized;
  18. namespace System.Web.Services.Protocols
  19. {
  20. class DummyHttpHandler : IHttpHandler
  21. {
  22. bool IHttpHandler.IsReusable {
  23. get { return false; }
  24. }
  25. void IHttpHandler.ProcessRequest (HttpContext context)
  26. {
  27. // Do nothing
  28. }
  29. }
  30. public class WebServiceHandlerFactory : IHttpHandlerFactory
  31. {
  32. #region Constructors
  33. public WebServiceHandlerFactory ()
  34. {
  35. }
  36. #endregion // Constructors
  37. #region Methods
  38. public IHttpHandler GetHandler (HttpContext context, string verb, string url, string filePath)
  39. {
  40. Type type = WebServiceParser.GetCompiledType (filePath, context);
  41. WSProtocol protocol = GuessProtocol (context, verb);
  42. IHttpHandler handler = null;
  43. if (!WSConfig.IsSupported (protocol))
  44. return new DummyHttpHandler ();
  45. switch (protocol) {
  46. case WSProtocol.HttpSoap:
  47. handler = new HttpSoapWebServiceHandler (type);
  48. break;
  49. case WSProtocol.HttpPost:
  50. handler = new HttpPostWebServiceHandler (type);
  51. break;
  52. case WSProtocol.HttpGet:
  53. handler = new HttpGetWebServiceHandler (type);
  54. break;
  55. case WSProtocol.Documentation:
  56. handler = new SoapDocumentationHandler (type, context);
  57. break;
  58. }
  59. return handler;
  60. }
  61. static WSProtocol GuessProtocol (HttpContext context, string verb)
  62. {
  63. if (context.Request.PathInfo == null || context.Request.PathInfo == "")
  64. {
  65. if (context.Request.RequestType == "GET")
  66. return WSProtocol.Documentation;
  67. else
  68. return WSProtocol.HttpSoap;
  69. }
  70. else
  71. {
  72. if (context.Request.RequestType == "GET")
  73. return WSProtocol.HttpGet;
  74. else
  75. return WSProtocol.HttpPost;
  76. }
  77. }
  78. public void ReleaseHandler (IHttpHandler handler)
  79. {
  80. }
  81. #endregion // Methods
  82. }
  83. }