Async web method invocation

  • Thread starter Giulio Petrucci
  • Start date
G

Giulio Petrucci

Hi there,

I'm quite a newbie in Web Service programming/using and I'm sorry if my
question could sound quite "stupid". ;-)

I'm working on an application which should request a service to a
WebService, calling its method "FooMethod(...args...)". I've imported
the web reference within my VisualStudio project and tryed to invoke the
method. I noticed that the intellisense expose also:
- an "AsyncFooMethod(...args...(+1 overloads))";
- a "CompleteFooMethod" event;
I supposed they're for async method invocation, right?
So, could you suggest me any "for-very-dummy" resource to learn how to
use them? Expecially examples and code snippets would be appreciated.

Thanks in advance,
Giulio
 
P

Peter Duniho

Giulio said:
Hi there,

I'm quite a newbie in Web Service programming/using and I'm sorry if my
question could sound quite "stupid". ;-)

As they say, "there are no stupid questions".

Based on past experience with a small minority of questioners, I might
amend that, qualifying the statement with "...as long as the questions
are asked in earnest and the questioner is open to the answers, even if
they don't necessarily like the answer". But IMHO, this qualification
is almost always assumable. :)
I'm working on an application which should request a service to a
WebService, calling its method "FooMethod(...args...)". I've imported
the web reference within my VisualStudio project and tryed to invoke the
method. I noticed that the intellisense expose also:
- an "AsyncFooMethod(...args...(+1 overloads))";
- a "CompleteFooMethod" event;

I haven't used WebService. Sounds like an ASP.NET-specific thing, and
if so there is a newsgroup that is specific to ASP.NET questions that
might be a better place to ask that.

That said...
I supposed they're for async method invocation, right?
So, could you suggest me any "for-very-dummy" resource to learn how to
use them? Expecially examples and code snippets would be appreciated.

MSDN has many good code samples, IMHO. In a cursory search, I wasn't
able to find anything related to WebService that looked like the naming
pattern you describe, so I can't confirm for the specific things you're
talking about. If you're having trouble finding or using the code
samples, you might want to post actual names of classes and methods
you're trying to use.

The basic idea, however, should be simple and should follow the same
asynchronous design other parts of .NET have. Specifically, you call a
method that starts with "Begin..." or "Async...", providing a callback
delegate method (generally you can just write as a parameter the name of
the method you want called when the operation completes). Then in that
callback method, you call the "End..." or "Complete..." method to finish
the operation.

(Note: I'm making some assumptions about the "Async..." and
"Complete..." versions, that they are similar if not identical to the
"Begin..." and "End..." pattern. I haven't actually run into the
Async/Complete naming scheme before, so hopefully it's a valid
assumption to make :) ).

If the operation uses the IAsyncResult interface, you can also check for
completion using an event handle or flag property found in the
IAsyncResult instance, but IMHO the callback is usually the more
convenient and practical mechanism to use.

Pete
 
C

Chris Mullins [MVP - C#]

Peter Duniho said:
I haven't used WebService. Sounds like an ASP.NET-specific thing, and if
so there is a newsgroup that is specific to ASP.NET questions that might
be a better place to ask that.

Well, these days it's not that simple. Web Services have since become
Services (what that does to a Windows Service, is somewhat of a terminology
mystery), which don't need any of the ASP.Net or even IIS...

WCF has changed the game there, and made what used to be a Web Service into
the generic thing for out-of-proecss communication.
(Note: I'm making some assumptions about the "Async..." and "Complete..."
versions, that they are similar if not identical to the "Begin..." and
"End..." pattern. I haven't actually run into the Async/Complete naming
scheme before, so hopefully it's a valid assumption to make :) ).

It's a pretty valid asumption in most cases. With that said, there are some
instances where that pattern is used and has some "unexpected" threading
implications:
- the BackgroundWorker in Winforms will make sure your event fires on
the right thread, eliminating much of the complexity that traps people.
- The ASP.Net AsyncOperationManager can, I believe, sometimes get
involved in the fray, and help insure things such as your Context are
correct when the even fires (I'm not quite sure about this one. I haven't
personally used it).

Overall, it's a pattern simply designed to not scare off people new to the
world of Async Programming.
[...] IMHO the callback is usually the more convenient and practical
mechanism to use.

I tend to agree, as I've been using them for years and the pattern is very
widespread. However, all that passing around state, and dealing the
IAsyncResult realy confuses many people.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top