I'm wondering how to make this object available through WCF:
[DataContract]
public class A : IA
{
[DataMember]
public List<IB> ListOfB { get; set; }
}
public interface IA
{
List<IB> ListOfB { get; set; }
}
with IB
interface of class B
.
Generated XSD is:
<xs:complexType name="A">
<xs:sequence>
<xs:element xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" minOccurs="0" name="ListOfB" nillable="true" type="q1:ArrayOfanyType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="A" nillable="true" type="tns:A"/>
</xs:schema>
ArrayOfanyType -> I'm feeling that it can't work since IB
can't be tagged [DataContract]
.
For the serializer to interpret your contract they need to be expressed in terms of concrete types rather than interfaces. If you change your code to this (and annotate class B with the appropriate DataContract
and DataMember
attributes, you should be good to go.
[DataContract]
public class A
{
[DataMember]
public List<B> ListOfB { get; set; }
}