2010-07-20 34 views
1

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

这里是一个相同的I与所述数据契约创建属性: 命名空间例如: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 

回答

0

ResourceTypeOption也看起来是一个自定义类,因此您可以将其定义为其自己类中合同的一部分。客户必须知道这一点,所以它需要自己的合同。客户已经知道如何处理像字符串这样的CLR类型。任何其他自定义类型也必须在合同中定义。

相关问题