문제

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; } 
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top