2 // System.Web.Services.Protocols.HttpWebClientProtocol.cs
\r
5 // Tim Coleman (tim@timcoleman.com)
\r
7 // Copyright (C) Tim Coleman, 2002
\r
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.ComponentModel;
\r
34 using System.Security.Cryptography.X509Certificates;
\r
35 using System.Threading;
\r
36 using System.Web.Services;
\r
38 namespace System.Web.Services.Protocols {
\r
39 public abstract class HttpWebClientProtocol : WebClientProtocol {
\r
43 bool allowAutoRedirect;
\r
44 X509CertificateCollection clientCertificates;
\r
45 CookieContainer cookieContainer;
\r
50 bool _unsafeAuthenticated;
\r
54 #region Constructors
\r
56 protected HttpWebClientProtocol ()
\r
58 allowAutoRedirect = false;
\r
59 clientCertificates = null;
\r
60 cookieContainer = null;
\r
61 proxy = null; // FIXME
\r
62 userAgent = String.Format ("Mono Web Services Client Protocol {0}", Environment.Version);
\r
65 #endregion // Constructors
\r
69 [DefaultValue (false)]
\r
70 [WebServicesDescription ("Enable automatic handling of server redirects.")]
\r
71 public bool AllowAutoRedirect {
\r
72 get { return allowAutoRedirect; }
\r
73 set { allowAutoRedirect = value; }
\r
77 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
78 [WebServicesDescription ("The client certificates that will be sent to the server, if the server requests them.")]
\r
79 public X509CertificateCollection ClientCertificates {
\r
81 if (clientCertificates == null)
\r
82 clientCertificates = new X509CertificateCollection ();
\r
83 return clientCertificates;
\r
87 [DefaultValue (null)]
\r
88 [WebServicesDescription ("A container for all cookies received from servers in the current session.")]
\r
89 public CookieContainer CookieContainer {
\r
90 get { return cookieContainer; }
\r
91 set { cookieContainer = value; }
\r
95 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
96 public IWebProxy Proxy {
\r
97 get { return proxy; }
\r
98 set { proxy = value; }
\r
101 [WebServicesDescription ("Sets the user agent http header for the request.")]
\r
102 public string UserAgent {
\r
103 get { return userAgent; }
\r
104 set { userAgent = value; }
\r
108 public bool UnsafeAuthenticatedConnectionSharing
\r
110 get { return _unsafeAuthenticated; }
\r
111 set { _unsafeAuthenticated = value; }
\r
115 #endregion // Properties
\r
119 internal virtual void CheckForCookies (HttpWebResponse response)
\r
121 CookieCollection cookies = response.Cookies;
\r
122 if (cookieContainer == null || cookies.Count == 0)
\r
125 CookieCollection coll = cookieContainer.GetCookies (uri);
\r
126 foreach (Cookie c in cookies) {
\r
128 foreach (Cookie prev in coll) {
\r
129 if (c.Equals (prev)) {
\r
135 cookieContainer.Add (c);
\r
139 protected override WebRequest GetWebRequest (Uri uri)
\r
141 WebRequest req = base.GetWebRequest (uri);
\r
142 HttpWebRequest request = req as HttpWebRequest;
\r
143 if (request == null)
\r
146 request.AllowAutoRedirect = allowAutoRedirect;
\r
147 if (clientCertificates != null)
\r
148 request.ClientCertificates.AddRange (clientCertificates);
\r
150 request.CookieContainer = cookieContainer;
\r
152 request.Proxy = proxy;
\r
154 request.UserAgent = userAgent;
\r
157 // request.UnsafeAuthenticatedConnectionSharing = _unsafeAuthenticated;
\r
163 protected override WebResponse GetWebResponse (WebRequest request)
\r
165 WebResponse response = base.GetWebResponse (request);
\r
166 HttpWebResponse wr = response as HttpWebResponse;
\r
168 CheckForCookies (wr);
\r
173 protected override WebResponse GetWebResponse (WebRequest request, IAsyncResult result)
\r
175 WebResponse response = base.GetWebResponse (request, result);
\r
176 HttpWebResponse wr = response as HttpWebResponse;
\r
178 CheckForCookies (wr);
\r
183 #endregion // Methods
\r