By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,884 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,884 IT Pros & Developers. It's quick & easy.

No return from async web service call

P: n/a
Hi,

I'm trying to invoke a web method asynchronously but just can't seem to get
it to tell me when it has finished! Below is the code I am (currently) using:

private void btnUpload_Click(object sender, System.EventArgs e)
{
try
{
SOPWebService.Client uploader = new
GLTUpload.SOPWebService.Client();
uploader.Credentials =
System.Net.CredentialCache.DefaultCredentials;

IAsyncResult async_upload =
uploader.BeginUploadDirect(txtKeyAccountTeam.Selec tedValue.ToString(),
_xml_content, new AsyncCallback(UploadHandler), uploader);

while(!async_upload.IsCompleted)
{
Thread.Sleep(1000);
Progress.Increment(1);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), Application.ProductName,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Close();
}
}

private void UploadHandler(IAsyncResult async_result)
{
SOPWebService.Client sop_web_client = (SOPWebService.Client)
async_result.AsyncState;
sop_web_client.EndUploadDirect(async_result);
}

The problem is that although the web method is invoked, executes and ends
the callback never gets fired and the IAsyncResult never has it's IsCompleted
set to true.

Anyone know what I'm missing?
Nov 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Paul,

I have to admit that my thread knowledge has gotten pretty rusty, but
I think that even though your webservice will run on new thread, the
thread your callback will run on is the same thread that your
btnUpload_click method will be running on. Therefore UploadHandler
won't be able to run until btnUpload_click method has completed. Since
you have infinite loop running in there, UploadHandler will just keep
waiting and won't fire.

I managed to replicate the same behaviour you are experiencing using a
continual while loop. When I removed the while loop, your code worked
fine.

Hope that helps

Peter Kelcey

Paul Hasell wrote:
Hi,

I'm trying to invoke a web method asynchronously but just can't seem to get
it to tell me when it has finished! Below is the code I am (currently) using:

private void btnUpload_Click(object sender, System.EventArgs e)
{
try
{
SOPWebService.Client uploader = new
GLTUpload.SOPWebService.Client();
uploader.Credentials =
System.Net.CredentialCache.DefaultCredentials;

IAsyncResult async_upload =
uploader.BeginUploadDirect(txtKeyAccountTeam.Selec tedValue.ToString(),
_xml_content, new AsyncCallback(UploadHandler), uploader);

while(!async_upload.IsCompleted)
{
Thread.Sleep(1000);
Progress.Increment(1);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), Application.ProductName,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Close();
}
}

private void UploadHandler(IAsyncResult async_result)
{
SOPWebService.Client sop_web_client = (SOPWebService.Client)
async_result.AsyncState;
sop_web_client.EndUploadDirect(async_result);
}

The problem is that although the web method is invoked, executes and ends
the callback never gets fired and the IAsyncResult never has it's IsCompleted
set to true.

Anyone know what I'm missing?


Nov 23 '05 #2

P: n/a
Hi Paul,

As for the asynchornous webmethod invoking, it's just a normal .NET async
delegate invoking. We just need to use one of the three calling models:

1.Waiting for an Asynchronous Call with WaitHandle

2.Polling for Asynchronous Call Completion

3.Executing a Callback Method When an Asynchronous Call Completes

they're also described in the following msdn reference:

#Asynchronous Programming Overview
http://msdn.microsoft.com/library/en...chronousprogra
mmingoverview.asp?frame=true

So please do not use multiple of them in your application code. Especially
when your main executing thread is a UI thread. For example, you can just
use async callback only to see whether the callback get executed (not use
the while loop in main thread).

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
Thread-Topic: No return from async web service call
thread-index: AcW6yHij0He2mq2dRSuZ4tgZF3IK4w==
X-WBNR-Posting-Host: 62.6.144.66
From: "=?Utf-8?B?UGF1bCBIYXNlbGw=?=" <pa*********@community.nospam>
Subject: No return from async web service call
Date: Fri, 16 Sep 2005 07:11:03 -0700
Lines: 47
Message-ID: <8B**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
microsoft.public.dotnet.framework.webservices:7917
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Hi,

I'm trying to invoke a web method asynchronously but just can't seem to get
it to tell me when it has finished! Below is the code I am (currently)
using:

private void btnUpload_Click(object sender, System.EventArgs e)
{
try
{
SOPWebService.Client uploader = new
GLTUpload.SOPWebService.Client();
uploader.Credentials =
System.Net.CredentialCache.DefaultCredentials;

IAsyncResult async_upload =
uploader.BeginUploadDirect(txtKeyAccountTeam.Selec tedValue.ToString(),
_xml_content, new AsyncCallback(UploadHandler), uploader);

while(!async_upload.IsCompleted)
{
Thread.Sleep(1000);
Progress.Increment(1);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), Application.ProductName,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Close();
}
}

private void UploadHandler(IAsyncResult async_result)
{
SOPWebService.Client sop_web_client = (SOPWebService.Client)
async_result.AsyncState;
sop_web_client.EndUploadDirect(async_result);
}

