0

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 like ClassNameEnumName for the enumerator and that needs to be accessed like Namespace.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 like ClassName.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
    }
}
thinkster
  • 586
  • 2
  • 5
  • 19
  • I didn't understand exactly what you need but, why did you create the class "ErrXYZ"? Just to hold the enum "EnumErrorType"? You can simply declare the enum within the same name space of "Error" class. – Ricardo Pontual Nov 07 '16 at 11:28
  • Declaring enum inside the Namespace instead of the class works but that causes a change in design and the way it is encapsulated. I am trying to locate all the enums/constants etc. in a separate class so that it could be invoked like - ClassName.Enum.Value by the client. ErrXYZ class contains constants and enums supporting other Operations in the service. – thinkster Nov 07 '16 at 13:30

0 Answers0