WCF - 我可以使用现有类型通过我的 WCF 服务传递吗

发布于 2024-09-10 19:17:08 字数 2334 浏览 4 评论 0原文

我有一个服务。我有一个现有的业务对象类。我想知道的是如何从业务对象程序集中通过 WCF 传递类,而无需在附加或标记时在 WCF 站点中创建新类?

这是一个现有的 UDT: 命名空间示例: Application.BusinessObjects.Appointments

Public Structure AppointmentResource
    Private _id As String
    Private _type As ResourceTypeOption
    Private _name As String

    Property id() As String
        Get
            Return _id
        End Get
        Set(ByVal value As String)
            _id = value
        End Set
    End Property

    Property type() As ResourceTypeOption
        Get
            Return CType(_type, Int32)
        End Get
        Set(ByVal value As ResourceTypeOption)
            _type = value
        End Set
    End Property

    Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property

    Public Sub New(ByVal id As String, ByVal type As ResourceTypeOption, ByVal name As String)
        _id = id
        _type = type
        _name = name
    End Sub
End Structure

这是我使用数据协定属性创建的同一命名空间: 命名空间示例: Application.Service.Appointments

<DataContract()> _
    Public Structure AppointmentResource
        Private _id As String
        Private _type As ResourceTypeOption
        Private _name As String

        <DataMember()> _
        Property id() As String
            Get
                Return _id
            End Get
            Set(ByVal value As String)
                _id = value
            End Set
        End Property

        <DataMember()> _
        Property type() As ResourceTypeOption
            Get
                Return CType(_type, Int32)
            End Get
            Set(ByVal value As ResourceTypeOption)
                _type = value
            End Set
        End Property

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

        Public Sub New(ByVal id As String, ByVal type As ResourceTypeOption, ByVal name As String)
            _id = id
            _type = type
            _name = name
        End Sub
    End Structure

I have a service. I have an existing class of business objects. What I would like to know is how can I pass a class through WCF from the business object assembly without having to create a new class in my WCF site while appending or tags?

Here is an existing UDT:
Namespace example: Application.BusinessObjects.Appointments

Public Structure AppointmentResource
    Private _id As String
    Private _type As ResourceTypeOption
    Private _name As String

    Property id() As String
        Get
            Return _id
        End Get
        Set(ByVal value As String)
            _id = value
        End Set
    End Property

    Property type() As ResourceTypeOption
        Get
            Return CType(_type, Int32)
        End Get
        Set(ByVal value As ResourceTypeOption)
            _type = value
        End Set
    End Property

    Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property

    Public Sub New(ByVal id As String, ByVal type As ResourceTypeOption, ByVal name As String)
        _id = id
        _type = type
        _name = name
    End Sub
End Structure

Here is the same one I created with the data contract attributes:
Namespace example: Application.Service.Appointments

<DataContract()> _
    Public Structure AppointmentResource
        Private _id As String
        Private _type As ResourceTypeOption
        Private _name As String

        <DataMember()> _
        Property id() As String
            Get
                Return _id
            End Get
            Set(ByVal value As String)
                _id = value
            End Set
        End Property

        <DataMember()> _
        Property type() As ResourceTypeOption
            Get
                Return CType(_type, Int32)
            End Get
            Set(ByVal value As ResourceTypeOption)
                _type = value
            End Set
        End Property

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

        Public Sub New(ByVal id As String, ByVal type As ResourceTypeOption, ByVal name As String)
            _id = id
            _type = type
            _name = name
        End Sub
    End Structure

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不会写诗 2024-09-17 19:17:08

有一种简单的方法可以在客户端和服务之间共享类型,只需在添加服务引用之前向客户端添加对共享类型程序集的引用即可。

您可以在那里找到详细的场景和示例项目:

http://blog.walteralmeida.com/2010/08/wcf-tips-and-tricks-share-types- Between-server-and-client.html

There is an easy way to share types between client and service, just by adding reference to shared type assembly to your client BEFORE adding the service reference.

You can find the detailed scenario and sample project there:

http://blog.walteralmeida.com/2010/08/wcf-tips-and-tricks-share-types-between-server-and-client.html

白昼 2024-09-17 19:17:08

ResourceTypeOption 似乎也是一个自定义类,因此您可以将其定义为其自己的类中的协定的一部分。客户必须了解这一点,因此需要自己的合同。客户端已经知道如何处理字符串等 CLR 类型。任何其他自定义类型也必须在合同中定义。

ResourceTypeOption also appears to be a custom class, so you would to define that as part of the contract in its own class. The client has to know about that and so it needs its own contract. Clients already know how to deal with CLR types like string. Any other custom types would also have to be defined in the contract.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文