Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

webservice gurus, help with asynchronous invoking

Status
Not open for further replies.

Glowworm27

Programmer
May 30, 2003
587
US
Hey group,

I have a question relating to calling a Webservice method asynchronously.

The question is this; I have a webmethod() that will download a file and import the file into the database. I have a webpage that allows the user to tell it the filename, and then click on the button, to invoke the webservice to download and import the file.
I want to invoke the webservice asynchronously so the user does not need to wait around for the import to finish. I want to the user to be able to go to other pages, and continue working on other stuff. I dont care if the user ever gets notified that the import was completed, I will write a line to the status of the application that all can see from the front page.
Is this do-able or must the user stay on that page until the webservice completes?

Thanks in Advance
[cannon]

George Oakes
Check out this awsome .Net Resource!
 
hi,
i am at work and my reference is at home. but I would suggest the visual basic programmers cookbook. it has webservice code in it.

i will post more tonight when I find it.

bassguy
 
What I would to for this, is in the webservice class, create the following:

Code:
Public Delegate Sub Status_Message(ByVal Message as String)
Private m_smStatus as Status_Message

Make the constructor in the webservice class like this:

Code:
Public Sub New(ByVal StatusCallback as Status_Message)
    m_smStatus = StatusCallback
End Sub

IN the webservice class, you'll need the following
Code:
Public Property FileToUpload() As String
        Get
            Return m_strFileName
        End Get
        Set(ByVal Value As String)
            m_StrFileName = Value
        End Set
End Property

and some subroute to fire off the uploading.
Code:
Public Sub UploadFile()
    'Do uploading here
Exit Sub

In the UI, you have to create a Sub that will handle the status message callbacks:

Code:
Public Sub StatusMessageFired(ByVal Message as String)
   MyStatusLabel.Text = Message
End Sub

In the button click event:

Code:
Public Sub Button_Click(blahblah) Handles Button.Click
   Dim ws as new MyWebService(AddressOf StatusMessageFired)

   ws.FileNameToUpload = strFileName

   Dim threadWeb as New _
      System.Threading.Thread(ws.UploadFile())
   threadWeb.Start
End Sub


Something like that should work.

--NipsMG
 
Oh yeah, and in the webservice, you can fire a status message back to the client by:

Code:
    m_smStatus.Invoke("My Status Message")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top