2016-06-29 74 views
1

我已經實現了WCF服務,我已經定義瞭如下的同步方法;如何避免在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中的「添加服務引用」下的項目配置此服務,則在命名空間「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(); 
    } 
+0

咦?你爲什麼要實施它們?它們由Visual Studio自動實現。 – nvoigt

+0

我知道,我不需要實現接口,我可以選擇,但我喜歡保持代碼清潔,並且我不服務接口的原因給出每個方法的兩個或有更好的方法來處理這種情況 – toxic

回答

1

確保,您已在Serviceconfig未選中此選項:

Disable async

+0

非常感謝,這給了我解決方案 – toxic