Re: No return from async web service call

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang2052\f0\fs20 Hi Paul,
\par
\par Any further progress on this issue or does the suggestions in my former messages helps a little? If there're any thing else we can help, please feel free to post here.
\par
\par Thanks & Regards,
\par
\par Steven Cheng
\par Microsoft Online Support
\par
\par Get Secure! www.microsoft.com/security
\par (This posting is provided "AS IS", with no warranties, and confers no rights.)
\par \pard\li720 --------------------
\par X-Tomcat-ID: 160077421
\par References: <8BD9AD06-E6D9-4D1D-8565-1BF1CB0527F1@xxxxxxxxxxxxx> <1126903555.326591.302910@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> <D72AF3D8-F2EB-4072-8145-AC9871709AE0@xxxxxxxxxxxxx>
\par MIME-Version: 1.0
\par Content-Type: multipart/alternative; boundary="----=_NextPart_0001_D359132B"
\par Content-Transfer-Encoding: 7bit
\par From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
\par Organization: Microsoft
\par Date: Tue, 20 Sep 2005 09:24:16 GMT
\par Subject: Re: No return from async web service call
\par X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
\par Message-ID: <LROSWUcvFHA.768@xxxxxxxxxxxxxxxxxxxxx>
\par Newsgroups: microsoft.public.dotnet.framework.webservices
\par Lines: 333
\par Path: TK2MSFTNGXA01.phx.gbl
\par Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.framework.webservices:7949
\par NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
\par
\par Hi Paul,
\par
\par Have you tried only using the CallBack handler, generally this is the most recommend means in desktop applicaiton since it won't block your main UI thread. Also, have you tried testing through a simple webmethod which will take long time to run? Based on my local test, I can correctly get both
\par
\par while(!ar.IsCompleted)
\par \{
\par \tab pbTime.Increment(5);
\par \tab System.Threading.Thread.Sleep(1000);
\par \tab\tab\tab\tab
\par \}
\par
\par or using Callback handler means to work correctly. The only problem is that when using while loop to poll the Complete status, the main UI thread will be blocked from accepting other UI message gracefully.
\par Also, I've noticed that you're wanting to update the processbar constatly during the long run webmethod processing, if so, I'm afraid CallBack hander won't quite meet your requirement. Thus, spawn a new work thread to do the work will be the best choice (if you won't spawn lots of such thread since spawning a new thread is much more expensive than utilize threadpool thread...). The code will be something like:
\par
\par ==================
\par private void btnCall_Click(object sender, System.EventArgs e)
\par \{\tab
\par \tab System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(CallWS_Proc));
\par \tab thread.Start();
\par \}
\par
\par
\par private void CallWS_Proc()
\par \{
\par \tab DocService.DocService ds = new WSClient.DocService.DocService();
\par \tab ds.Credentials = System.Net.CredentialCache.DefaultCredentials;
\par
\par \tab IAsyncResult ar = ds.BeginDummyUpload(null,null, ds);
\par
\par \tab while(!ar.IsCompleted)
\par \tab\{
\par //call function to update the UI
\par
\par \tab\tab pbTime.Increment(5);
\par \tab\tab System.Threading.Thread.Sleep(1000);
\par \tab\tab\tab\tab
\par \tab\}
\par
\par \tab string ret = ds.EndDummyUpload(ar);
\par \}
\par
\par
\par If there're anything else we can help, please feel free to post here. Thanks,
\par
\par Steven Cheng
\par Microsoft Online Support
\par
\par Get Secure! www.microsoft.com/security
\par (This posting is provided "AS IS", with no warranties, and confers no rights.)
\par \pard\li1440 --------------------
\par Thread-Topic: No return from async web service call
\par thread-index: AcW89ZW8tjUj7CXhR5y2bwnyuA6mlQ==
\par X-WBNR-Posting-Host: 62.6.144.66
\par From: "=?Utf-8?B?UGF1bCBIYXNlbGw=?=" <paul_hasell@xxxxxxxxxxxxxxxx>
\par References: <8BD9AD06-E6D9-4D1D-8565-1BF1CB0527F1@xxxxxxxxxxxxx> <1126903555.326591.302910@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
\par Subject: Re: No return from async web service call
\par Date: Mon, 19 Sep 2005 01:39:01 -0700
\par Lines: 80
\par Message-ID: <D72AF3D8-F2EB-4072-8145-AC9871709AE0@xxxxxxxxxxxxx>
\par MIME-Version: 1.0
\par Content-Type: text/plain;
\par \tab charset="Utf-8"
\par Content-Transfer-Encoding: 7bit
\par X-Newsreader: Microsoft CDO for Windows 2000
\par Content-Class: urn:content-classes:message
\par Importance: normal
\par Priority: normal
\par X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
\par Newsgroups: microsoft.public.dotnet.framework.webservices
\par NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
\par Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
\par Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.framework.webservices:7932
\par X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
\par
\par Peter,
\par
\par Thanks, that would explain a lot. The idea of the infinite loop is to try
\par and fake an upload progress bar so the user doesn't think it's frozen if the
\par upload takes a while (our users can get very twitchy). I had tried using just
\par the IsCompleted without a callback but that didn't seem to be getting set
\par either!? I may have to to cheat and use a synchronous call on the main thread
\par and spin the progress bar onto another thread instead, not elegant but at
\par least functional.
\par
\par "Peter K" wrote:
\par
\par > Hi Paul,
\par >
\par > I have to admit that my thread knowledge has gotten pretty rusty, but
\par > I think that even though your webservice will run on new thread, the
\par > thread your callback will run on is the same thread that your
\par > btnUpload_click method will be running on. Therefore UploadHandler
\par > won't be able to run until btnUpload_click method has completed. Since
\par > you have infinite loop running in there, UploadHandler will just keep
\par > waiting and won't fire.
\par >
\par > I managed to replicate the same behaviour you are experiencing using a
\par > continual while loop. When I removed the while loop, your code worked
\par > fine.
\par >
\par > Hope that helps
\par >
\par > Peter Kelcey
\par >
\par > Paul Hasell wrote:
\par > > Hi,
\par > >
\par > > I'm trying to invoke a web method asynchronously but just can't seem to get
\par > > it to tell me when it has finished! Below is the code I am (currently) using:
\par > >
\par > > private void btnUpload_Click(object sender, System.EventArgs e)
\par > > \{
\par > > try
\par > > \{
\par > > SOPWebService.Client uploader = new
\par > > GLTUpload.SOPWebService.Client();
\par > > uploader.Credentials =
\par > > System.Net.CredentialCache.DefaultCredentials;
\par > >
\par > > IAsyncResult async_upload =
\par > > uploader.BeginUploadDirect(txtKeyAccountTeam.SelectedValue.ToString(),
\par > > _xml_content, new AsyncCallback(UploadHandler), uploader);
\par > >
\par > > while(!async_upload.IsCompleted)
\par > > \{
\par > > Thread.Sleep(1000);
\par > > Progress.Increment(1);
\par > > \}
\par > > \}
\par > > catch(Exception ex)
\par > > \{
\par > > MessageBox.Show(ex.ToString(), Application.ProductName,
\par > > MessageBoxButtons.OK, MessageBoxIcon.Error);
\par > > \}
\par > > finally
\par > > \{
\par > > Close();
\par > > \}
\par > > \}
\par > >
\par > > private void UploadHandler(IAsyncResult async_result)
\par > > \{
\par > > SOPWebService.Client sop_web_client = (SOPWebService.Client)
\par > > async_result.AsyncState;
\par > > sop_web_client.EndUploadDirect(async_result);
\par > > \}
\par > >
\par > > The problem is that although the web method is invoked, executes and ends
\par > > the callback never gets fired and the IAsyncResult never has it's IsCompleted
\par > > set to true.
\par > >
\par > > Anyone know what I'm missing?
\par >
\par >
\par \pard\li720
\par
\par \pard
\par
\par }

















