473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Webservices and Exceptions

Hi,

Am using VS 2005 C#

I'm calling a webservice Asynchronously on a form used to process a login.
If an exception is thrown from the webservice - if the service was called
synchronously obviously the try catch works. However how do I catch
exceptions when I call it Async? At the moment the exception is getting
moved up to the Parent Form which I dont want. Where can I on my form
capture any exceptions?

Much appreciated for any help

Gary Howlett

try{

LWS.DataService oWS = new LWS.DataService();

oWS.PerformLoginAsync(tUsername.Text, tPassword.Text);

oWS.PerformLoginCompleted += new
Leprechaun.Database.LWS.PerformLoginCompletedEvent Handler(oWS_PerformLoginCompleted);

}

catch (Exception ex){

MessageBox.Show(ex.Message, "Unable to Logon", MessageBoxButtons.OK,
MessageBoxIcon.Stop);

this.DialogResult = DialogResult.Abort;
}


Jul 6 '06 #1
3 1017
In addition the exception sent is..

Exception has been thrown by the target of an invocation.

Gary
Jul 6 '06 #2
I'm not sure what you are calling in terms of method PerformLoginAsync but
you need to be calling the Begin... portion of the method in order to
implement async processing in Web Services.

The exception will be on another thread, the callback thread in this case.
So you need to encapsulate the End... in a try..catch block.

Its good practice to have a try..catch block around the initiating call
Begin..as well.

See here for more information:
http://www.developer.com/net/net/art...1087_3408531_1

"Gary Howlett" <gh@nuclide.co.ukwrote in message
news:44***********************@ptn-nntp-reader01.plus.net...
Hi,

Am using VS 2005 C#

I'm calling a webservice Asynchronously on a form used to process a login.
If an exception is thrown from the webservice - if the service was called
synchronously obviously the try catch works. However how do I catch
exceptions when I call it Async? At the moment the exception is getting
moved up to the Parent Form which I dont want. Where can I on my form
capture any exceptions?

Much appreciated for any help

Gary Howlett

try{

LWS.DataService oWS = new LWS.DataService();

oWS.PerformLoginAsync(tUsername.Text, tPassword.Text);

oWS.PerformLoginCompleted += new
Leprechaun.Database.LWS.PerformLoginCompletedEvent Handler(oWS_PerformLoginCompleted);

}

catch (Exception ex){

MessageBox.Show(ex.Message, "Unable to Logon", MessageBoxButtons.OK,
MessageBoxIcon.Stop);

this.DialogResult = DialogResult.Abort;
}


Jul 7 '06 #3
Hi,

Am using VS 2005 C#

I'm calling a webservice Asynchronously on a form used to process a login.
If an exception is thrown from the webservice - if the service was called
synchronously obviously the try catch works. However how do I catch
exceptions when I call it Async? At the moment the exception is getting
moved up to the Parent Form which I dont want. Where can I on my form
capture any exceptions?

Much appreciated for any help

Gary Howlett

try{

LWS.DataService oWS = new LWS.DataService();

oWS.PerformLoginAsync(tUsername.Text, tPassword.Text);

oWS.PerformLoginCompleted += new
Leprechaun.Database.LWS.PerformLoginCompletedEvent Handler(oWS_PerformLoginCompleted);

}

catch (Exception ex){

MessageBox.Show(ex.Message, "Unable to Logon", MessageBoxButtons.OK,
MessageBoxIcon.Stop);

this.DialogResult = DialogResult.Abort;
}
Take a look at the EventHandler registered against the Async Web Service call.
Try some what like this sort of implementation in it

if (!e.Cancelled)
{
if (e.Error == null)
{
if (e.Result != null)
{
// Done what u want with the result
}

}
else
{
MessageBox.Show(e.Error.Message);

}
}
else
{
// Web Service call cancelled apply your custom algo here
}

Posted from http://www.topxml.com/renntp using reNNTP: the website based NNTP reader.
Jul 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Liza | last post by:
Hi guys, i'm trying to build a web service....... is there such thing as polymorphism in web services? i mean could i have two web services of the same name but different arguments such that i...
5
by: cyberstrike | last post by:
Hi guys, my company was wondering if it's possible to develop ASP.NET/Webservices easily using a IIS installed on a server instead of installing IIS locally on the development boxes. Can you...
2
by: Antuane | last post by:
any one have any idea how transactions could be enabled in webservices. i.e., suppose i've got 2 methods - one to add a contact, & the other to set some miscellaneous details for the contact, in a...
1
by: Mike | last post by:
Hi all, I have written a webservice which I am using in my smartphone applicaiton. I have tried the webservice with a WinForms client and it works time and time again perfectly. When I include...
1
by: Vinoth Kumar | last post by:
Hi All, I have a problem in throwing custom exceptions from a webservice method. The custom exception is being converted into soapexception in the webservice client. only the custom exception...
8
by: Komandur Kannan | last post by:
We have a smart device application running on handhelds(Symbol MC9000G). The backend is Oracle and a middle tier web services development done in Vb.net. We use pessimistic Locking due to...
5
by: ChrisM | last post by:
Hi, I have written a stand alone WinForms application with an MS Access back-end for the (small)company I work for. They are now talking about moving a part of their operations into a second...
5
by: =?Utf-8?B?a3Jpcw==?= | last post by:
Hi all, How to handle exceptions of webservices? I have a wsdl file which contains the exception classes. when i am adding that wsdl file in my asp application I am unable to view those...
3
by: John Skandar | last post by:
I've found a free WebService on the net for a currency converter and have created a class to use it with the WSDL tool. I call the WebService method asynchronously: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.