使用WCF的NameValueCollection序列化问题 [英] WCF serialization problem using NameValueCollection

查看:229
本文介绍了使用WCF的NameValueCollection序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在序列化WCF一个NameValueCollection中。我不断收到异常告诉我陆续添加一个类型。加入他们后,我终于得到

I'm trying to serialize a NameValueCollection over WCF. I keep getting exceptions telling me to add one type after another. After adding them, I finally get

键入'System.Object的[]不能因为其他类型添加到已知类型列表制度.Collections.ArrayList使用相同的数据合同名称' http://schemas.microsoft.com/2003/ 10 /序列化/阵列:ArrayOfanyType '已经存在

Type 'System.Object[]' cannot be added to list of known types since another type 'System.Collections.ArrayList' with the same data contract name 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfanyType' is already present.

该合同现在看起来是这样的:

The contract now looks like this:

[KnownType(typeof(NameValueCollection))]
[KnownType(typeof(CaseInsensitiveHashCodeProvider))]
[KnownType(typeof(CaseInsensitiveComparer))]
[KnownType(typeof(string[]))]
[KnownType(typeof(Object[]))]
[KnownType(typeof(ArrayList))]
[DataContract]
public class MyClassDataBase
{
    [DataMember]
    public NameValueCollection DataCollection = new NameValueCollection();
}



我真的不知道该怎么做才能够序列化我NameValueColletion。

I really dont know what to do to be able to serialize my NameValueColletion.

另一个奇怪的是,编译器警告说,CaseInsensitiveHashCodeProvider已经过时了。

Another strange thing is that the compiler warns that the CaseInsensitiveHashCodeProvider is deprecated.

推荐答案

最好的办法是停止使用弱类型,如的NameValueCollection 的ArrayList 。使用词典<字符串,字符串> 列表< T> 而不是

The best idea would be to stop using weak types like NameValueCollection and ArrayList. Use Dictionary<string,string> and List<T> instead.

这篇关于使用WCF的NameValueCollection序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