473,466 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

No return from async web service call

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
5 3236
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Drew Stoddard | last post by:
We are working in C#/Winforms and are using asynchronous client-side web service calls (the Begin... and End... methods supplied by the web reference creation). Many of these calls are contained...
1
by: DBC User | last post by:
Hi Sharpies, I have developed a asyncrnous web service client. Everything is working fine. Except folloing 2 things 1. Is it possible to force timeout on an async call? 2. Is it possible to...
1
by: Simon Hart | last post by:
Hi, I thought I'd just open a thread in an attempt to get peoples feelers with regards to multithreading vs Async Web Service processing. Of course Web Services makes it easy to do Async...
0
by: whizpop | last post by:
Hi, First of all, thanks for a great starter kit, now If I could just get it to work (fully). I am trying to compile and run the solution/services all on a local dev box. I am able to...
10
by: Brian Parker | last post by:
I inherited a C++ DLL that I need to remotely call multiple times asynchronously. What I have developed is: CSharp web application that makes asynchronous calls to a CSharp Web Service. The...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
0
by: screen.one | last post by:
Hi (Framework 1.1, Webservice platform Windows 2003 Server) I have a little windows service which is supposed to call one or more webservices at regular intervals. Recently this service has...
5
by: =?Utf-8?B?U3RlZmFuIEZpbGlw?= | last post by:
Hello, I'm trying to launch several async calls for different methods of a web service, but I get this error when i'm trying to read the result (There was an error during asynchronous...
0
markmcgookin
by: markmcgookin | last post by:
Hi, I have a web service that I call from a winforms application. This web service can be cancelled, or completed,and then will call back the win forms application with a response (i.e. e.Complete...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.