2011-09-20 22 views
1

我試圖通過我的WCF REST Web服務公開一個枚舉。只顯示一個屬性。詳情請參閱下文。任何人都可以建議爲什麼發生這種情況?通過WCF Rest公開一個枚舉。只顯示一個屬性

[DataContract] 
    public enum OrderAttributes 
    { 
     [EnumMember] 
     AppointmentRef, 
     [EnumMember] 
     AddressRef, 
     [EnumMember] 
     ContactEmail, 
     [EnumMember] 
     ContactFirstName 
    } 

接口

[WebGet(BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "OrderAttributes")] 
     [OperationContract(Name = "OrderAttributes")] 
     DataLayer.OrderAttributes OrderAttributes(); 

服務

[PrincipalPermission(SecurityAction.Demand, Role = "Administrators")] 
DataLayer.OrderAttributes IService.OrderAttributes() { 
    return new OrderAttributes(); 
} 

結果的獲得

<OrderAttributesResponse> 
<OrderAttributesResult>AppointmentRef</OrderAttributesResult> 
</OrderAttributesResponse> 

回答

2

代碼是做什麼你告訴它做,它返回的OrderAttributes類型的值。第一個枚舉是這種情況下的默認枚舉值。如果您需要OrderAttributes的列表,則必須手動構建並返回該列表。 this blog post中的代碼顯示瞭如何創建該列表。

0

您實際上並不需要將枚舉標記爲DataContract。代碼生成器足夠智能,可以在您的代理代碼中使用相應的值生成枚舉。

因爲您指定它是DataContract,所以它實際上會創建一個名爲OrderAttributesclass而不是您的枚舉。

+0

刪除datacontract屬性給出了相同的結果 –