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方法





posted on 2015-08-09 00:35  畅想者  阅读(1390)  评论(4编辑  收藏  举报

导航