WCF RIA Services를 사용하여 사용자 지정 데이터 전송 개체를 Silverlight 클라이언트로 반환하고 있습니다.기본 개체 목록을 반환하는 서비스 메서드에서 'Complex types can KnownTypeAttribute'메시지를 지정할 수 없습니다.
과일 목록이 들어있는 FruitBasket (this post과 유사) 개체를 반환하고 싶습니다. Fruit 클래스는 Apple, Pear, Peach 등과 같은 파생 클래스의 기본 클래스입니다. 런타임시 Fruits 목록에는 이러한 파생 된 유형 중 하나가 포함될 수 있습니다. RIA Services가 FruitBasket 객체를 직렬화 및 비 직렬화하기를 원합니다.
Type 'Peach' with data contract name 'Peach:http://schemas.datacontract.org/2004/07/FruitApp' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
- 그때 나는 내 과일 클래스에
[KnownType(typeof(Peach))]
속성을 지정하는 경우 : 난 그냥 전체 FruitBasket 개체를 내 클래스 계층 구조를 정의하고 반환하는 경우- , 나는 런타임 오류
Complex type 'Fruit' is invalid. Complex types cannot specify a KnownTypeAttribute.
: 컴파일 시간 오류 클라이언트의 Fruit 컬렉션에 액세스 할 수 있도록 데이터 모델을 설정하려면 어떻게해야합니까? 클라이언트 측에서는 객체가 "과일"객체로만 인식되는 경우에도 괜찮습니다. 나는 그들을 비유화할 필요가있다.
팁 # 2 및 # 4는 매우 유용했습니다. 결국 WCF Services (# 4)로 전환하기 전에 응용 프로그램의 다른 영역에서 # 2를 사용하기 시작했습니다. – YeahStu