WCF と C# を使用してアプリケーションを作成しました。そのアーキテクチャでは、App.config を介して KnownTypes を追加する必要があります。私は次のようなサービスを持っています: Client -> CentralServer -> DataServer (ここで -> は WCF 接続です) ここで、KnownTypes を CentralServer App.config と DataServer App.config の両方に次のように追加しました。
<add
type="Odra.Server.CentralServer.SBQL.AbstractSyntax.Declarations.Declaration,
Odra.Server.CentralServer.SBQL">
<knownType
type="Odra.Server.CentralServer.SBQL.AbstractSyntax.Declarations.MethodDeclaration,
Odra.Server.CentralServer.SBQL" />
</add>
私の問題は、CentralServer から DataServer の MethodDeclaration 型の引数を取るメソッドを呼び出すと、サービスがこのパラメーターを逆シリアル化できないという例外がスローされることです。さらに、同じように定義されたそのようなメソッドがたくさんありますが、引数として異なる型を受け入れ、それらは完全に機能します。なぜこれがこのように機能している(機能していない)のか分かりますか?
例外:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:val.
The InnerException message was 'Element 'http://tempuri.org/:val' contains data of the 'http://schemas.datacontract.org/2004/07/Odra.Server.CentralServer.SBQL.AbstractSyntax.Declarations:MethodDeclaration' data contract. The deserializer has no knowledge of any type that maps to this contract.
Add the type corresponding to 'MethodDeclaration' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.