简体   繁体   English

无法将类型void隐式转换为System.Threading.Tasks.Task <bool>

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

I have a WCF Service that contains the following method. 我有一个WCF服务,其中包含以下方法。 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. 我的客户端应用程序被设置为使用“允许异步操作生成”复选框访问WCF服务,并且它生成的代理很好。

I am receiving the above subject error when trying to call this WCF service method from my client with the following code. 尝试使用以下代码从客户端调用此WCF服务方法时,收到上述主题错误。 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. 请注意,我知道错误消息的含义,但这是我第一次尝试从客户端调用WCF服务中的异步任务。

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; WCF代理较旧; try to re-create the proxy with a newer (VS2012/VS2013) proxy generator. 尝试使用更新的(VS2012 / VS2013)代理生成器重新创建代理。

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. 如果这是针对Silverlight客户端的,则自动生成的代理将拒绝创建TAP方法。 In that case, you'd need to write your own wrappers (which are pretty easy , just rather tedious). 在这种情况下,您需要编写自己的包装器(这很简单 ,很繁琐)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将类型&#39;void&#39;隐式转换为&#39;System.Threading.Tasks.Task&#39; - Cannot implicitly convert type 'void' to 'System.Threading.Tasks.Task' 无法将类型&#39;bool&#39;隐式转换为&#39;System.Threading.Tasks.Task&#39; - Cannot implicitly convert type 'bool' to 'System.Threading.Tasks.Task' 无法将类型&#39;bool&#39;隐式转换为&#39;system.threading.tasks.task bool&#39; - Cannot implicitly convert type 'bool' to 'system.threading.tasks.task bool' 无法将布尔类型隐式转换为System.Threading.Tasks.Task <bool> - Cannot implicitly convert type bool to System.Threading.Tasks.Task<bool> 无法隐式转换类型&#39;System.Threading.Tasks.Task - Cannot implicitly convert type 'System.Threading.Tasks.Task 无法将 System.Threading.Tasks.Task... 转换为 System.Threading.Tasks.Task... 尽管看似相同的类型 - Cannot convert System.Threading.Tasks.Task… to System.Threading.Tasks.Task… despite seemingly being same type 无法从“无效”转换为System.Threading.Tasks.Task <System.Action> - Cannot convert from 'void' to System.Threading.Tasks.Task<System.Action> C#无法从&#39;void&#39;转换为&#39;System.Threading.Tasks.Task - C# Cannot convert from 'void' to 'System.Threading.Tasks.Task 无法将类型&#39;System.Collections.Generic.List &lt;&gt;&#39;隐式转换为&#39;System.Threading.Tasks.Task &lt;&gt;&gt; - Cannot implicitly convert type 'System.Collections.Generic.List<>' to 'System.Threading.Tasks.Task<>> “System.Func`1[System.Threading.Tasks.Task]”类型的表达式不能用于返回类型“System.Threading.Tasks.Task” - Expression of type 'System.Func`1[System.Threading.Tasks.Task]' cannot be used for return type 'System.Threading.Tasks.Task'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM