関数を公開するWCFサービスがあります。
Public Function FeedAnimal(ByVal animal As Animal) As Animal Implements IFarm.FeedAnimal
animal.Feed()
Return animal;
End Function
ただし、Animalは、それぞれ独自のプロパティを持つ多くの派生型を持つ抽象クラスです。しかし、Cowを示すプロパティを使用してSOAPUIでリクエストを行うと、抽象クラスを作成できないというエラーが発生します。WCFでパラメータを実際のタイプに逆シリアル化するにはどうすればよいですか?それらはすべて、異なる名前のプロパティによって区別できると仮定しましょう。
私はすでにKnownType属性をどこにでも追加しようとしましたが、役に立ちませんでした。そうすることで、派生型を返すことができましたが、パラメーターとして受け入れることはできませんでした。
私がやろうとしていることが完全に狂っているなら、次に近いことを教えてください
編集済み; 以前のバージョンで機能していたこの関数のみをXmlSerializerにフォールバックさせることができれば満足です。
[ServiceContract(Namespace:=Constants.SERVICE_NAMESPACE)]
[ServiceKnownType(GetType(Cow))]
Public Interface IFarm
[OperationContract()]
[ServiceKnownType(GetType(Cow))]
[Validation(CheckAssertions:=False, SchemaValidation:=True)]
Function FeedAnimal(ByVal animal As Animal) _
As Animal
End Interface
そしてクラス
[KnownType(GetType(Cow))]
Public MustInherit Class Animal
Public weight As Integer
End Class
Public Class Cow
Inherits Animal
Public mooPower As Double
End Class
そしてリクエスト:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:v3="mycomapnyaddresss" xmlns:foo="animalnamespace">
<soap:Header/>
<soap:Body>
<v3:FeedAnimal>
<!--Optional:-->
<v3:animal>
<!--Optional:-->
<foo:weight>100</foo:weight>
<foo:mooPower>10.0</foo:mooPower>
</v3:animal>
</v3:FeedAnimal>