0

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.
4

2 に答える 2

1

サーバーとクライアントの間でタイプが一致しない可能性はありますか?

例外の詳細を投稿していただければ、さらに役立つ可能性があります。

于 2009-10-23T14:30:35.430 に答える
0

私が試すこと:

  1. MethodDeclaration に DataContractAttribute とプロパティ DataMemberAttribute があるかどうかを確認します
  2. [ServiceKnownType(typeof(MethodDeclaration))] をサービスクラスに追加

擬似コード:

[ServiceContract]
public interface IService
{
    [ServiceKnownType(typeof(MethodDeclaration))]
    void ProcessMethodDeclaration(Declaration val);
}
于 2017-06-23T09:37:56.833 に答える