我正在學習如何使用WCF Web服務訪問數據庫上的數據。我碰到的主要問題是,當調用服務的結果時,返回值的類型是UniversityClass,但沒有屬性可用,我相信它的實際類型只是一個對象,因此我無法訪問它的任何「真實」屬性。WCF服務返回沒有屬性的對象
繼承人在我的接口的類名爲的片斷「服務1」
<ServiceContract()>
Public Interface IService1
<OperationContract()>
Function GetUniversity(ByVal universityID As Integer) As UniversityClass
End Interface
<DataContract()>
Public Class UniversityClass
Private _universityId As Integer
Public Property UniversityID As Integer
Get
Return _universityId
End Get
Set(value As Integer)
_universityId = value
End Set
End Property
和繼承人我做調用該服務的預覽來獲取數據
Dim client As New ServiceReference1.Service1Client
Dim result As New ServiceReference1.UniversityClass
Dim x = client.GetUniversityAsync(Integer.Parse(tbUniversityID.Text))
Dim r As WCFServiceExample.ServiceReference1.UniversityClass = Await x
If x.IsCompleted Then
result = x.Result
End If
tbResult.Text = result. _ _ _ _
'//^No properties accessible here even though it recognizes that result is of type UniversityClass
在檢查ServiceReference1 .UniversityClass我被帶到Referece.vb並注意到存在部分類繼承對象的大學類。我想也許這可能是我沒有任何訪問我的Service1類中定義的屬性的原因,因爲它認爲UniversityClass是一個沒有類型的對象。
我試過單獨重建所有項目,重建解決方案仍然沒有。
想了解如何實際獲得類型爲UniversityClass的對象從我的服務中返回,希望能得到一些幫助。
確認類型:http://i50.tinypic.com/e5mhvk.jpg 無可用屬性:http://i50.tinypic.com/wmjui9.jpg
任何幫助將不勝感激!
我明白了!非常感謝Paul – Dave