简体   繁体   中英

Cannot implicity convert type void to System.Threading.Tasks.Task<bool>

I have a WCF Service that contains the following method. All the methods in the service are asynchrounous and compile just fine.

public async Task<Boolean> ValidateRegistrationAsync(String strUserName)
{
    try
    {
        using (YeagerTechEntities DbContext = new YeagerTechEntities())
        {
            DbContext.Configuration.ProxyCreationEnabled = false;
            DbContext.Database.Connection.Open();

            var reg = await DbContext.aspnet_Users.FirstOrDefaultAsync(f => f.UserName == strUserName);

            if (reg != null)
                return true;
            else
                return false;
        }
    }
    catch (Exception)
    {
        throw;
    }
}

My client application was set to access the WCF service with the check box for the "Allow generation of asynchronous operations" and it generated the proxy just fine.

I am receiving the above subject error when trying to call this WCF service method from my client with the following code. Mind you, I know what the error message means, but this is my first time trying to call an asynchronous task in a WCF service from a client.

Task<Boolean> blnMbrShip = db.ValidateRegistrationAsync(FormsAuthentication.Decrypt(cn.Value).Name);

What do I need to do to properly call the method so the design time compile error disappears?

The WCF proxy is old; try to re-create the proxy with a newer (VS2012/VS2013) proxy generator.

Specifically, it is generating Event-based Asynchronous Pattern endpoints, and you need Task-based Asynchronous Pattern endpoints.

If this is for a Silverlight client, then the auto-generated proxy will refuse to create TAP methods. In that case, you'd need to write your own wrappers (which are pretty easy , just rather tedious).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM