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

  • Question

  • User-1355356054 posted

    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?

    Thanks so much in advance...

    The generated proxy code is as follows:

    public void ValidateRegistrationAsync(string strUserName) { this.ValidateRegistrationAsync(strUserName, null)};

    I'm expecting it to return a Boolean. I don't know whether I have the WCF service method or the client code incorrect.       

    Friday, November 8, 2013 4:53 PM

Answers

  • User1519735232 posted

    Hi,

    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).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 12, 2013 2:57 AM
  • User-488622176 posted

    Probably you modified the service implementation after you added the service reference to the client. The client does not get updated automatically.

    Remove the client service reference, and add it again. Your return type should be correct.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 12, 2013 8:03 AM

All replies

  • User1519735232 posted

    Hi,

    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).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 12, 2013 2:57 AM
  • User-488622176 posted

    Probably you modified the service implementation after you added the service reference to the client. The client does not get updated automatically.

    Remove the client service reference, and add it again. Your return type should be correct.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 12, 2013 8:03 AM