高版本.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>
。
解決方案
-
關閉生成異步方法
svcutil /syncOnly
-
手動刪除生成結果的XXXAsync方法