Name of enum in innerclass changes through WCF-service
I have a class Actions with an Enum in it
[DataContract]
public class Actions
{
[DataContract]
public enum MailDirectLinkContent
{
[EnumMember]
[DescriptionAttribute("Second account holder")]
SecondAccountHolder = 0,
[EnumMember]
[DescriptionAttribute("Legal representative")]
LegalRepresentative = 1,
[EnumMember]
[DescriptionAttribute("Authorized representative")]
AuthorizedRepresentative = 2
}
}
In my wcf-service I have a method
[OperationContract]
void DoActionMailDirec开发者_开发知识库tLinkContent(string toAddress, Actions.MailDirectLinkContent mailDirectLinkContent);
When I want to use this Enum in my webclient, it comes up like this:
var myValue = ActionsMailDirectLinkContent.AuthorizedRepresentative;
(the dot between the class-name and the enum-name disappears)
I suppose there is a decent explanation for this behaviour, but I couldn't find one.
UPDATE: I took the Enum out of the class and put it in a subfolder so that they are still grouped together. The reason for this change is another issue I came accross and was able to solve it this way.
WCF produces its own names for the Types that you're returning from your web service methods. It usually tries to name things based on their local names, but I'm guessing it can't really "namespace" the types, so the type can't include a .
inside of it. WCF therefore is doing its best to create an enum type for purposes of its service that has a descriptive name, but which fits into the SOAP schema (or whatever binding you're using).
The serialization has different rules from C#, you can't expect every C# feature to be supported.
It can't deal with nested types so it constructs a flattened name for those.
You can't overload methods in a OperationContract either.
精彩评论