开发者

Why is my array of enumeration values null in my WCF service?

开发者 https://www.devze.com 2023-01-10 20:46 出处:网络
I have an array of enumerations on a WCF request that comes through as null, no matter what I have tried.

I have an array of enumerations on a WCF request that comes through as null, no matter what I have tried. The service works apart from the issue with enumerations.

Does anyone have any ideas why this might be?

Enumeration code:

    [DataContract(Namespace = "http://services.myproject.com/requests/MyProject")]
    public enum Recommendation
    {
        [EnumMember]
        One = 1,
        [EnumMember]
        Two = 2,            
    }

SOAP XML:

 ... xmlns:lat="http://services.myproject.com/requests/MyProject" ...
 ...
 <lat:Recommendations>
        <Recommendation>One</Recommendation>
        <Recommendation>Two</Recommendation>
 </lat:Recommendations>
 ...

C#:

[DataContract(Namespace = "http://services.myproject.com/requests/MyProject")]
public class MyRequest : Request ...
{
  开发者_运维问答  //...
    [DataMember]
    public Recommendation[] Recommendations { get; set; }
    //...
}


Try to add [KnownType(typeof(Recommendation[]))] attribute to your MyRequest class

0

精彩评论

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