我在服务和客户端共享的项目中有一个Class2和一个Class1。
<DataContract> _
Public Class Class1
<DataMember> _
Public Property Test
End Class
<DataContract()> _
Public Class Class2(Of ReturnType)
<DataMember> _
Public Property Test As String
<DataMember()> _
Public Property Items() As ReturnType()
End Class
这是我的服务界面:
<ServiceContract(Name:="Service")> _
Public Interface IService
<OperationContract()> _
Function GetStuff() As Class2(Of Class1)
End Interface
我的服务实施:
Public Class Service
Implements IService
Public Function GetStuff() As Class2(Of Class1) Implements IService.GetStuff
Dim results As Class2(Of Class1) = New Class2(Of Class1)
Dim oClass1 As New Class1
results.Test = "test"
oClass1.Test = "test"
results.Items = {oClass1}
Return results
End Function
End Class
在我的服务项目中,我还有一个继承自共享类的Class1:
Public Class Class1
Inherits [Shared].Entities.Class1
End Class
我的客户代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oEndpoint As New System.ServiceModel.EndpointAddress(New Uri("net.tcp://localhost/service"), _
System.ServiceModel.EndpointIdentity.CreateUpnIdentity(""))
Dim oClient As New ServiceClient("IService", oEndpoint)
Dim oList As Class2(Of Class1) = oClient.GetStuff()
MessageBox.Show(oList.Test)
MessageBox.Show(oList.Items.Length.ToString)
End Sub
Public Class ServiceClient
Inherits System.ServiceModel.ClientBase(Of IService)
Implements IService
Public Sub New(ByVal endpointConfigurationName As String, _
ByVal endpoint As System.ServiceModel.EndpointAddress)
MyBase.New(endpointConfigurationName, endpoint)
End Sub
Public Function GetStuff() As Class2(Of Class1) Implements IService.GetStuff
Dim oRet As Class2(Of Class1) = MyBase.Channel.GetStuff()
Return oRet
End Function
End Class
运行按钮单击会生成两个消息框,一个字符串为“Test”(预期),另一个字符串为0(我预期为1)。只要从服务项目中排除继承的Class1,它就会按预期工作。
事情是这个项目已经工作多年了,只有当我最近做出改变并重建它已经停止工作时。我怎样才能让它发挥作用?显然,在我的实际项目中,服务项目中的Class1包含一些我想要使用的附加功能。
答案 0 :(得分:0)
为我解决的是将Namespace添加到派生类DataContract属性中。这已经存在于基类中。