Search code examples
vb.netreturnsilverlight-5.0wcf-ria-servicesasync-await

Silverlight 5, return from WCF Ria Service, VB.NET - Simple Hello World


i can't found on any website (yeah.. i took a good couple or hours searching/Reading/testing), a way to call a simple Hello World Function by Return, and show it to the user.

Here is my WCF class code:

Imports System.ServiceModel
Imports System.ServiceModel.Activation

<ServiceContract(Namespace:="Servicio")>
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class ServicioBD

<OperationContract()>
Public Function ReturnString(ByVal number As Integer) As String

    If number = 1 Then
        Return "Hello World!"
    Else
        Return "Bye World!"
    End If

End Function

I added this service with the name "ServicioWCF_BD".

And this is how im calling it from the MainPage.xaml:

Private Sub SayHello()
Dim wcf As New ServicioWCF_BD.ServicioBDClient
    Dim message As String = wcf.ReturnStringAsync(1)  'ERROR THE EXPRESSION DOESNT GENERATE A VALUE
    MessageBox.Show(message)
End Sub

When i try to get the value from the function visual says the error: "The expression doesnt generate a value".

I hope you can help me, actually its the first time im stuck so hard with something that looks so simple..... * sigh *


Solution

  • The return value of wcf.ReturnStringAsync(1) is, most probably, of type Task and not string.

    Your SayHello sub should look something like:

    Private Sub SayHello()
        Dim wcf As New ServicioWCF_BD.ServicioBDClient
        Dim message As String = wcf.ReturnStringAsync(1).Result
        MessageBox.Show(message)
    End Sub
    

    Or, depending where you're calling it from:

    Private Async Function SayHello() As Task
        Dim wcf As New ServicioWCF_BD.ServicioBDClient
        Dim message As String = Await wcf.ReturnStringAsync(1)
        MessageBox.Show(message)
    End Sub