views:

20

answers:

1

I have an array of enumerations on a WCF reuqest 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; }
    //...
}
+2  A: 

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

Alex Krupnov
@Alex, thanks just tried it, no effect that I can see. Xml fail!
Ben Aston
Solution was to actually add [KnownType(typeof(Recommendation))]. Thanks for pointer
Ben Aston