类不能在WCF服务中使用,而派生类可以使用

时间:2015-02-13 13:05:23

标签: vb.net wcf

我有一个抽象类FileFolderBase,其中有2个类派生自FileFolder,类ProjectFolder再次派生自Folder类。

我有一个名为BrowseService的WCF服务,其中包含两个函数:GetRoot,它返回ProjectFolder个实例列表,OpenFolder返回一个Folder实例。

这是服务代码

iBrowseService.vb:

Imports System.ServiceModel

<ServiceContract()>
Public Interface IBrowseService

    <OperationContract()>
    Function OpenFolder(ByVal path As String) As Domain.Folder
    <OperationContract()>
    Function GetRoot(ByVal projectCodes As String) As List(Of Domain.ProjectFolder)
End Interface

BrowseService.svc.vb:

Imports System.ServiceModel.Activation

<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class BrowseService
    Implements IBrowseService

    Public Function OpenFolder(ByVal path As String) As Domain.Folder Implements IBrowseService.OpenFolder
        Dim service As MyService = New MyService()
        Dim folder As Domain.Folder = service.OpenFolder(path)
        Return folder
    End Function

    Public Function GetRoot(ByVal projectCodes As String) As List(Of Domain.ProjectFolder) Implements IBrowseService.GetRoot
        Dim service As MyService = New MyService()
        Dim folders As List(Of Domain.ProjectFolder)
        If Not String.IsNullOrEmpty(projectCodes) Then
            Dim codes As List(Of String) = projectCodes.Split(",").ToList
            folders = service.GetRoot(codes)
        Else
            folders = service.GetRoot(Nothing)
        End If
        Return folders
    End Function    
End Class

那里没有什么过于复杂的,现在奇怪的是,GetRoot函数完美地运行并在我调用它时返回一组ProjectFolder个实例。然而,OpenFolder功能根本不起作用。 WCF测试客户端提供'WCF测试客户端不支持此操作,因为它使用类型文件夹'消息,当我在应用程序中使用该服务时,我得到CommunicationsException ,大多数内部异常消息'在调用时,远程主机'强行关闭现有连接。

我找不到可以使用ProjectFolder的原因,而Folder则不能,尤其是导致ProjectFolder来自Folder

以下是4种类型的来源:

FileFolderBase

Imports System.Runtime.Serialization

<Serializable()>
<DataContract(IsReference:=True)>
Public MustInherit Class FileFolderBase
    Implements IComparable(Of FileFolderBase)
#Region "Attributes"
    Protected varPkey As Long
    Protected varName As String
    Protected varFullName As String
    Protected varProjectFolder As ProjectFolder
    Protected varLastModified As Date
#End Region
#Region "Properties"
    <DataMember>
    Public Property Pkey() As Long
        Get
            Return varPkey
        End Get
        Set(value As Long)
            varPkey = value
        End Set
    End Property

    <DataMember>
    Public Property Name() As String
        Get
            Return varName
        End Get
        Set(ByVal value As String)
            varName = value
        End Set
    End Property

    <DataMember>
    Public Property FullName() As String
        Get
            Return varFullName
        End Get
        Set(ByVal value As String)
            varFullName = value
        End Set
    End Property

    <DataMember>
    Public Property ProjectFolder() As ProjectFolder
        Get
            Return varProjectFolder
        End Get
        Set(value As ProjectFolder)
            varProjectFolder = value
        End Set
    End Property

    <DataMember>
    Public Property LastModified() As Date
        Get
            Return Me.varLastModified
        End Get
        Set(ByVal value As Date)
            Me.varLastModified = value
        End Set
    End Property
#End Region
#Region "Methods"
    'Equals function and = and <> operators
#End Region
#Region "CompareMethods"
'Comparison functions, used for sorting and stuff
#End Region
End Class

文件

Imports System.Runtime.Serialization

