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
37 using System.Collections;
\r
39 namespace System.Web.Services.Protocols {
\r
40 public abstract class HttpWebClientProtocol : WebClientProtocol {
\r
44 bool allowAutoRedirect;
\r
45 X509CertificateCollection clientCertificates;
\r
46 CookieContainer cookieContainer;
\r
49 CookieCollection prevCookies;
\r
52 bool _unsafeAuthenticated;
\r
56 #region Constructors
\r
58 protected HttpWebClientProtocol ()
\r
60 allowAutoRedirect = false;
\r
61 clientCertificates = null;
\r
62 cookieContainer = null;
\r
63 proxy = null; // FIXME
\r
64 userAgent = String.Format ("Mono Web Services Client Protocol {0}", Environment.Version);
\r
67 #endregion // Constructors
\r
71 [DefaultValue (false)]
\r
72 [WebServicesDescription ("Enable automatic handling of server redirects.")]
\r
73 public bool AllowAutoRedirect {
\r
74 get { return allowAutoRedirect; }
\r
75 set { allowAutoRedirect = value; }
\r
79 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
80 [WebServicesDescription ("The client certificates that will be sent to the server, if the server requests them.")]
\r
81 public X509CertificateCollection ClientCertificates {
\r
83 if (clientCertificates == null)
\r
84 clientCertificates = new X509CertificateCollection ();
\r
85 return clientCertificates;
\r
89 [DefaultValue (null)]
\r
90 [WebServicesDescription ("A container for all cookies received from servers in the current session.")]
\r
91 public CookieContainer CookieContainer {
\r
92 get { return cookieContainer; }
\r
93 set { cookieContainer = value; }
\r
97 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
98 public IWebProxy Proxy {
\r
99 get { return proxy; }
\r
100 set { proxy = value; }
\r
103 [WebServicesDescription ("Sets the user agent http header for the request.")]
\r
104 public string UserAgent {
\r
105 get { return userAgent; }
\r
106 set { userAgent = value; }
\r
110 public bool UnsafeAuthenticatedConnectionSharing
\r
112 get { return _unsafeAuthenticated; }
\r
113 set { _unsafeAuthenticated = value; }
\r
117 #endregion // Properties
\r
121 internal virtual void AddCookies (Uri uri)
\r
123 if (cookieContainer == null)
\r
124 cookieContainer = new CookieContainer ();
\r
126 if (prevCookies == null || prevCookies.Count == 0)
\r
129 CookieCollection coll = cookieContainer.GetCookies (uri);
\r
130 foreach (Cookie prev in prevCookies) {
\r
132 foreach (Cookie c in coll) {
\r
133 if (c.Equals (prev)) {
\r
140 cookieContainer.Add (prev);
\r
144 internal virtual void CheckForCookies (HttpWebResponse response)
\r
146 CookieCollection cookies = response.Cookies;
\r
147 if (cookies.Count == 0)
\r
150 if (prevCookies == null)
\r
151 prevCookies = new CookieCollection ();
\r
153 foreach (Cookie c in cookies)
\r
154 prevCookies.Add (c);
\r
157 protected override WebRequest GetWebRequest (Uri uri)
\r
159 WebRequest req = base.GetWebRequest (uri);
\r
160 HttpWebRequest request = req as HttpWebRequest;
\r
161 if (request == null)
\r
164 request.AllowAutoRedirect = allowAutoRedirect;
\r
165 if (clientCertificates != null)
\r
166 request.ClientCertificates.AddRange (clientCertificates);
\r
169 request.CookieContainer = cookieContainer;
\r
171 request.Proxy = proxy;
\r
173 request.UserAgent = userAgent;
\r
176 // request.UnsafeAuthenticatedConnectionSharing = _unsafeAuthenticated;
\r
182 protected override WebResponse GetWebResponse (WebRequest request)
\r
184 WebResponse response = base.GetWebResponse (request);
\r
185 HttpWebResponse wr = response as HttpWebResponse;
\r
187 CheckForCookies (wr);
\r
192 protected override WebResponse GetWebResponse (WebRequest request, IAsyncResult result)
\r
194 WebResponse response = base.GetWebResponse (request, result);
\r
195 HttpWebResponse wr = response as HttpWebResponse;
\r
197 CheckForCookies (wr);
\r
205 protected void CancelAsync (object userState)
\r
207 throw new NotImplementedException ();
\r
211 public static bool GenerateXmlMappings (Type type, ArrayList mapping)
\r
213 throw new NotImplementedException ();
\r
217 public static Hashtable GenerateXmlMappings (Type[] types, ArrayList mapping)
\r
219 throw new NotImplementedException ();
\r
223 #endregion // Methods
\r