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