【发布时间】:2017-03-06 08:39:53
【问题描述】:
我正在尝试将字典发送到 WCF 服务。但是,如果对象类型是数组或列表,它会显示错误“尝试序列化参数时出现错误......”
尝试序列化参数时出错 http://tempuri.org/:str。 InnerException 消息是“类型 带有数据合同名称的“System.String[]” 'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' 预计不会。将任何静态未知的类型添加到列表中 已知类型 - 例如,通过使用 KnownTypeAttribute 属性 或者通过将它们添加到传递给的已知类型列表中 DataContractSerializer.'。有关详细信息,请参阅 InnerException。
这是我的 WCF 服务:
[OperationContract]
int PDFImport(string server,
string repo,
string username,
string password,
string templateName,
string entryName,
byte[] image,
Dictionary<string, Object> value,
string entryPath = @"\1. Incoming",
string volume = "DEFAULT");
也尝试添加一些 ServiceKnowType 属性,但还是不行
[ServiceContract]
[ServiceKnownType(typeof(Dictionary<string, string>))]
[ServiceKnownType(typeof(Dictionary<string, object>))]
[ServiceKnownType(typeof(Dictionary<string, List<string>>))]
[ServiceKnownType(typeof(List<Dictionary<string, List<string>>>))]
请帮帮我。提前致谢。
【问题讨论】:
-
为什么需要发送类型对象?
-
我认为他正在发送 System.String[] 作为对象。它在内部异常消息中说。
-
这是我第一次写WCF服务。它用于与一个 ECM 软件进行通信。因此,对于 Dictionary
,字符串表示模板名称,而对象用于值(可以是 DateTime、int、double、list、array 等),这就是我传递对象类型的原因. -
int、double、float 和其他 premitive 类型应该可以正常工作。 DateTime 是一个结构,这也应该没问题。 List
和 ArrayList 不起作用。
标签: c# wcf dictionary