0
votes

I have a Class2 and a Class1 in a project shared between service and client.

<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

This is my service interface:

<ServiceContract(Name:="Service")> _
Public Interface IService

    <OperationContract()> _
    Function GetStuff() As Class2(Of Class1)

End Interface

And my service implementation:

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

In my service project I also have a Class1 which inherits from the shared class:

Public Class Class1
    Inherits [Shared].Entities.Class1

End Class

My client code:

  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

Running the button click results in two message boxes one with the string "Test" (expected) and one with the string 0 (I expected 1). As soon as I exclude the inherited Class1 from my service project it works as expected.

The thing is this project has been working for years like this and it is only when I recently made a change and rebuilt it that it has stopped working. How can I get this to work? Obviously in my real project, the Class1 in the service project contains some additional functionality I want to use.

1

1 Answers

0
votes

What solved it for me was to add the Namespace to the derived class DataContract attribute. This was already present on the base class.