[英]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.