Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exposing Unused Enum from a WCF service

Tags:

enums

wcf

I want to expose an enum to my client application without referencing it in my WCF Service. However the enum is not visible in the client application. Below is my code:

[DataContract]
public enum Columns
{
    [EnumMember]
    Column1= 0,
    [EnumMember]
    Column2= 1
}

[ServiceKnownType(typeof(Columns))]
public interface IService
{
    [OperationContract]
    Response GetObjects(Request request);
}

Please let me know what am I doing wrong?

like image 838
Dhawal Avatar asked Dec 11 '25 06:12

Dhawal


1 Answers

The Columns enumeration needs to be a property of either Request or Response classes as these are the only types included in the WSDL. The types that are exposed in the WSDL and thus visible to the client are only those that are used as input or output parameters (and all that are part of their class hierarchy) to the operation contract methods. So for example you could add the enum to the Request class:

[DataContract]
public class Request
{
    [DataMember]
    public Columns Columns { get; set; }

    // ... some other properties
}
like image 68
Darin Dimitrov Avatar answered Dec 12 '25 18:12

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!