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

标签 wcf web-services

当我调用我的 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/

相关文章:

.net - 带有 WCF 的 JSON-P 示例?

javax.xml.ws.WebServiceException : Method X is exposed as WebMethod, 但是没有对应的wsdl操作

WCF:限制每小时的调用次数 - 每个用户

java - 获取异常 java.lang.NoSuchMethodError : org. apache.neethi.Constants.isPolicyElement

r - 无法通过 SSOAP 在 R 中使用 Web 服务功能

java - SOAP 规范化变换

c# - 集合被修改;枚举操作可能无法执行

c# - 处理 WCF 服务中的异常?

wcf - 带有 Windows 容器的 Docker 在 tcp 服务上支持 wcf

c# - ChannelFactory.CreateChannel() 是否真的打开了连接?