The problem is that although the web method is invoked, executes and ends
the callback never gets fired and the IAsyncResult never has it's
IsCompleted
set to true.

Anyone know what I'm missing?

Nov 23 '05 #3

P: n/a
Peter,

Thanks, that would explain a lot. The idea of the infinite loop is to try
and fake an upload progress bar so the user doesn't think it's frozen if the
upload takes a while (our users can get very twitchy). I had tried using just
the IsCompleted without a callback but that didn't seem to be getting set
either!? I may have to to cheat and use a synchronous call on the main thread
and spin the progress bar onto another thread instead, not elegant but at
least functional.

"Peter K" wrote:
Hi Paul,

I have to admit that my thread knowledge has gotten pretty rusty, but
I think that even though your webservice will run on new thread, the
thread your callback will run on is the same thread that your
btnUpload_click method will be running on. Therefore UploadHandler
won't be able to run until btnUpload_click method has completed. Since
you have infinite loop running in there, UploadHandler will just keep
waiting and won't fire.

I managed to replicate the same behaviour you are experiencing using a
continual while loop. When I removed the while loop, your code worked
fine.

Hope that helps

Peter Kelcey

Paul Hasell wrote:
Hi,

I'm trying to invoke a web method asynchronously but just can't seem to get
it to tell me when it has finished! Below is the code I am (currently) using:

private void btnUpload_Click(object sender, System.EventArgs e)
{
try
{
SOPWebService.Client uploader = new
GLTUpload.SOPWebService.Client();
uploader.Credentials =
System.Net.CredentialCache.DefaultCredentials;

IAsyncResult async_upload =
uploader.BeginUploadDirect(txtKeyAccountTeam.Selec tedValue.ToString(),
_xml_content, new AsyncCallback(UploadHandler), uploader);

while(!async_upload.IsCompleted)
{
Thread.Sleep(1000);
Progress.Increment(1);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), Application.ProductName,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Close();
}
}

private void UploadHandler(IAsyncResult async_result)
{
SOPWebService.Client sop_web_client = (SOPWebService.Client)
async_result.AsyncState;
sop_web_client.EndUploadDirect(async_result);
}

The problem is that although the web method is invoked, executes and ends
the callback never gets fired and the IAsyncResult never has it's IsCompleted
set to true.

Anyone know what I'm missing?


Nov 23 '05 #4

P: n/a
Hi Paul,

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

while(!ar.IsCompleted)
{
pbTime.Increment(5);
System.Threading.Thread.Sleep(1000);

}

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.
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:

==================
private void btnCall_Click(object sender, System.EventArgs e)
{
System.Threading.Thread thread = new System.Threading.Thread(new
System.Threading.ThreadStart(CallWS_Proc));
thread.Start();
}
private void CallWS_Proc()
{
DocService.DocService ds = new WSClient.DocService.DocService();
ds.Credentials = System.Net.CredentialCache.DefaultCredentials;

IAsyncResult ar = ds.BeginDummyUpload(null,null, ds);

while(!ar.IsCompleted)
{
//call function to update the UI

pbTime.Increment(5);
System.Threading.Thread.Sleep(1000);

}

string ret = ds.EndDummyUpload(ar);
}
If there're anything else we can help, please feel free to post here.
Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
Thread-Topic: No return from async web service call
thread-index: AcW89ZW8tjUj7CXhR5y2bwnyuA6mlQ==
X-WBNR-Posting-Host: 62.6.144.66
From: "=?Utf-8?B?UGF1bCBIYXNlbGw=?=" <pa*********@community.nospam>
References: <8B**********************************@microsoft.co m>
<11**********************@o13g2000cwo.googlegroups .com>
Subject: Re: No return from async web service call
Date: Mon, 19 Sep 2005 01:39:01 -0700
Lines: 80
Message-ID: <D7**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
microsoft.public.dotnet.framework.webservices:7932
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Peter,

Thanks, that would explain a lot. The idea of the infinite loop is to try
and fake an upload progress bar so the user doesn't think it's frozen if
the
upload takes a while (our users can get very twitchy). I had tried using
just
the IsCompleted without a callback but that didn't seem to be getting set
either!? I may have to to cheat and use a synchronous call on the main
thread
and spin the progress bar onto another thread instead, not elegant but at
least functional.

"Peter K" wrote:
Hi Paul,

I have to admit that my thread knowledge has gotten pretty rusty, but
I think that even though your webservice will run on new thread, the
thread your callback will run on is the same thread that your
btnUpload_click method will be running on. Therefore UploadHandler
won't be able to run until btnUpload_click method has completed. Since
you have infinite loop running in there, UploadHandler will just keep
waiting and won't fire.

I managed to replicate the same behaviour you are experiencing using a
continual while loop. When I removed the while loop, your code worked
fine.

Hope that helps

Peter Kelcey

Paul Hasell wrote:
Hi,

