WCF在REST模式下工作,默认用xml序列化传输,可以切换到Json,兼容ajax直接使用。现在问题来了,如果设置BodyStyle为WebMessageBodyStyle.WrappedRequest或者干脆用默认值,就无法返回接口或者抽象类(Object)也不可以,它不会自动查找真实类型,即使你添加了ServiceKnownType也没用。为了解决这个BUG,必须将BodyStyle设置为WebMessageBodyStyle.Wrapped才行,xml序列化传输就正常,因此这肯定是BUG。

可以正常运行的示例代码:

[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[ServiceKnownType("GetKnownTypes", typeof(Helper))]
object EntityGet(string type, object id, string dbname);

 

相关文章:

  • 2021-11-01
  • 2022-01-12
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-03
  • 2021-09-14
  • 2022-12-23
相关资源
相似解决方案