WCFはオブジェクトを正常にシリアル化できます。WCF一覧<string >シリアライズ/デシリアライズエラー
Message=The formatter threw an exception while trying to deserialize the message:
There was an error while trying to deserialize parameter http://tempuri.org/:GetDataResult.
The InnerException message was 'Error in line 1 position 990.
Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value' contains data from a type
that maps to the name 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfstring'.
The deserializer has no knowledge of any type that maps to this name.
Consider using a DataContractResolver or add the type corresponding to 'ArrayOfstring'
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.'.
私もKnownType属性を追加しようとしました:Response.Data辞書の値の型がリスト<文字列>である場合にデータをitreceivedし、それをデシリアライズしようとしたときには、クライアントは次の例外がスローされましたServiceContractとDataContractは次のようになります。
[ServiceContract]
[ServiceKnownType(typeof(List<string>))]
[ServiceKnownType(typeof(Dictionary<string, string>))]
[ServiceKnownType(typeof(Dictionary<string, List<string>>))]
public interface IWcfService
{
[OperationContract]
[ServiceKnownType(typeof(List<string>))]
[ServiceKnownType(typeof(Dictionary<string, string>))]
[ServiceKnownType(typeof(Dictionary<string, List<string>>))]
Response GetData();
}
[DataContract]
[ServiceKnownType(typeof(List<string>))]
[ServiceKnownType(typeof(Dictionary<string, string>))]
[ServiceKnownType(typeof(Dictionary<string, List<string>>))]
[KnownType(typeof(List<string>))]
[KnownType(typeof(Dictionary<string, string>))]
[KnownType(typeof(Dictionary<string, List<string>>))]
public class Response
{
[DataMember]
public Dictionary<string, object> Data { get; set; }
}
しかし、これは役に立ちませんでした。誰もがこれに関するアイデアを持っていますか? サーバーがクライアントに「動的」の辞書を送信する必要があります:
Data = new new DIctionary<string, object>
{
{"_id", 12344},
{"names", new List<string>{ "John", "Peter", "Jack"}},
{"time", DateTime.Now}
}
私たちは辞書<文字列、オブジェクト>を使用した理由を:データは次のようになり
を更新しました
データは、int、List、DataTimeなどとすることができます。これは辞書を使用してこの問題を解決するのに役立ちますが、元の型情報も失います。たとえば、クライアントはListを必要とし、コレクションを表示するためにデータバインディングを行うため、List.ToString()はこの場合役に立ちません。
辞書の値の1つが 'string []'または 'List'でしょうか?私は言う必要があります: 'オブジェクト'を使用する***任意のポイントで***データの契約ではすぐに警鐘をオフに設定する必要があります。 'object' *は契約ではありません* - 契約の合計*不在*です。しかしながら! ([KnownType(typeof(string [])) '/' [ServiceKnownType(typeof(string [])) '(注:ランダム属性を追加するのは何かを "修正"する最良の方法ではありません) –
辞書の値がListである場合、問題が発生します。また、[KnownType(typeof(string []))]/[ServiceKnownType(typeof(string []))]を使用しようとしましたが、役に立たなかった –
wd113
サービスリファレンスの追加を使用して、サービス? –