I'm trying to invoke a web method asynchronously but just can't seem to get it to tell me when it has finished! Below is the code I am (currently) using:
private void btnUpload_Click(object sender, System.EventArgs e)
{
try
{
SOPWebService.Client uploader = new
GLTUpload.SOPWebService.Client();
uploader.Credentials =
System.Net.CredentialCache.DefaultCredentials;

IAsyncResult async_upload =
uploader.BeginUploadDirect(txtKeyAccountTeam.Selec tedValue.ToString(),
_xml_content, new AsyncCallback(UploadHandler), uploader);

while(!async_upload.IsCompleted)
{
Thread.Sleep(1000);
Progress.Increment(1);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), Application.ProductName,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Close();
}
}

private void UploadHandler(IAsyncResult async_result)
{
SOPWebService.Client sop_web_client = (SOPWebService.Client)
async_result.AsyncState;
sop_web_client.EndUploadDirect(async_result);
}

The problem is that although the web method is invoked, executes and ends the callback never gets fired and the IAsyncResult never has it's IsCompleted set to true.

Anyone know what I'm missing?



Nov 23 '05 #5

P: n/a
Hi Paul,

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.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
X-Tomcat-ID: 160077421
References: <8B**********************************@microsoft.co m>
<11**********************@o13g2000cwo.googlegroups .com>
<D7**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----=_NextPart_0001_D359132B"
Content-Transfer-Encoding: 7bit
From: st*****@online.microsoft.com (Steven Cheng[MSFT])
Organization: Microsoft
Date: Tue, 20 Sep 2005 09:24:16 GMT
Subject: Re: No return from async web service call
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
Message-ID: <LR*************@TK2MSFTNGXA01.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.webservices
Lines: 333
Path: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.webservices:7949
NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182

Hi Paul,

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

while(!ar.IsCompleted)
{
pbTime.Increment(5);
System.Threading.Thread.Sleep(1000);

}

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.
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:

==================
private void btnCall_Click(object sender, System.EventArgs e)
{
System.Threading.Thread thread = new System.Threading.Thread(new
System.Threading.ThreadStart(CallWS_Proc));
thread.Start();
}
private void CallWS_Proc()
{
DocService.DocService ds = new WSClient.DocService.DocService();
ds.Credentials = System.Net.CredentialCache.DefaultCredentials;

IAsyncResult ar = ds.BeginDummyUpload(null,null, ds);

while(!ar.IsCompleted)
{
//call function to update the UI

pbTime.Increment(5);
System.Threading.Thread.Sleep(1000);

}

string ret = ds.EndDummyUpload(ar);
}
If there're anything else we can help, please feel free to post here.
Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
Thread-Topic: No return from async web service call
thread-index: AcW89ZW8tjUj7CXhR5y2bwnyuA6mlQ==
X-WBNR-Posting-Host: 62.6.144.66
From: "=?Utf-8?B?UGF1bCBIYXNlbGw=?=" <pa*********@community.nospam>
References: <8B**********************************@microsoft.co m>
<11**********************@o13g2000cwo.googlegroups .com>
Subject: Re: No return from async web service call
Date: Mon, 19 Sep 2005 01:39:01 -0700
Lines: 80
Message-ID: <D7**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
microsoft.public.dotnet.framework.webservices:7932
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Peter,

Thanks, that would explain a lot. The idea of the infinite loop is to try
and fake an upload progress bar so the user doesn't think it's frozen if
the
upload takes a while (our users can get very twitchy). I had tried using
just
the IsCompleted without a callback but that didn't seem to be getting set
either!? I may have to to cheat and use a synchronous call on the main
thread
and spin the progress bar onto another thread instead, not elegant but at
least functional.

"Peter K" wrote:
Hi Paul,

I have to admit that my thread knowledge has gotten pretty rusty, but
I think that even though your webservice will run on new thread, the
thread your callback will run on is the same thread that your
btnUpload_click method will be running on. Therefore UploadHandler
won't be able to run until btnUpload_click method has completed. Since
you have infinite loop running in there, UploadHandler will just keep
waiting and won't fire.

I managed to replicate the same behaviour you are experiencing using a
continual while loop. When I removed the while loop, your code worked
fine.

Hope that helps

Peter Kelcey

Paul Hasell wrote:
Hi,

I'm trying to invoke a web method asynchronously but just can't seem to get it to tell me when it has finished! Below is the code I am (currently) using:
private void btnUpload_Click(object sender, System.EventArgs e)
{
try
{
SOPWebService.Client uploader = new
GLTUpload.SOPWebService.Client();
uploader.Credentials =
System.Net.CredentialCache.DefaultCredentials;

IAsyncResult async_upload =
uploader.BeginUploadDirect(txtKeyAccountTeam.Selec tedValue.ToString(),
_xml_content, new AsyncCallback(UploadHandler), uploader);

while(!async_upload.IsCompleted)
{
Thread.Sleep(1000);
Progress.Increment(1);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), Application.ProductName,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Close();
}
}

private void UploadHandler(IAsyncResult async_result)
{
SOPWebService.Client sop_web_client = (SOPWebService.Client)
async_result.AsyncState;
sop_web_client.EndUploadDirect(async_result);
}

The problem is that although the web method is invoked, executes and ends the callback never gets fired and the IAsyncResult never has it's IsCompleted set to true.

Anyone know what I'm missing?



Nov 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.