HttpWebClientProtocol.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // System.Web.Services.Protocols.HttpWebClientProtocol.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2002
  8. //
  9. using System;
  10. using System.ComponentModel;
  11. using System.Net;
  12. using System.Security.Cryptography.X509Certificates;
  13. using System.Threading;
  14. using System.Web.Services;
  15. namespace System.Web.Services.Protocols {
  16. public abstract class HttpWebClientProtocol : WebClientProtocol {
  17. #region Fields
  18. bool allowAutoRedirect;
  19. X509CertificateCollection clientCertificates;
  20. CookieContainer cookieContainer;
  21. IWebProxy proxy;
  22. string userAgent;
  23. #endregion
  24. #region Constructors
  25. protected HttpWebClientProtocol ()
  26. {
  27. allowAutoRedirect = false;
  28. clientCertificates = new X509CertificateCollection ();
  29. cookieContainer = null;
  30. proxy = null; // FIXME
  31. userAgent = String.Format ("Mono Web Services Client Protocol {0}", Environment.Version);
  32. }
  33. #endregion // Constructors
  34. #region Properties
  35. [DefaultValue (false)]
  36. [WebServicesDescription ("Enable automatic handling of server redirects.")]
  37. public bool AllowAutoRedirect {
  38. get { return allowAutoRedirect; }
  39. set { allowAutoRedirect = value; }
  40. }
  41. [Browsable (false)]
  42. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  43. [WebServicesDescription ("The client certificates that will be sent to the server, if the server requests them.")]
  44. public X509CertificateCollection ClientCertificates {
  45. get { return clientCertificates; }
  46. }
  47. [DefaultValue (null)]
  48. [WebServicesDescription ("A container for all cookies received from servers in the current session.")]
  49. public CookieContainer CookieContainer {
  50. get { return cookieContainer; }
  51. set { cookieContainer = value; }
  52. }
  53. [Browsable (false)]
  54. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  55. public IWebProxy Proxy {
  56. get { return proxy; }
  57. set { proxy = value; }
  58. }
  59. [WebServicesDescription ("Sets the user agent http header for the request.")]
  60. public string UserAgent {
  61. get { return userAgent; }
  62. set { userAgent = value; }
  63. }
  64. #endregion // Properties
  65. #region Methods
  66. protected override WebRequest GetWebRequest (Uri uri)
  67. {
  68. if (null == uri)
  69. throw new InvalidOperationException ("The uri parameter is a null reference.");
  70. return WebRequest.Create (uri);
  71. }
  72. protected override WebResponse GetWebResponse (WebRequest request)
  73. {
  74. return request.GetResponse ();
  75. }
  76. protected override WebResponse GetWebResponse (WebRequest request, IAsyncResult result)
  77. {
  78. IAsyncResult ar = request.BeginGetResponse (null, null);
  79. ar.AsyncWaitHandle.WaitOne ();
  80. return request.EndGetResponse (result);
  81. }
  82. #endregion // Methods
  83. }
  84. }