Cannot have two operations in the same contract with the same name (Async & Non)

后端 未结 5 1697
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 15:15

I get the following exception (Cannot have two operations in the same contract with the same name, methods ExecuteAsync and Execute) when the following service is activated.

5条回答
  •  悲&欢浪女
    2021-01-01 16:01

    You can declare either, but not both. WCF will automatically make either method work in the generated channel proxy -- you can connect an interface that uses an async method to an implementation that uses a sync one, and vice versa.

    If you want to share the interface definition across client and server code (which is not unreasonable) and have to settle for one, your best bet is the async one: offering only sync means async clients must waste a thread, while offering only async means callers have the choice to block and waste the thread themselves if they have to. As calling a WCF service involves I/O, you definitely want to give the client the option for async, even if the server has a sync implementation.

提交回复
热议问题