开发者

What's the logic behind WCF generated names for DataContracts

When I use WCF to expose a DataContract as a SOAP wevservice I get some funky genenerated names, such as:

[Flags]
public enum EnumType1
{
    EnumMember1 = 1;
    EnumMember2 = 2;
    EnumMember3 = 4;
}

[DataMember]
private Dictionary< EnumType1, Class1>  Class1Dictionary;

Has this soap r开发者_StackOverflowepresentation over the wire: (I'm paraphrasing):

<Class1Dictionary>
    <KeyValueOfEnumType1Class1UTLV0zE5>
        <Key>EnumMember1 </Key>
        <Value> ... </Value>
    </KeyValueOfEnumType1Class1UTLV0zE5>
</Class1Dictionary>

What's the logic behind KeyValueOfEnumType1Class1UTLV0zE5? I can explain the KeyValueOfEnumType1Class1 part, but where does UTLV0zE5 come from? Furthermore will a WCF client break if this arbitrary string charges?


It does look a bit random to me. I don't know whether the funk is random and subject to changes that will break contracts.

But if you are in search of less funcky WSDL, a workaround (from here) is to subclass the dictionary and use the CollectionDataContractAttribute to override the output during serialization:

[CollectionDataContract(
    Name="MyDictionary", ItemName="Items", KeyName="Key", ValueName="Value")]
public class MyDictionary: Dictionary<EnumType1, Class1>
{        
}

Should generate xml like:

<MyDictionary> 
    <Items> 
        <Key>EnumMember1</Key> 
        <Value> ... </Value> 
    </Items> 
</MyDictionary> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