J'ai une application créée en utilisant WCF et C#, son architecture nécessite d'ajouter KnownTypes via App.config. J'ai des services va comme ceci: client -> centralserver -> DataServer (où -> est la connexion WCF) Maintenant, j'ai ajouté KnownTypes à la fois centralserver App.config et DataServer App.config de cette façon:DataContractSerializer C# Peut sérialiser, ne peut pas désérialiser, pourquoi?
<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>
Mon problème est que la méthode appelante qui prend l'argument de type MethodDeclaration sur DataServer de CentralServer lève une exception que service ne peut désérialiser ce paramètre, bien que CentralServer CAN le sérialise (je sais, car quand je supprime KnownType j'obtiens ce service ne peut pas SERIALIZE). En outre, j'ai beaucoup de ces méthodes définies de la même manière, mais en acceptant un type différent en tant qu'argument, et ils fonctionnent parfaitement. Avez-vous la moindre idée de la raison pour laquelle cela fonctionne (pas) de la sorte?
Exception:
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.
Non, je ne pense pas que ce soit une incompatibilité de type parce qu'ils utilisent un ssembly. J'ai posté une exception. – michajas
Il semble que votre client ne connaisse pas le type MethodDeclaration. est-ce décoré avec l'attribut DataContract et ajouté en tant que type connu au contrat de service> – Maurice