Silverlight 5,从WCF返回Ria服务,VB.NET -简单的Hello世界



我在任何网站上都找不到。我花了好几个小时搜索/阅读/测试),一种通过返回调用简单Hello World函数的方法,并将其显示给用户。

下面是我的WCF类代码:

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

我添加了这个名为" serviciciowcf_bd "的服务。

这是我从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

当我试图从函数中获取值时,视觉显示错误:"表达式不生成值"。

我希望你能帮助我,实际上这是第一次我卡住了这么难的东西,看起来如此简单.....

wcf.ReturnStringAsync(1)的返回值很可能是Task类型而不是字符串。

你的SayHello子句应该看起来像这样:

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

或者,取决于你从哪里调用它:

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

最新更新