且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-11-30 16:17:54

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

From what I gather, you have a WCF function that has a parameter named 'myEntity'. I'm assuming that the type of myEntity is a user-defined class and is adorned with the DataContract attribute, as it should be. I'm also assuming that the type of myEntity has a member field that is a string array. Let's assume that all of this is true (again, it'd be really helpful if you could post your code).

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

Ordinarily, string arrays, i.e., string[], will serialize just fine. But, in some cases (see here and here), you may have to add it to the list of known types in order for WCF to serialize everything correctly.

为此,添加以下内容:

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