gpt4 book ai didi

wcf - 为什么我会收到此 WCF 错误消息?

转载 作者:行者123 更新时间:2023-12-04 05:27:56 24 4
gpt4 key购买 nike

当我调用我的 WCF 服务时,我收到以下错误。我在这里缺少什么?

'System.String[]' with data contract name
'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays'
is not expected. Add any types not known statically to the list of known
types - for example, by using the KnownTypeAttribute attribute or by adding
them to the list of known types passed to DataContractSerializer.'. Please
see InnerException for more details.

{"There was an error while trying to serialize parameter
http://tempuri.org/:myEntity. The InnerException message was
'Type 'System.String[]' with data contract name
'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays'
is not expected. Add any types not known statically to the list of known
types - for example, by using the KnownTypeAttribute attribute or by adding
them to the list of known types passed to DataContractSerializer.'.

Please see InnerException for more details."}

最佳答案

据我所知,您有一个 WCF 函数,它有一个名为“myEntity”的参数。我假设 myEntity 的类型是一个用户定义的类,并且用 DataContract 属性装饰,这是应该的。我还假设 myEntity 的类型有一个成员字段,它是一个字符串数组。让我们假设所有这些都是真的(同样,如果您可以发布代码,那将非常有帮助)。

通常,字符串数组,即 string[],会很好地序列化。但是,在某些情况下(请参阅 herehere ),您可能必须将其添加到已知类型列表中,以便 WCF 正确序列化所有内容。

为此,请添加以下内容:

[DataContract]
[KnownType(typeof(string[]))]
public class YourClassNameHere
{
}

关于wcf - 为什么我会收到此 WCF 错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/800358/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com