Avatar of cehrnow
cehrnow

asked on 

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 ?
WCFVisual Basic.NET

Avatar of undefined
Last Comment
Bob Learned
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Introductory questions:

What type of web service?

What type of web site?

Framework version?
Avatar of cehrnow
cehrnow

ASKER

ASMX
Framework 4.0
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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

Avatar of cehrnow
cehrnow

ASKER

They did not get auto generated as I think this is not longer the default.
Can you please show what I need to add.
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Can you show me the code for the auto-generated proxy?

How did you add the web service reference?
Avatar of cehrnow
cehrnow

ASKER

I don't think VS2013 adds these anymore ?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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.
Avatar of cehrnow
cehrnow

ASKER

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 ?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo