【问题标题】:WCF enum - any way to transfer both valid enum values AND numbersWCF 枚举 - 传输有效枚举值和数字的任何方式
【发布时间】:2010-06-07 15:33:13
【问题描述】:

假设你有:

 public enum Priority : short
        {

            Low = 100
            Normal = 200,
            High = 300
        }

我想通过以下调用调用 WCF 服务

myWCF.call(Priority.Low);
myWCF.call(Priority.High);
myWCF.call(105);

是否可以在不重写 WCF 堆栈的一半的情况下做到这一点?我更喜欢将所有 WCF 配置设置都设置为枚举类型的解决方案。

谢谢。

【问题讨论】:

  • 您是在问是否可以在 WCF 中拥有重载方法?我不确定您为什么认为需要重写 WCF 堆栈。我想您会惊讶于 WCF 的可扩展性。

标签: .net wcf enums


【解决方案1】:

是的,当然 - 您可以在数据合约中添加第二个属性,以反映枚举的 int 值:

[DataContract]
public class YourData
{
   [DataMember]
   public Priority MyPriority { get; set; }

   [DataMember]
   public int MyPriorityAsInt 
   {  
      get { return (int)MyPriority; }
      set { ; }
   }
}

我认为这应该可行 - MyPriorityAsInt 应该始终准确反映存储在 MyPriority 中的值。如果您愿意,您甚至可以为MyPriorityAsInt 创建setter 方法来根据需要设置MyPriority 的值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多