WCF开发笔记 高版本.Net的坑


高版本.Net的坑

开发环境

.Net 4.5.1
Visual Studio 2015RC
Windows 8.1
SQL Server 2005 sp1

运行环境

.Net 4.0 en
Windows Server 2003
SQL Server 2005 sp1

现象

 

 

WCF客户端,开发环境测试正常。发布到运行环境后,提示Type 'System.Threading.Tasks.Task`1[XXXResponse]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

原因

Visual Studio 2012以上版本的svcutil默认情况下会生成XXXAsync的调用方法。类似System.Threading.Tasks.Task<T>。但是在运行环境,.Net4.0不支持Task<T>

解决方案

  1. 关闭生成异步方法

    1. svcutil /syncOnly
  2. 手动删除生成结果的XXXAsync方法






免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM