-// \r
-// System.Web.Services.Protocols.HttpWebClientProtocol.cs\r
-//\r
-// Author:\r
-// Tim Coleman (tim@timcoleman.com)\r
-//\r
-// Copyright (C) Tim Coleman, 2002\r
-//\r
+//
+// System.Web.Services.Protocols.HttpWebClientProtocol.cs
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
//
// Permission is hereby granted, free of charge, to any person obtaining
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-\r
-using System;\r
-using System.ComponentModel;\r
-using System.Net;\r
-using System.Security.Cryptography.X509Certificates;\r
-using System.Threading;\r
-using System.Web.Services;\r
-using System.Collections;\r
-\r
-namespace System.Web.Services.Protocols {\r
- public abstract class HttpWebClientProtocol : WebClientProtocol {\r
-\r
- #region Fields\r
-\r
- bool allowAutoRedirect;\r
- X509CertificateCollection clientCertificates;\r
- CookieContainer cookieContainer;\r
- IWebProxy proxy;\r
- string userAgent;\r
- \r
-#if NET_1_1\r
- bool _unsafeAuthenticated;\r
-#endif\r
- #endregion\r
-\r
- #region Constructors\r
-\r
- protected HttpWebClientProtocol () \r
- {\r
- allowAutoRedirect = false;\r
- clientCertificates = null;\r
- cookieContainer = null;\r
- proxy = null; // FIXME\r
- userAgent = String.Format ("Mono Web Services Client Protocol {0}", Environment.Version);\r
- }\r
- \r
- #endregion // Constructors\r
-\r
- #region Properties\r
-\r
- [DefaultValue (false)]\r
- [WebServicesDescription ("Enable automatic handling of server redirects.")]\r
- public bool AllowAutoRedirect {\r
- get { return allowAutoRedirect; }\r
- set { allowAutoRedirect = value; }\r
- }\r
-\r
- [Browsable (false)]\r
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
- [WebServicesDescription ("The client certificates that will be sent to the server, if the server requests them.")]\r
- public X509CertificateCollection ClientCertificates {\r
- get {\r
- if (clientCertificates == null)\r
- clientCertificates = new X509CertificateCollection ();\r
- return clientCertificates;\r
- }\r
- }\r
-\r
- [DefaultValue (null)]\r
- [WebServicesDescription ("A container for all cookies received from servers in the current session.")]\r
- public CookieContainer CookieContainer {\r
- get { return cookieContainer; }\r
- set { cookieContainer = value; }\r
- }\r
-\r
- [Browsable (false)]\r
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
- public IWebProxy Proxy {\r
- get { return proxy; }\r
- set { proxy = value; }\r
- }\r
-\r
- [WebServicesDescription ("Sets the user agent http header for the request.")]\r
- public string UserAgent {\r
- get { return userAgent; }\r
- set { userAgent = value; }\r
- }\r
- \r
-#if NET_1_1\r
- public bool UnsafeAuthenticatedConnectionSharing\r
- {\r
- get { return _unsafeAuthenticated; }\r
- set { _unsafeAuthenticated = value; }\r
- }\r
-#endif\r
-\r
- #endregion // Properties\r
-\r
- #region Methods\r
-\r
- internal virtual void CheckForCookies (HttpWebResponse response)\r
- {\r
- CookieCollection cookies = response.Cookies;\r
- if (cookieContainer == null || cookies.Count == 0)\r
- return;\r
-\r
- CookieCollection coll = cookieContainer.GetCookies (uri);\r
- foreach (Cookie c in cookies) {\r
- bool add = true;\r
- foreach (Cookie prev in coll) {\r
- if (c.Equals (prev)) {\r
- add = false;\r
- break;\r
- }\r
- }\r
- if (add)\r
- cookieContainer.Add (c);\r
- }\r
- }\r
- \r
- protected override WebRequest GetWebRequest (Uri uri)\r
- {\r
- WebRequest req = base.GetWebRequest (uri);\r
- HttpWebRequest request = req as HttpWebRequest;\r
- if (request == null)\r
- return req;\r
-\r
- request.AllowAutoRedirect = allowAutoRedirect;\r
- if (clientCertificates != null)\r
- request.ClientCertificates.AddRange (clientCertificates);\r
-\r
- request.CookieContainer = cookieContainer;\r
- if (proxy != null)\r
- request.Proxy = proxy;\r
-\r
- request.UserAgent = userAgent;\r
-\r
-#if NET_1_1\r
- // request.UnsafeAuthenticatedConnectionSharing = _unsafeAuthenticated;\r
-#endif\r
-\r
- return request;\r
- }\r
-\r
- protected override WebResponse GetWebResponse (WebRequest request)\r
- {\r
- WebResponse response = base.GetWebResponse (request);\r
- HttpWebResponse wr = response as HttpWebResponse;\r
- if (wr != null)\r
- CheckForCookies (wr);\r
- \r
- return response;\r
- }\r
-\r
- protected override WebResponse GetWebResponse (WebRequest request, IAsyncResult result)\r
- {\r
- WebResponse response = base.GetWebResponse (request, result);\r
- HttpWebResponse wr = response as HttpWebResponse;\r
- if (wr != null)\r
- CheckForCookies (wr);\r
- \r
- return response;\r
- }\r
- \r
-#if NET_2_0\r
-\r
- [MonoTODO]\r
- protected void CancelAsync (object userState)\r
- {\r
- throw new NotImplementedException ();\r
- }\r
-\r
- [MonoTODO]\r
- public static bool GenerateXmlMappings (Type type, ArrayList mapping)\r
- {\r
- throw new NotImplementedException ();\r
- }\r
-\r
- [MonoTODO]\r
- public static Hashtable GenerateXmlMappings (Type[] types, ArrayList mapping)\r
- {\r
- throw new NotImplementedException ();\r
- }\r
-#endif\r
-\r
- #endregion // Methods\r
- }\r
- \r
-#if NET_2_0\r
- internal class InvokeAsyncInfo\r
- {\r
- public SynchronizationContext Context;\r
- public object UserState;\r
- public SendOrPostCallback Callback;\r
- \r
- public InvokeAsyncInfo (SendOrPostCallback callback, object userState)\r
- {\r
- Callback = callback;\r
- UserState = userState;\r
- Context = SynchronizationContext.Current;\r
- }\r
- }\r
-#endif\r
-}\r
+
+using System;
+using System.ComponentModel;
+using System.Net;
+using System.Security.Cryptography.X509Certificates;
+using System.Threading;
+using System.Web.Services;
+using System.Collections;
+
+namespace System.Web.Services.Protocols {
+ [System.Runtime.InteropServices.ComVisible (true)]
+ public abstract class HttpWebClientProtocol : WebClientProtocol {
+
+ #region Fields
+
+ bool allowAutoRedirect, enableDecompression;
+ X509CertificateCollection clientCertificates;
+ CookieContainer cookieContainer;
+ IWebProxy proxy;
+ string userAgent;
+
+ bool _unsafeAuthenticated;
+ #endregion
+
+ #region Constructors
+
+ protected HttpWebClientProtocol ()
+ {
+ allowAutoRedirect = false;
+ clientCertificates = null;
+ cookieContainer = null;
+ proxy = null; // FIXME
+ userAgent = String.Format ("Mono Web Services Client Protocol {0}", Environment.Version);
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ [DefaultValue (false)]
+ [WebServicesDescription ("Enable automatic handling of server redirects.")]
+ public bool AllowAutoRedirect {
+ get { return allowAutoRedirect; }
+ set { allowAutoRedirect = value; }
+ }
+
+ [Browsable (false)]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ [WebServicesDescription ("The client certificates that will be sent to the server, if the server requests them.")]
+ public X509CertificateCollection ClientCertificates {
+ get {
+ if (clientCertificates == null)
+ clientCertificates = new X509CertificateCollection ();
+ return clientCertificates;
+ }
+ }
+
+ [DefaultValue (null)]
+ [WebServicesDescription ("A container for all cookies received from servers in the current session.")]
+ public CookieContainer CookieContainer {
+ get { return cookieContainer; }
+ set { cookieContainer = value; }
+ }
+
+ [DefaultValue (false)]
+ public bool EnableDecompression {
+ get { return enableDecompression; }
+ set { enableDecompression = value; }
+ }
+
+ [Browsable (false)]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ public IWebProxy Proxy {
+ get { return proxy; }
+ set { proxy = value; }
+ }
+
+ [WebServicesDescription ("Sets the user agent http header for the request.")]
+ [Browsable (false)]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ public string UserAgent {
+ get { return userAgent; }
+ set { userAgent = value; }
+ }
+
+ [Browsable (false)]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ public bool UnsafeAuthenticatedConnectionSharing
+ {
+ get { return _unsafeAuthenticated; }
+ set { _unsafeAuthenticated = value; }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ internal virtual void CheckForCookies (HttpWebResponse response)
+ {
+ CookieCollection cookies = response.Cookies;
+ if (cookieContainer == null || cookies.Count == 0)
+ return;
+
+ CookieCollection coll = cookieContainer.GetCookies (uri);
+ foreach (Cookie c in cookies) {
+ bool add = true;
+ foreach (Cookie prev in coll) {
+ if (c.Equals (prev)) {
+ add = false;
+ break;
+ }
+ }
+ if (add)
+ cookieContainer.Add (c);
+ }
+ }
+
+ protected override WebRequest GetWebRequest (Uri uri)
+ {
+ WebRequest req = base.GetWebRequest (uri);
+ HttpWebRequest request = req as HttpWebRequest;
+ if (request == null)
+ return req;
+ if (enableDecompression)
+ request.AutomaticDecompression = DecompressionMethods.GZip;
+
+ request.AllowAutoRedirect = allowAutoRedirect;
+ if (clientCertificates != null)
+ request.ClientCertificates.AddRange (clientCertificates);
+
+ request.CookieContainer = cookieContainer;
+ if (proxy != null)
+ request.Proxy = proxy;
+
+ request.UserAgent = userAgent;
+
+ return request;
+ }
+
+ protected override WebResponse GetWebResponse (WebRequest request)
+ {
+ WebResponse response = base.GetWebResponse (request);
+ HttpWebResponse wr = response as HttpWebResponse;
+ if (wr != null)
+ CheckForCookies (wr);
+
+ return response;
+ }
+
+ protected override WebResponse GetWebResponse (WebRequest request, IAsyncResult result)
+ {
+ WebResponse response = base.GetWebResponse (request, result);
+ HttpWebResponse wr = response as HttpWebResponse;
+ if (wr != null)
+ CheckForCookies (wr);
+
+ return response;
+ }
+
+ Hashtable mappings = new Hashtable ();
+
+ internal void RegisterMapping (object userState, WebClientAsyncResult result)
+ {
+ if (userState == null)
+ userState = typeof (string);
+
+ mappings [userState] = result;
+ }
+
+ internal void UnregisterMapping (object userState)
+ {
+ if (userState == null)
+ userState = typeof (string);
+
+ mappings.Remove (userState);
+ }
+
+ protected void CancelAsync (object userState)
+ {
+ WebClientAsyncResult result = (WebClientAsyncResult) mappings [userState];
+
+ if (result == null)
+ return;
+
+ mappings.Remove (userState);
+ result.Abort ();
+ }
+
+ [MonoTODO]
+ public static bool GenerateXmlMappings (Type type, ArrayList mapping)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public static Hashtable GenerateXmlMappings (Type[] types, ArrayList mapping)
+ {
+ throw new NotImplementedException ();
+ }
+
+ #endregion // Methods
+ }
+
+ internal class InvokeAsyncInfo
+ {
+ public SynchronizationContext Context;
+ public object UserState;
+ public SendOrPostCallback Callback;
+
+ public InvokeAsyncInfo (SendOrPostCallback callback, object userState)
+ {
+ Callback = callback;
+ UserState = userState;
+ Context = SynchronizationContext.Current;
+ }
+ }
+}