简体   繁体   English

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

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

I have implemented WCF Services, I have defined synchronize method as following; 我已经实现了WCF服务,我已经定义了同步方法,如下所示;

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

    [OperationContract]
    MarketingCampaignTypeData GetCampaignTypeByID(int CampaignTypeID);

    [OperationContract]
    MarketingCampaignTypeData CreateNewCampaignType();

    [OperationContract]
    MarketingCampaignTypeData EditCampaignType();

    [OperationContract]
    bool DeleteCampaignType();
}

Now on client side when I configure this service by choosing 'Add Service Reference' in visual studio under project, interface is generated under namespace 'App.Client.Proxies.MarketingCampaignTypeServiceRef' 现在在客户端,当我通过在项目下的Visual Studio中选择“添加服务引用”来配置此服务时,将在名称空间“ App.Client.Proxies.MarketingCampaignTypeServiceRef”下生成界面。

but when I am implement this interface I am getting two of each methods for each implementation one synchronous and other asynchronous. 但是当我实现此接口时,我为每种实现都使用了两种方法,一种是同步的,另一种是异步的。 I know that in client only you choose which one you want to implement but my question can I can control which one I am allowing or just have one type of method instead of two? 我知道只有在客户端中,您才能选择要实现的方法,但是我的问题可以控制我允许的一种方法,还是只有一种方法而不是两种?

here is interface implementation of service 这是服务的接口实现

 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();
    }

Make sure, you have unchecked this in your Serviceconfig: 确保已在Serviceconfig中取消选中此选项:

禁用异步

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM