我已经实现了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();
}
咦?你为什么要实施它们?它们由Visual Studio自动实现。 – nvoigt
我知道,我不需要实现接口,我可以选择,但我喜欢保持代码清洁,并且我不服务接口的原因给出每个方法的两个或有更好的方法来处理这种情况 – toxic