Name of enum in innerclass changes through WCF-service

℡╲_俬逩灬. 提交于 2020-01-07 02:21:43

问题


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 DoActionMailDirectLinkContent(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.


回答1:


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).




回答2:


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.



来源:https://stackoverflow.com/questions/6957830/name-of-enum-in-innerclass-changes-through-wcf-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!