In Visual Studio 2012 there is a handy "Generate task-based operations" option that you can use to generate Task
and Task<T>
versions of WCF service calls.
I am using the Microsoft.Bcl.Async NuGet package to take advantage of async/await in my .NET 4.0 project. However, I seem to be unable to generate the Task-based operations using the Configuration Service Reference wizard in VS 2012 (the option is disabled).
As far as I can tell this only works if the project targets .NET 4.5. Does anyone know of a way to generate the Task-based operations with a .NET 4.0 client?
You can use this workaround to create async task-based wcf client in .Net 4.0
In conclusion, you have to generate the service reference in .Net 4.5 and copy it to your .Net 4.0 project. It is mandatory to add the "Microsoft.Bcl.Async" package to your .Net 4.0 project.
EDIT
I have discovered that this workaround only works if .Net Framework 4.5 is installed on the computer. If you run the program in a computer with .Net Framework 4.0 installed it doesn't work (Windows XP is not supported in .Net Framework 4.5, so it is a good environment to test the program). This exception is thrown when .Net Framework 4.0 is not installed:
Type 'System.Threading.Tasks.Task`1[System.Boolean]' 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.
Summing up, it is not a good workaround.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With