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

后端 未结 5 1704
被撕碎了的回忆
被撕碎了的回忆 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:08

    Here's what I did. I have two separate contracts. One for the client and one for the server:

    namespace ServiceLibrary.Server
    {
        [ServiceContract]
        public interface IMyService
        {
            [OperationContract]
            byte[] Execute(MyRequest request);
        }
    }
    
    namespace ServiceLibrary.Client
    {
        [ServiceContract]
        public interface IMyService : Server.IMyService
        {
            [OperationContract]
            Task ExecuteAsync(MyRequest request);
        }
    }
    

    Because both ServiceContracts share the same name, the OperationContracts' Action and ReplyAction are the same for the async and sync methods. The client now has both the sync and async version and the server stays unmodified.

提交回复
热议问题