Sharing Enum with WCF Service

后端 未结 4 2209
你的背包
你的背包 2020-12-13 08:53

I have few different applications among which I\'d like to share a C# enum. I can\'t quite figure out how to share an enum declaration between a regular application and a WC

4条回答
  •  天涯浪人
    2020-12-13 09:03

    I had a quite weird problem and thought it might be interesting to you. I also had problems that I got a connection stop when I used enums in my data contract. It took me quite a while to find out what the real problem was: I used enums with int values assigned. They started by 1 instead of 0. Obviously WCF requires that there is an enum value equal to 0 for serialization. If you don't state any values within your enumeration, an automatic int value mapping will be done for you starting by 0, so everything's fine. But when you copy paste some other enum definition where the 0 value is not assigned you won't get that to your client through WCF - strange but true!

提交回复
热议问题