This operation is not supported in wcf test client because it uses system.threading.tasks.task

.net c# entity-framework multithreading wcf


I'm trying to create an asynchronous method in my WCF service, but am getting the above subject error message. I simply want to return a list of Categories.

To be clear, tack on the following to the above error message at the end: YeagerTechModel.Category[]

The wcfclient service was added successfully except for this method (which has a red "X" next to it). In actuality, all of the methods (in the wcf service client) expect an associated asynchronous method (with red "X") in conjunction with the rest of the regular synchronous methods.

I know how to use WCF, but am not an expert in it. What do I need to do in order to get this functioning correctly?

I am using the full blown release version of VisualStudio 2013 and have the project using the 4.5.1 framework. I am also using EntityFramework 6.

My service contract has the following namespace included.

using System.Threading.Tasks;

My operation contract is as follows.

Task<List<Category>> GetCategoriesAsync();

My DataContract is as follows:

namespace YeagerTechModel
    using System;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Collections.Generic;

    [Serializable, DataContract(IsReference = true)] 
    public partial class Category
        public Category()
            this.Projects = new HashSet<Project>();

        public short CategoryID { get; set; }
        public string Description { get; set; }

        public virtual ICollection<Project> Projects { get; set; }

The method in my web service is as follows. Note that I don't have any design time compile errors and the solution is able to be built successfully:

public async Task<List<Category>> GetCategoriesAsync()
                using (YeagerTechEntities DbContext = new YeagerTechEntities())
                    DbContext.Configuration.ProxyCreationEnabled = false;

                    var category = await DbContext.Categories.ToListAsync();

                    return category;
            catch (Exception ex)
                throw ex;
10/29/2013 3:59:31 PM

Accepted Answer

Why are you making your service async? Async methods are created on the client side with the service reference. When you add a service reference to your service, mark the service reference as allow generation of asynchronous operations. With VS 2013 and .NET 4.5 you can either make task-based operations or asynchronous operations.

Then your client can call the async method to return a task and then future await the task to get the return object. Or call the begin method with a callback for when it finished the begin method call. Assumed is that you want client async calls. Those are made client side and not server side in the service code.

Example is shown on this post:

1/8/2014 10:21:14 PM

Popular Answer

Try to remove the suffix "Async" from your action. I believe it's reserved.

I cannot prove it, but I think something has silently changed with VS 2013 Update 1 since I remember I was unable to invoke Task actions and now I can.

public interface IXmlImportService
    Task<ImportResult> Import(ImportRequest request);

and here WCF Test Client using it.

WCF Test Client accessing a WCF service with async operations

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow