I'm developing a Windows Phone 7 app that uses a WCF service.
I need to use on both projects the following code:
public enum GameType
{
MonoPlayer = 1,
MultiPlayer = 2
}
I'm sure I must not define this enum on both projects, so I figure out that I need to find another solution.
I think I need to use a third project where I have to put enum.
Do you have a better approach?
WCF uses contracts, so the enum must be decorated as a contract.
For instance, you can have:
[DataContract]
public enum GameType
{
[EnumMember]
MonoPlayer = 0,
[EnumMember]
MultiPlayer = 1
}
You put this enum file in a separate project, so that it can be shared by client and WCF service.
Then, in the service contract (i.e., the interface of your WCF service), you must declare the enum as a "known type", like so:
[ServiceContract]
[ServiceKnownType(typeof(GameType))]
public interface IMyService {...}
That should do it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With