【发布时间】:2017-09-19 00:36:35
【问题描述】:
我在服务和客户端之间共享的项目中有一个 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 包含一些我想要使用的附加功能。
【问题讨论】:
标签: vb.net wcf serialization