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
51 bool _unsafeAuthenticated;
\r
55 #region Constructors
\r
57 protected HttpWebClientProtocol ()
\r
59 allowAutoRedirect = false;
\r
60 clientCertificates = null;
\r
61 cookieContainer = null;
\r
62 proxy = null; // FIXME
\r
63 userAgent = String.Format ("Mono Web Services Client Protocol {0}", Environment.Version);
\r
66 #endregion // Constructors
\r
70 [DefaultValue (false)]
\r
71 [WebServicesDescription ("Enable automatic handling of server redirects.")]
\r
72 public bool AllowAutoRedirect {
\r
73 get { return allowAutoRedirect; }
\r
74 set { allowAutoRedirect = value; }
\r
78 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
79 [WebServicesDescription ("The client certificates that will be sent to the server, if the server requests them.")]
\r
80 public X509CertificateCollection ClientCertificates {
\r
82 if (clientCertificates == null)
\r
83 clientCertificates = new X509CertificateCollection ();
\r
84 return clientCertificates;
\r
88 [DefaultValue (null)]
\r
89 [WebServicesDescription ("A container for all cookies received from servers in the current session.")]
\r
90 public CookieContainer CookieContainer {
\r
91 get { return cookieContainer; }
\r
92 set { cookieContainer = value; }
\r
96 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
97 public IWebProxy Proxy {
\r
98 get { return proxy; }
\r
99 set { proxy = value; }
\r
102 [WebServicesDescription ("Sets the user agent http header for the request.")]
\r
103 public string UserAgent {
\r
104 get { return userAgent; }
\r
105 set { userAgent = value; }
\r
109 public bool UnsafeAuthenticatedConnectionSharing
\r
111 get { return _unsafeAuthenticated; }
\r
112 set { _unsafeAuthenticated = value; }
\r
116 #endregion // Properties
\r
120 internal virtual void CheckForCookies (HttpWebResponse response)
\r
122 CookieCollection cookies = response.Cookies;
\r
123 if (cookieContainer == null || cookies.Count == 0)
\r
126 CookieCollection coll = cookieContainer.GetCookies (uri);
\r
127 foreach (Cookie c in cookies) {
\r
129 foreach (Cookie prev in coll) {
\r
130 if (c.Equals (prev)) {
\r
136 cookieContainer.Add (c);
\r
140 protected override WebRequest GetWebRequest (Uri uri)
\r
142 WebRequest req = base.GetWebRequest (uri);
\r
143 HttpWebRequest request = req as HttpWebRequest;
\r
144 if (request == null)
\r
147 request.AllowAutoRedirect = allowAutoRedirect;
\r
148 if (clientCertificates != null)
\r
149 request.ClientCertificates.AddRange (clientCertificates);
\r
151 request.CookieContainer = cookieContainer;
\r
153 request.Proxy = proxy;
\r
155 request.UserAgent = userAgent;
\r
158 // request.UnsafeAuthenticatedConnectionSharing = _unsafeAuthenticated;
\r
164 protected override WebResponse GetWebResponse (WebRequest request)
\r
166 WebResponse response = base.GetWebResponse (request);
\r
167 HttpWebResponse wr = response as HttpWebResponse;
\r
169 CheckForCookies (wr);
\r
174 protected override WebResponse GetWebResponse (WebRequest request, IAsyncResult result)
\r
176 WebResponse response = base.GetWebResponse (request, result);
\r
177 HttpWebResponse wr = response as HttpWebResponse;
\r
179 CheckForCookies (wr);
\r
187 protected void CancelAsync (object userState)
\r
189 throw new NotImplementedException ();
\r
193 public static bool GenerateXmlMappings (Type type, ArrayList mapping)
\r
195 throw new NotImplementedException ();
\r
199 public static Hashtable GenerateXmlMappings (Type[] types, ArrayList mapping)
\r
201 throw new NotImplementedException ();
\r
205 #endregion // Methods
\r
209 internal class InvokeAsyncInfo
\r
211 public SynchronizationContext Context;
\r
212 public object UserState;
\r
213 public SendOrPostCallback Callback;
\r
215 public InvokeAsyncInfo (SendOrPostCallback callback, object userState)
\r
217 Callback = callback;
\r
218 UserState = userState;
\r
219 Context = SynchronizationContext.Current;
\r