<Serializable()>
<DataContract(IsReference:=True)>
Public Class File
    Inherits FileFolderBase
#Region "Attributes"
    Private varSize As Long
    Private varComment As String
#End Region
#Region "Constructors"
    Public Sub New()
        Me.varPkey = 0
    End Sub

    Public Sub New(ByVal pkey As Long, ByVal name As String, ByVal fullName As String, ByVal lastModified As Date, ByVal size As Long, ByVal comment As String, ByVal project As ProjectFolder)
        Me.varPkey = pkey
        Me.varName = name
        Me.varFullName = fullName
        Me.varLastModified = lastModified
        Me.varSize = size
        Me.varComment = comment
        Me.varProjectFolder = project
    End Sub
#End Region
#Region "Properties"
    <DataMember>
    Public Property Size() As Long
        Get
            Return Me.varSize
        End Get
        Set(ByVal value As Long)
            Me.varSize = value
        End Set
    End Property

    <DataMember>
    Public Property Comment() As String
        Get
            Return Me.varComment
        End Get
        Set(ByVal value As String)
            Me.varComment = value
        End Set
    End Property
#End Region
#Region "Methods"
    'Equals function and = and <> operators
#End Region
#Region "CompareMethods"
    'Comparison functions, used for sorting and stuff
#End Region
End Class

文件夹

Imports System.Runtime.Serialization
<Serializable()>
<DataContract(IsReference:=True)>
Public Class Folder
    Inherits FileFolderBase
#Region "Attributes"
    Protected varItems As List(Of FileFolderBase)
    Protected varParent As Folder
#End Region
#Region "Constructors"
    Public Sub New()
        Me.varPkey = 0
    End Sub

    Public Sub New(ByVal pkey As Long, ByVal name As String, ByVal fullName As String, ByVal lastModified As Date, ByVal parent As Folder, ByVal project As ProjectFolder)
        Me.varPkey = pkey
        Me.varName = name
        Me.varFullName = fullName
        Me.varLastModified = lastModified
        Me.varParent = parent
        Me.varProjectFolder = project
        varItems = New List(Of FileFolderBase)()
    End Sub
#End Region
#Region "Properties"
    <DataMember>
    Public Property Items() As List(Of FileFolderBase)
        Get
            Return Me.varItems
        End Get
        Set(ByVal value As List(Of FileFolderBase))
            Me.varItems = value
        End Set
    End Property

    <DataMember>
    Public Property Parent() As Folder
        Get
            Return varParent
        End Get
        Set(ByVal value As Folder)
            Me.varParent = value
        End Set
    End Property
#End Region
#Region "Methods"
    'Equals function and = and <> operators
#End Region
End Class

ProjectFolder

Imports System.Runtime.Serialization

<Serializable()>
<DataContract(IsReference:=True)>
Public Class ProjectFolder
    Inherits Folder
#Region "Attributes"
    Private varProject As Project
#End Region
#Region "Constructors"
    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal project As Project, ByVal parent As Folder)
        MyBase.New(0, project.Name, project.Name, Date.Now, parent, Nothing)
        Me.varProject = project
    End Sub
#End Region
#Region "Properties"
    <DataMember>
    Public Property Project() As Project
        Get
            Return Me.varProject
        End Get
        Set(ByVal value As Project)
            Me.varProject = value
        End Set
    End Property

    <DataMember>
    Public Overloads Property Items() As List(Of FileFolderBase)
        Get
            Return Me.varItems
        End Get
        Set(ByVal value As List(Of FileFolderBase))
            Me.varItems = value
        End Set
    End Property

    <DataMember>
    Public Overloads Property ProjectFolder() As ProjectFolder
        Get
            Return Me
        End Get
        Set(value As ProjectFolder)

        End Set
    End Property
#End Region
#Region "Methods"
    'Equals function and = and <> operators
#End Region
End Class

请帮助,因为我不知道如何做到这一点。

0 个答案:

没有答案