Translate

Sunday 20 January 2013

Hiding fields in WSDL file for Enum structure

Attended the training on WCF at workplace.. and found out a solution to my recuring problem of dealing with Issues when an Enum Data Contract is binded to a combobox.
The issue is when you bind an enum to a combobox, you can manually select a default value to the combobox by selected the SELECTED_INDEX property.. But if you fail to do so,a Blank value is selected by default.

But if you transfer this over your service, the System throws serialization exception as a Blank Value is never set in your enum.

But if you Add a Enum member as "BLANK" to denote that no data is selected then you need to expose the change to WSDL file, and hence to all clients which are using your service.

To avoid it, we can use [EnumMember] attribute over the fields which we want to include in WSDL.

HEnce now Enum will look like:(at ur end)

enum Color
{
NotSelected,

[EnumMember]
Red,

[EnumMember
Yellow

}


But to Client it will be displayed as:

enum Color
{

Red,
Yellow

}

No comments:

Post a Comment