如何避免在 WCF 服务接口中实现同步或异步方法

how to avoid in WCF service interface to implementing either synchronous or asynchronous Method

我已经实现了 WCF 服务,我定义了如下同步方法;

[ServiceContract]
public interface IMarketingCampaignType
{
    [OperationContract]
    List<MarketingCampaignTypeData> GetAllCampaignTypes();

    [OperationContract]
    MarketingCampaignTypeData GetCampaignTypeByID(int CampaignTypeID);

    [OperationContract]
    MarketingCampaignTypeData CreateNewCampaignType();

    [OperationContract]
    MarketingCampaignTypeData EditCampaignType();

    [OperationContract]
    bool DeleteCampaignType();
}

现在在客户端,当我通过在项目下的 visual studio 中选择 'Add Service Reference' 配置此服务时,在命名空间 'App.Client.Proxies.MarketingCampaignTypeServiceRef'

下生成接口

但是当我实现这个接口时,我为每个实现获得了两种方法,一种是同步的,另一种是异步的。我知道在客户端中只有你选择你想要实现的一个但是我的问题是我可以控制我允许哪个或者只有一种方法而不是两种方法?

这里是服务的接口实现

 public class MarketingCampaignTypeClient : IMarketingCampaignType
 {
    public MarketingCampaignTypeData CreateNewCampaignType()
    {
        throw new NotImplementedException();
    }

    public Task<MarketingCampaignTypeData> CreateNewCampaignTypeAsync()
    {
        throw new NotImplementedException();
    }

    public bool DeleteCampaignType()
    {
        throw new NotImplementedException();
    }

    public Task<bool> DeleteCampaignTypeAsync()
    {
        throw new NotImplementedException();
    }

    public MarketingCampaignTypeData EditCampaignType()
    {
        throw new NotImplementedException();
    }

    public Task<MarketingCampaignTypeData> EditCampaignTypeAsync()
    {
        throw new NotImplementedException();
    }

    public MarketingCampaignTypeData[] GetAllCampaignTypes()
    {
        throw new NotImplementedException();
    }

    public Task<MarketingCampaignTypeData[]> GetAllCampaignTypesAsync()
    {
        throw new NotImplementedException();
    }

    public MarketingCampaignTypeData GetCampaignTypeByID(int CampaignTypeID)
    {
        throw new NotImplementedException();
    }

    public Task<MarketingCampaignTypeData> GetCampaignTypeByIDAsync(int CampaignTypeID)
    {
        throw new NotImplementedException();
    }

确保您在服务配置中取消选中此选项: