我创建了一个 WCF 服务并有两个特定的对象,Contact 和 Driver。驱动程序继承联系人。Contact 对象是更大的 Member 对象的一部分。在代码中,我有以下内容:
<DataContract()>
Public Class Contact
<DataMember()>
Public Name As String
<DataMember()>
Public HomePhone As String
... etc.
End Class
<DataContract()>
Public Class Driver
Inherits Contact
<DataMember()>
Public LicenseNum As String
<DataMember()>
Public LicenseState As String
... etc.
End Class
<DataContract(), KnownType(GetType(Driver))>
Public Class Member
<DataMember()>
Public Info As Contact
<DataMember()>
Public PrimaryStore As Store
... etc.
End Class
因为我在 datacontract 行上有 knowntype,所以我可以创建一个带有 Info 属性的 Member 对象作为 Driver 而不是 Contact,这样我就可以保存他们的许可证信息。
我的问题是,当我创建一个测试项目来查看返回的数据时,我调用 Info 属性时无法获取许可证信息。
Dim svc as New Service.RetrieveService
Dim sMember as Member
Dim memNum as String = "ABC123"
sMember = svc.GetMember(memNum)
Console.WriteLine("LicenseNumber" & sMember.Info...PROBLEM!!!)
sMember.Info 只给我属于联系人的属性(姓名、家庭电话等),而没有属于司机的属性(LicenseNum、LicenseState 等)我如何访问此信息?
我已经尝试将 ServiceKnownType 添加到我的 OperationContract 中,如下所示:
<ServiceContract()>
Public Interface RetrieveMember
<OperationContract(), ServiceKnownType(GetType(Driver))>
Function GetMember(ByVal memberNumber as String) As Member
End Interface
但它没有帮助。