This workaround can be used to create task-based wcf async client in .NET 4.0
- Open NuGet and add Microsoft.Bcl.Async package to .Net 4.0 project
- Create a new solution with a new .Net 4.5 project with the same name as your .Net 4.0 project
- Add the service link (to the desired web service) with the same name as the service link created in the .Net 4.0 project
- Make sure that the option "Create tasks based on tasks" in the "Allow creation of asynchronous operations" section is checked in the advanced settings dialog
- Open the help folder for your .Net 4.5 project service ("NET_4.5_PROJECT_FOLDER \ List of Services \ YOUR__SERVICE_REFERENCE_FOLDER \")
- Copy all files from the folder
- Open the help folder for your .Net 4.0 project service ("NET_4.0_PROJECT_FOLDER \ List of Services \ YOUR__SERVICE_REFERENCE_FOLDER \")
- Paste the files (in the .Net 4.0 service help folder) that you copied earlier (from the .Net 4.5 service help folder)
In conclusion, you must create a link to the service in .Net 4.5 and copy it into the .Net 4.0 project. Be sure to add the Microsoft.Bcl.Async package to your .Net 4.0 project.
EDIT
I found that this workaround only works when installing the .NET Framework 4.5 on the computer. If you run the program on a computer with the .Net Framework 4.0 installed, it does not work (Windows XP is not supported in the .Net Framework 4.5, so this is a good environment for testing the program). This exception occurs when the .NET Framework 4.0 is not installed:
The type 'System.Threading.Tasks.Task`1 [System.Boolean]' cannot be serialized. Consider labeling it with the DataContractAttribute attribute and labeling all of its elements that you want to serialize with the DataMemberAttribute attribute. If the type is a collection, consider labeling it with CollectionDataContractAttribute. See the Microsoft.NET Framework documentation for other supported types.
To summarize, this is a bad workaround .
source share