【发布时间】:2012-06-18 21:26:18
【问题描述】:
我有一个 API 可以返回多个我事先不知道的东西,所以我必须将返回类型设为 System.Object。
我对某些类型有一些问题。就像当它返回不同的对象时它很好,但是当它返回 System.Int32 时,它不起作用并告诉我:
Cannot serialize parameter of type 'System.Int32' because it is not the exact type 'System.Object' in the method signature and is not in the known types collection.
有什么想法吗?
我知道我们可以使用 ServiceKnownType 但我想知道是否有其他方法可以做到这一点?我需要所有现有的类型(int、bool、string 等)...
【问题讨论】:
-
您是否对值类型有问题,但对引用类型没有问题? String 是引用类型,所以这很奇怪。
-
是值类型、int、double、long 等......当我的服务返回一个具有 int、double、long 等类型的对象时,它会犯这个错误。否则,没关系。