Home
Manage Your Code
Snippet: Exposing Enums through WCF (C#)
Title: Exposing Enums through WCF Language: C#
Description: Shows how to expose enumerators that aren't being used in method prototypes through WCF Views: 5236
Author: Sagy Langer Date Added: 3/12/2009
Copy Code  
1[ServiceKnownType("GetKnownTypes", typeof(EnumHelper))]
2[ServiceContract]
3public interface IService
4{
5}
6
7
8public static class EnumHelper
9{
10	public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider)
11	{
12		List<Type> knownTypes = new List<Type>();
13		
14		// Add any types to include here

15		knownTypes.Add(typeof(MyEnumName));
16		knownTypes.Add(typeof(MyOtherEnumName));
17
18		return knownTypes;
19	}
20}
21
22[DataContract]
23public enum MyEnumName
24{
25	[EnumMember]
26	FIRST = 1,
27	[EnumMember]
28	SECOND = 2,
29}
30
31[DataContract]
32public enum MyOterEnumName
33{
34	[EnumMember]
35	One = 1,
36	[EnumMember]
37	Two = 2,
38}
Notes
Taken from http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute.aspx