[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

Asynchronous Web Service that returns Percent Complete

Charles Kierklo

1/5/2003 1:12:00 AM

I am trying to create an Asynchronous Web service that has two methods.

One to perform some work (GetPrice), and one to return the status of that
work.



Like the following:



<WebMethod(Description:="Get the price of a book based on its ProductID
number.", EnableSession:=True)> _

Public Function GetPrice(ByVal ProductID As String) As Double

' Randomly make this routine take between 1 and 10 seconds.

Dim r As New Random()

Session("PercentComplete") = 2

Thread.Sleep(r.Next(1000, 10000))

Return dbProducts.GetPrice(ProductID)

End Function



<WebMethod(Description:="", EnableSession:=True)> Public Function
PercentComplete() As Integer

Return Session("PercentComplete")

End Function



I call it from an ASPX page like the following:



' Create an instance of the web service object

Dim Products As New localhost.Service1()

Dim l_intPercentComplete As Integer



' Call the method asynchronously

Dim result As IAsyncResult = Products.BeginGetPrice("1", Nothing,
Nothing)



Do

' Wait up to 5 seconds for the method to complete

result.AsyncWaitHandle.WaitOne(New TimeSpan(0, 0, 5), False)



' Did the service respond in time?

If (result.IsCompleted) Then

' Yes

Response.Write("The vendor has this item for $" &
Products.EndGetPrice(result).ToString() & ".<BR>")

Exit Do

Else

' No

l_intPercentComplete = Products.PercentComplete()



Response.Write("Percent Complete: " & l_intPercentComplete &
"<BR>")

End If

Loop



The problem is that the PercentComplete method always returns 0, because the
call creates a new instance of the Web Service.



How can I make the call on the same instance?



2 Answers

Saurabh Nandu [MVP]

1/6/2003 6:48:00 AM

0

look at this article to learn how to create a progress bar at the client
side.

[
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service11... ]

--
Regards,
Saurabh Nandu
Microsoft MVP | MCP | Author
www.MasterCSharp.com
Master C#, the easy way...


Charles Kierklo

1/7/2003 3:39:00 AM

0

I appreciate the reply, but I already read that article. It is not
useful to me, because it is a Windows client (not a Web) and the
progress bar is bogus (not a true reflection of percent complete)

The following is a link to an article that is closer to what I am trying
to accomplish. I have to modify it for my needs, but it is a good base.
http://www.codeproject.com/useritems/webserviceca...



*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!