return value async webservice

Does anyone have a good example of calling a web service asynchronously and retrieving a return value (i.e. a dataset) in ASP.NET And VB.NET ?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

Bob LearnedConnect With a Mentor Commented:
Even in Visual Basic, the async methods should be created when you add a classic web reference, using the Compatibility dialog.

I have uploaded a short .mp4 recording of what I mean.
Bob LearnedCommented:
Introductory questions:

What type of web service?

What type of web site?

Framework version?
cehrnowAuthor Commented:
Framework 4.0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Bob LearnedCommented:
If you are going against a classic .asmx web service, then it should have auto-generated async methods in the proxy that it generated, so you could do something like this:

 	 Private supplier As New BookSupplier.WebService()

        Public Sub GetBookCost(ByVal bookName As String)

	   AddHandler supplier.GetCostCompleted AddressOf supplier_GetCostCompleted


        End Sub

       Private Sub supplier1_GetCostCompleted(sender As Object, e As BookSupplier.GetCostCompletedEventArgs)
	   If e.Error IsNot Nothing Then
		Throw e.Error
	   End If
    	   Dim cost As Decimal = TryCast(e.UserState, Decimal)
	   costLabel.Text = "Quote from Book Supplier: " & cost
        End Sub

Open in new window

cehrnowAuthor Commented:
They did not get auto generated as I think this is not longer the default.
Can you please show what I need to add.
Bob LearnedCommented:
Can you show me the code for the auto-generated proxy?

How did you add the web service reference?
cehrnowAuthor Commented:
I don't think VS2013 adds these anymore ?
Bob LearnedCommented:
Here is an example of a classic web service reference:

     public void EchoMessageServiceAsync(string MessageID, string Destination, string Touchpoint, string Location, string Style, string ProductionFlag) {
            this.EchoMessageServiceAsync(MessageID, Destination, Touchpoint, Location, Style, ProductionFlag, null);
        /// <remarks/>
        public void EchoMessageServiceAsync(string MessageID, string Destination, string Touchpoint, string Location, string Style, string ProductionFlag, object userState) {
            if ((this.EchoMessageServiceOperationCompleted == null)) {
                this.EchoMessageServiceOperationCompleted = new System.Threading.SendOrPostCallback(this.OnEchoMessageServiceOperationCompleted);

Use the following steps:

Right click on the Reference node in the Server Explorer tree
Select Add Service Reference
Click on the Advanced button in the lower left corner
Click on the Add Web Reference button in the Compatibility section at the bottom of the Advanced dialog

This will allow you to add a web service reference the old, classic way.
cehrnowAuthor Commented:
It is the async methods in the webservice that are not being created.
Do you have VB code to show how these can be added ?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.