Exceptions when Making Asynchronous Web Service Calls

Exceptions when Making Asynchronous Web Service Calls

Post by Diwi » Wed, 07 May 2003 01:25:34



Dear Group,

I am calling a webService asynchronously, using a pattern similar to this:
private void button2_Click(object sender, System.EventArgs e)
{
    // Disable the Async button and clear the ListView of any data
    // Create an instance of XML Web service proxy class
    BookCatalog.Service1 ws = new BookCatalog.Service1();
    // Create a reference to the callback delegate
    AsyncCallback cb = new AsyncCallback(ServiceCallback);
    // Call the Begin method, passing the callback delegate and
    // this proxy class instance as the AsyncState object.
    ws.BeginGetItems(cb,ws);

Quote:}

private void ServiceCallback(IAsyncResult ar)
{
    // Cast the AsyncState object to the proxy object
    BookCatalog.Service1 ws = (BookCatalog.Service1)ar.AsyncState;
    // Call the End method and assign the response to a DataSet
    this.ds = ws.EndGetItems(ar);    //forces to updates the ui in the
corresponding thread    this.Invoke(new
EventHandler(this.DataGridUpdater));}

private void DataGridUpdater(object sender, EventArgs ea)

{

      this.pctbSalir.Enabled=true;

      this.dgSanatorios.DataSource=this.ds.Tables["prestadores"];

      this.dgSanatorios.RowHeadersVisible=false;

      this.dgSanatorios.Visible=true;

Quote:}

But I have problems when exceptions rise, I have tried to add a try/cath
block in te line: ws.BeginGetItems(cb,ws), but exceptions still arise and
make me crash the app. The exceptions I wanna catch are
ObjectDisposedException, and InvalidOperationException and some more which
are thrown when the call to the web service has not been successful.

Diwik

 
 
 

Exceptions when Making Asynchronous Web Service Calls

Post by Mike Boilen [M » Thu, 08 May 2003 07:25:04


You'll need to place the try...catch block around the EndGetItems call.  It
is from there that most exceptions due to a failing web service call are
thrown.

Hope this helps.

Mike Boilen
Developer
NET Compact Framework

This posting is provided "AS IS" with no warranties, and confers no rights.
http://www.gotdotnet.com/team/netcf/FAQ.aspx

--------------------

| Subject: Exceptions when Making Asynchronous Web Service Calls
| Date: Mon, 5 May 2003 09:25:34 -0700
| Lines: 53
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 200.80.38.14
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:22304
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Dear Group,
|
|
| I am calling a webService asynchronously, using a pattern similar to this:
| private void button2_Click(object sender, System.EventArgs e)
| {
|     // Disable the Async button and clear the ListView of any data
|     // Create an instance of XML Web service proxy class
|     BookCatalog.Service1 ws = new BookCatalog.Service1();
|     // Create a reference to the callback delegate
|     AsyncCallback cb = new AsyncCallback(ServiceCallback);
|     // Call the Begin method, passing the callback delegate and
|     // this proxy class instance as the AsyncState object.
|     ws.BeginGetItems(cb,ws);
| }
|
| private void ServiceCallback(IAsyncResult ar)
| {
|     // Cast the AsyncState object to the proxy object
|     BookCatalog.Service1 ws = (BookCatalog.Service1)ar.AsyncState;
|     // Call the End method and assign the response to a DataSet
|     this.ds = ws.EndGetItems(ar);    //forces to updates the ui in the
| corresponding thread    this.Invoke(new
| EventHandler(this.DataGridUpdater));}
|
| private void DataGridUpdater(object sender, EventArgs ea)
|
| {
|
|       this.pctbSalir.Enabled=true;
|
|       this.dgSanatorios.DataSource=this.ds.Tables["prestadores"];
|
|       this.dgSanatorios.RowHeadersVisible=false;
|
|       this.dgSanatorios.Visible=true;
|
| }
|
|
| But I have problems when exceptions rise, I have tried to add a try/cath
| block in te line: ws.BeginGetItems(cb,ws), but exceptions still arise and
| make me crash the app. The exceptions I wanna catch are
| ObjectDisposedException, and InvalidOperationException and some more which
| are thrown when the call to the web service has not been successful.
|
|
|
|
|
| Diwik
|
|
|

 
 
 

1. exception handling in asynchronous web method calling

I am makin an asynchronous calling af a webservice

but even the operation finishes with error there no exception throwing

how i can handle eerorors when i use asynchronous method coll?

/*ds = */ IAsyncResult res =
Controller.srvCoryphae.BeginGetDBChanges(afterDate, null, null);

while (!res.IsCompleted)

{

Application.DoEvents();

ds = Controller.srvCoryphae.EndGetDBChanges(res);

--

========================================
Sergius Adamtchouk aka TieX
Visit me http://tiex.topcities.com

2. Getting rid of the header on one page --only

3. Simple way to read local printer status in VMS

4. Catching Asynchronous Web Service Exceptions

5. Do not visit this site - Here it is!! MindBender will Blow your mind! 3061

6. Asynchronous Calls to Web Services

7. Loebner Prize 2001 Contest - transcripts and details

8. Program hangs in after Asynchronous (delegate) call to web service

9. ASP.NET aspx page and ASynchronous Web Service call

10. ASP.NET aspx page and Asynchronous Web Service call

11. making asynchronous calls to remote objects

12. making asynchronous db calls