Relevant Pages

  • Re: Add XmlNode
    ... You're welcome Paul. ... Steven Cheng ... Microsoft Online Support ... |> long as the Namespace URI is the same between multiple documents. ...
    (microsoft.public.dotnet.xml)
  • Re: Form OnKeypress event not firing while test loop running
    ... Paul E. Schoen wrote: ... Once this happens the display shows the running time and current value, and this may be repeated until a certain number of pulses occur, or a preset timeout is reached. ... The data analysis is accomplished in a rather large loop which fires on a 200 mSec timer event, and it processes about 480 integer data values. ... ESC key for example, then while your in that loop, you can test for that value incase the user wants to terminate the current function.. ...
    (comp.lang.pascal.delphi.misc)
  • Re: ldap configuration with IBM iSeries working with outlook 2003
    ... 60From: "Paul Fistler" ... 60>> The error message I get when I try to use the ldap server is "Control ... 60>>> Terry Liu ... 60>>> Microsoft Online Support Engineer ...
    (microsoft.public.outlook.general)
  • Re: Timer not working in WinCE Service
    ... Create a loop with a Sleep of WaitForSingleObject call like Paul ... void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime) ... the clients that the timer has fired. ...
    (microsoft.public.windowsce.embedded)
  • Re: Composite Control and accessing complex properties of child controls - C# VS2005
    ... Glad to hear from you Paul, ... Steven Cheng ... Microsoft Online Support ... | Subject: Re: Composite Control and accessing complex properties of child ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)