Reputation: 1378
I developed my code based on this posting : Asynchronous Programming Model in WCF with async/await
There was no compilation error but when hosted it generates below specified error :
Type 'System.Threading.Tasks.Task`1[System.String]' cannot be serialized. Consid er marking it with the DataContractAttribute attribute, and marking all of its m embers 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.
What could be the reason for this.
Upvotes: 0
Views: 1700
Reputation: 20870
It looks like one of your methods is either returning a Task object, or has a Task object as one of its parameters.
Tasks cannot be passed across the web-service boundary - this is the cause of your problem.
Update: I had a look at the link you got this code from, and it looks like the code provided is conceptual only. If you look closely at the wording, he says 'will' instead of 'can'.
WCF vNext will adopt the Async model in both the client and the server side, and provide new Task-based overloads for some of the most used asynchronous APIs.
Since a Task cannot be passed over the web-service boundary, it will not work.
Upvotes: 1