0

I'm pretty new to WCF, so I might be missing something, but what is my question:

I have a WCF service to connect my two apps. One of the app (it is windows service) connects to external server, so I have asynchronous web requests in code. I wanted to do it in following way: I created callback interface with authorization method:

public interface ICommunicationServiceCallback
{
    [OperationContract(IsOneWay = true)]
    Task OnAuthorizeAsync(
        string username,
        string password,
        string proxyUrl = null,
        string proxyUsername = null,
        string proxyPassword = null);
}

And then I added service reference to my WS code. But instead if Task OnAuthorizeAsync method it generates void OnAuthorize method, so only way to make it work is having async void OnAuthorize method in implementation, which is bad.

How can I achieve my goal?

serjou
  • 17
  • 1
  • 9
  • For how to use asynchronous callbacks in WCF, you can refer to this link, which contains a demo: https://stackoverflow.com/questions/5979252/wcf-asynchronous-callback – Ding Peng Oct 07 '20 at 08:07
  • @DingPeng I saw this answer, but the problem is that in any case I get `void` returning method after adding service reference to project when I need method that returns `Task` – serjou Oct 07 '20 at 11:47
  • The generated client has nothing to do with the server in terms of asynchrony. Which tool are you using to generate the client? – Paulo Morgado Oct 07 '20 at 20:25
  • I'm just adding service reference – serjou Oct 08 '20 at 07:30
  • WCF have three asynchronous patterns: the task-based asynchronous pattern, the event-based asynchronous pattern, the IAsyncResult asynchronous pattern. The calling method for each asynchronous mode client is also different, for more information about it, you can refer to this link: https://learn.microsoft.com/en-us/dotnet/framework/wcf/synchronous-and-asynchronous-operations – Ding Peng Oct 09 '20 at 08:54

0 Answers0