I am trying to create a WCF service with some enumerators exposed for clients to set certain properties on the class object. All enumerators associated with different Operations are put in a separate class.
What I understand after reading through some articles is that the Enumerator is accessible on the client side of a WCF service if,
the enumerator is declared in a separate DataContract. For my case, the problem is I am unable to have the client call the Enumerator like
ClassName.Enum.Value
per how the class has been designed. For some reason, wsdl generated combines the class name and enum name in to a single name likeClassNameEnumName
for the enumerator and that needs to be accessed likeNamespace.ClassNameEnumName
.a property of the enum type is declared inside the Class containing the Enumerators. The problem with this approach is that, I do not need this property but it is the only way I could have the enums recognized and included in the proxy class by the proxy generator on the client side as expected so that it could used like
ClassName.Enum.Value
. Another issue is that it exposes those properties to the client since it needs to be decorated with[DataMember]
. I wish the client never sees those because the client never needs to use it. I am not sure how could I expose only the enumerator without the backing property showing up such that it could be used likeClassName.Enum.Value
.
What I understand is, without an explicit instance of the DataMember, the object declared never gets defined in the proxy class generated. In my case, I am making it happen by creating a property like in the mock-up code below by creating properties but my concern is that this introduces unwanted DataMembers (like EnumErrType
, ErrType
) being exposed to the client.
So the question is, how can I have an enumerator declared inside a class to be used by the client which can be used like ClassName.Enum.Value
without having to expose backing properties or even not creating one in the first place.
[DataContract]
public class ErrorTransaction
{
[DataMember]
public ICollection<Error> Errors { get; set; }
}
[DataContract]
public class Error
{
[DataMember]
public EnumErrorType EnumErrType { get; set; }
[DataMember]
public int id { get; set; }
[DataMember]
public ErrXYZ.EnumErrorType Type { get; set; }
[DataMember]
public DateTime Date { get; set; }
}
public class ErrXYZ
{
[DataMember]
public EnumErrorType ErrType { get; set; }
public enum EnumErrorType : int
{
[EnumMember]
errType1 = 1,
[EnumMember]
errType2 = 2,
[EnumMember]
errType3 = 3
}
}