Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / February 2005

Tip: Looking for answers? Try searching our database.

Asynchronous web services

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jez - 15 Feb 2005 14:55 GMT
I've been trying for the past two days to get an asynchronous web service to
work. After understanding (thanks to an online tutorial and the Microsoft Web
Services book) all the concepts (call back, async result etc...), I still
haven't managed to get it to work. I am able however to use a synchronous web
service.

Here's the code that I have on the client. The webservice takes a string and
returns a string.

static void Main(string[] args) {   
jezWS.stoproService ws = new jezWS.stoproService();
AsyncCallback cb = new AsyncCallback (Class1.ReportCallBack);
IAsyncResult ar = ws.BegingetPhone("name", cb, ws);       
}

public static void ReportCallBack (IAsyncResult ar) {       
Console.WriteLine("*** Got response from Web Service ***");
stoproService ws = (stoproService) ar.AsyncState;
Console.WriteLine(ws.EndgetPhone(ar));           
}

The code compiles okay, but after the third line in the Main method it
simply exits. If however, I put the third line of the ReportCallBack method
in the main method (i.e. the one with EndgetPhone), I do get a response from
the web service but it's just not asynchronous! I just want to be able to
show for instance text on the Console while waiting for a response.

Thanks so much for the help,

jez
Dan Rogers - 15 Feb 2005 21:28 GMT
The code exits because it reaches the end of main.  There's no magic here -
the code works like it always did.  When main runs out, the program will
terminate.  What you need to do is put a wait loop into your main.  This
would be the worker thread, or whatever does the text display you spoke of
while the service is being invoked in the background.  FYI, the service
isn't async, and neither is your call.  This begin/end behavior simply
spins up a background thread that makes the synchronous call for you, and
then calls your registered callback method when the response is received.  
Your program has to exist (e.g not have exited) for this to work.

--------------------
>Thread-Topic: Asynchronous web services
>thread-index: AcUTblQ87n6jW28vRRCc14ykFnMyWQ==
[quoted text clipped - 17 lines]
>Path: TK2MSFTNGXA01.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
>Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:5535
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
>
[quoted text clipped - 28 lines]
>
>jez
jez - 16 Feb 2005 09:09 GMT
Thanks a lot for the explanation. I created a windows app to test the the
behavior (as it does not "simply" exit at the end of the main method) and
could indeed see the correct "asynchronous" behavior taking place. Thank you
for the clarification.

jez

> The code exits because it reaches the end of main.  There's no magic here -
> the code works like it always did.  When main runs out, the program will
[quoted text clipped - 67 lines]
> >
> >jez

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.