return value async webservice

Posted on 2014-12-11
Last Modified: 2015-01-16
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 ?
Question by:cehrnow
  • 5
  • 4
LVL 96

Expert Comment

by:Bob Learned
ID: 40496641
Introductory questions:

What type of web service?

What type of web site?

Framework version?

Author Comment

ID: 40496856
Framework 4.0
LVL 96

Expert Comment

by:Bob Learned
ID: 40497306
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.


Author Comment

ID: 40497670
They did not get auto generated as I think this is not longer the default.
Can you please show what I need to add.
LVL 96

Expert Comment

by:Bob Learned
ID: 40500413
Can you show me the code for the auto-generated proxy?

How did you add the web service reference?

Author Comment

ID: 40500642
I don't think VS2013 adds these anymore ?
LVL 96

Expert Comment

by:Bob Learned
ID: 40501021
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.

Author Comment

ID: 40502155
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 ?
LVL 96

Accepted Solution

Bob Learned earned 500 total points
ID: 40503006
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.

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Write to file when application closes (by logoff) - VB.NET 1 32
VB.Net Report Printing Issue 3 34
start a process from a service 3 23 class 3 16
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question