Solved

return value async webservice

Posted on 2014-12-11
9
99 Views
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 ?
0
Comment
Question by:cehrnow
  • 5
  • 4
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Introductory questions:

What type of web service?

What type of web site?

Framework version?
0
 

Author Comment

by:cehrnow
Comment Utility
ASMX
Framework 4.0
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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

	   supplier.GetCostAsync(bookName)

        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

0
 

Author Comment

by:cehrnow
Comment Utility
They did not get auto generated as I think this is not longer the default.
Can you please show what I need to add.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 96

Expert Comment

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

How did you add the web service reference?
0
 

Author Comment

by:cehrnow
Comment Utility
I don't think VS2013 adds these anymore ?
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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.
0
 

Author Comment

by:cehrnow
Comment Utility
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 ?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
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.

https://filedb.experts-exchange.com/incoming/ee-stuff/8399-Add-Classic-Web-Reference.mp4
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now