Browse Source

* HttpSimpleClientProtocol.cs, HttpWebClientProtocol.cs,
SoapHttpClientProtocol.cs: Implemented support for the new async model.
* InvokeCompletedEventArgs.cs: Implemented.

svn path=/trunk/mcs/; revision=31538

Lluis Sanchez 21 years ago
parent
commit
08f98cbb46

+ 6 - 0
mcs/class/System.Web.Services/System.Web.Services.Protocols/ChangeLog

@@ -1,3 +1,9 @@
+2004-07-27  Lluis Sanchez Gual  <[email protected]>
+
+	* HttpSimpleClientProtocol.cs, HttpWebClientProtocol.cs, 
+	  SoapHttpClientProtocol.cs: Implemented support for the new async model.
+	* InvokeCompletedEventArgs.cs: Implemented.
+
 2004-07-20  Lluis Sanchez Gual  <[email protected]>
 
 	* HttpWebClientProtocol.cs: Add received cookies to cookieContainer when

+ 13 - 4
mcs/class/System.Web.Services/System.Web.Services.Protocols/HttpSimpleClientProtocol.cs

@@ -174,18 +174,27 @@ namespace System.Web.Services.Protocols {
 		
 #if NET_2_0
 
-		[MonoTODO]
 		protected void InvokeAsync (string methodName, string requestUrl, object[] parameters, SendOrPostCallback callback)
 		{
-			throw new NotImplementedException ();
+			InvokeAsync (methodName, requestUrl, parameters, callback, null);
 		}
 
-		[MonoTODO]
 		protected void InvokeAsync (string methodName, string requestUrl, object[] parameters, SendOrPostCallback callback, object userState)
 		{
-			throw new NotImplementedException ();
+			InvokeAsyncInfo info = new InvokeAsyncInfo (callback, userState);
+			BeginInvoke (methodName, requestUrl, parameters, new AsyncCallback (InvokeAsyncCallback), info);
 		}
 
+		void InvokeAsyncCallback (IAsyncResult ar)
+		{
+			InvokeAsyncInfo info = (InvokeAsyncInfo) ar.AsyncState;
+			SimpleWebClientAsyncResult sar = (SimpleWebClientAsyncResult) ar;
+			InvokeCompletedEventArgs args = new InvokeCompletedEventArgs (sar.Exception, false, info.UserState, (object[]) sar.Result);
+			if (info.Context != null)
+				info.Context.SendOrPost (info.Callback, args);
+			else
+				info.Callback (args);
+		}
 #endif
 		
 		#endregion // Methods

+ 16 - 0
mcs/class/System.Web.Services/System.Web.Services.Protocols/HttpWebClientProtocol.cs

@@ -204,4 +204,20 @@ namespace System.Web.Services.Protocols {
 
 		#endregion // Methods
 	}
+	
+#if NET_2_0
+	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;
+		}
+	}
+#endif
 }

+ 3 - 4
mcs/class/System.Web.Services/System.Web.Services.Protocols/InvokeCompletedEventArgs.cs

@@ -34,20 +34,19 @@ using System.ComponentModel;
 
 namespace System.Web.Services.Protocols 
 {
-	[MonoTODO]
 	public class InvokeCompletedEventArgs : AsyncCompletedEventArgs
 	{
 		object[] _results;
 		
-		internal InvokeCompletedEventArgs ()
-		: base (null, false, null)
+		internal InvokeCompletedEventArgs (Exception error, bool cancelled, object userState, object[] results)
+		: base (error, cancelled, userState)
 		{
+			_results = results;
 		}
 		
 		public object[] Results {
 			get { return _results; }
 		}
-
 	}
 }
 

+ 15 - 4
mcs/class/System.Web.Services/System.Web.Services.Protocols/SoapHttpClientProtocol.cs

@@ -344,16 +344,26 @@ namespace System.Web.Services.Protocols
 			set { soapVersion = value; }
 		}
 		
-		[MonoTODO]
 		protected void InvokeAsync (string methodName, object[] parameters, SendOrPostCallback callback)
 		{
-			throw new NotImplementedException ();
+			InvokeAsync (methodName, parameters, callback, null);
 		}
 
-		[MonoTODO]
 		protected void InvokeAsync (string methodName, object[] parameters, SendOrPostCallback callback, object userState)
 		{
-			throw new NotImplementedException ();
+			InvokeAsyncInfo info = new InvokeAsyncInfo (callback, userState);
+			BeginInvoke (methodName, parameters, new AsyncCallback (InvokeAsyncCallback), info);
+		}
+		
+		void InvokeAsyncCallback (IAsyncResult ar)
+		{
+			InvokeAsyncInfo info = (InvokeAsyncInfo) ar.AsyncState;
+			SoapWebClientAsyncResult sar = (SoapWebClientAsyncResult) ar;
+			InvokeCompletedEventArgs args = new InvokeCompletedEventArgs (sar.Exception, false, info.UserState, (object[]) sar.Result);
+			if (info.Context != null)
+				info.Context.SendOrPost (info.Callback, args);
+			else
+				info.Callback (args);
 		}
 
 #endif
@@ -361,3 +371,4 @@ namespace System.Web.Services.Protocols
 		#endregion // Methods
 	}
 }
+