Asynchronously consume synchronous WCF service

后端 未结 3 566
北荒
北荒 2020-12-08 02:58

I’m currently in the process of migrating a client application over to .NET 4.5 to make use of async/await. The application is a client for a WCF service which currently off

3条回答
  •  -上瘾入骨i
    2020-12-08 03:51

    This isn't horrible: https://stackoverflow.com/a/23148549/177333. You just wrap your return values with Task.FromResult(). You have to change the service side, but it's still synchronous and you're not using an extra thread. That changes your server-side interface which can still be shared with the client so it can wait asynchronously. Otherwise it looks like you have to maintain separate contracts on server and client somehow.

提交回复
热议问题