public class SoapHttpClientProtocol : HttpWebClientProtocol {\r
SoapTypeStubInfo type_info;\r
\r
- #region AsyncInfo class\r
+ #region SoapWebClientAsyncResult class\r
\r
- internal class AsyncInfo: IAsyncResult\r
+ internal class SoapWebClientAsyncResult: WebClientAsyncResult\r
{\r
- bool _completedSynchronously;\r
- bool _done;\r
- ManualResetEvent _waitHandle;\r
-\r
- public object AsyncState \r
+ public SoapWebClientAsyncResult (WebRequest request, AsyncCallback callback, object asyncState)\r
+ : base (request, callback, asyncState)\r
{\r
- get { return InternalAsyncState; }\r
}\r
-\r
- public WaitHandle AsyncWaitHandle \r
- {\r
- get\r
- {\r
- lock (this) {\r
- if (_waitHandle != null) return _waitHandle;\r
- _waitHandle = new ManualResetEvent (_done);\r
- return _waitHandle;\r
- }\r
- }\r
- }\r
-\r
- public bool CompletedSynchronously \r
- {\r
- get { return _completedSynchronously; }\r
- }\r
-\r
- public bool IsCompleted \r
- {\r
- get { lock (this) { return _done; } }\r
- }\r
-\r
- internal void SetCompleted (object[] result, Exception exception, bool async)\r
- {\r
- lock (this)\r
- {\r
- Exception = exception;\r
- Result = result;\r
- _done = true;\r
- _completedSynchronously = async;\r
- if (_waitHandle != null) _waitHandle.Set ();\r
- Monitor.PulseAll (this);\r
- }\r
- if (Callback != null) Callback (this);\r
- }\r
-\r
- internal void WaitForComplete ()\r
- {\r
- lock (this)\r
- {\r
- Monitor.Wait (this);\r
- }\r
- }\r
-\r
- internal object InternalAsyncState;\r
- internal AsyncCallback Callback;\r
- internal SoapClientMessage Message;\r
- internal SoapExtension[] Extensions;\r
- internal WebRequest Request;\r
- internal object[] Result;\r
- internal Exception Exception;\r
+ \r
+ public SoapClientMessage Message;\r
+ public SoapExtension[] Extensions;\r
}\r
#endregion\r
\r
\r
protected IAsyncResult BeginInvoke (string methodName, object[] parameters, AsyncCallback callback, object asyncState)\r
{\r
- AsyncInfo ainfo = new AsyncInfo ();\r
-\r
SoapMethodStubInfo msi = (SoapMethodStubInfo) type_info.GetMethod (methodName);\r
- ainfo.Message = new SoapClientMessage (this, msi, Url, parameters);\r
- ainfo.Message.CollectHeaders (this, ainfo.Message.MethodStubInfo.Headers, SoapHeaderDirection.In);\r
- ainfo.Extensions = SoapExtension.CreateExtensionChain (type_info.SoapExtensions[0], msi.SoapExtensions, type_info.SoapExtensions[1]);\r
- ainfo.InternalAsyncState = asyncState;\r
- ainfo.Callback = callback;\r
\r
+ SoapWebClientAsyncResult ainfo = null;\r
try\r
{\r
- ainfo.Request = GetRequestForMessage (uri, ainfo.Message);\r
+ SoapClientMessage message = new SoapClientMessage (this, msi, Url, parameters);\r
+ message.CollectHeaders (this, message.MethodStubInfo.Headers, SoapHeaderDirection.In);\r
+ \r
+ WebRequest request = GetRequestForMessage (uri, message);\r
+ \r
+ ainfo = new SoapWebClientAsyncResult (request, callback, asyncState);\r
+ ainfo.Message = message;\r
+ ainfo.Extensions = SoapExtension.CreateExtensionChain (type_info.SoapExtensions[0], msi.SoapExtensions, type_info.SoapExtensions[1]);\r
+\r
ainfo.Request.BeginGetRequestStream (new AsyncCallback (AsyncGetRequestStreamDone), ainfo);\r
}\r
catch (Exception ex)\r
{\r
- ainfo.SetCompleted (null, ex, false);\r
+ if (ainfo != null)\r
+ ainfo.SetCompleted (null, ex, false);\r
}\r
\r
return ainfo;\r
\r
void AsyncGetRequestStreamDone (IAsyncResult ar)\r
{\r
- AsyncInfo ainfo = (AsyncInfo) ar.AsyncState;\r
+ SoapWebClientAsyncResult ainfo = (SoapWebClientAsyncResult) ar.AsyncState;\r
try\r
{\r
SendRequest (ainfo.Request.EndGetRequestStream (ar), ainfo.Message, ainfo.Extensions);\r
-\r
ainfo.Request.BeginGetResponse (new AsyncCallback (AsyncGetResponseDone), ainfo);\r
}\r
catch (Exception ex)\r
{\r
+ Console.WriteLine ("E1:" + ex);\r
ainfo.SetCompleted (null, ex, true);\r
}\r
}\r
\r
void AsyncGetResponseDone (IAsyncResult ar)\r
{\r
- AsyncInfo ainfo = (AsyncInfo) ar.AsyncState;\r
+ SoapWebClientAsyncResult ainfo = (SoapWebClientAsyncResult) ar.AsyncState;\r
WebResponse response = null;\r
\r
try {\r
response = GetWebResponse (ainfo.Request, ar);\r
}\r
catch (WebException ex) {\r
+ Console.WriteLine ("E2:" + ex);\r
response = ex.Response;\r
HttpWebResponse http_response = response as HttpWebResponse;\r
if (http_response == null || http_response.StatusCode != HttpStatusCode.InternalServerError) {\r
\r
protected object[] EndInvoke (IAsyncResult asyncResult)\r
{\r
- if (!(asyncResult is AsyncInfo)) throw new ArgumentException ("asyncResult is not the return value from BeginInvoke");\r
+ if (!(asyncResult is SoapWebClientAsyncResult)) throw new ArgumentException ("asyncResult is not the return value from BeginInvoke");\r
\r
- AsyncInfo ainfo = (AsyncInfo) asyncResult;\r
+ SoapWebClientAsyncResult ainfo = (SoapWebClientAsyncResult) asyncResult;\r
lock (ainfo)\r
{\r
if (!ainfo.IsCompleted) ainfo.WaitForComplete ();\r
if (ainfo.Exception != null) throw ainfo.Exception;\r
- else return ainfo.Result;\r
+ else return (object[]) ainfo.Result;\r
}\r
}\r
\r