【发布时间】:2016-06-29 10:19:50
【问题描述】:
我已经实现了 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 自动实现。
-
我知道我不需要实现接口,我可以选择,但我喜欢保持代码干净,并且我不为接口提供两种方法的原因是每个或存在处理这种情况的更好方法
标签: c# wcf wcfserviceclient