扩展方法的WCF命名约定

Mik*_*e_G 2 .net c# wcf

我有一个方法暴露为我的WCF服务的OperationContract,我想重做.以前的程序员写过类似的东西:

public ReportResultObject GetReport(string stringContainingParameters)
Run Code Online (Sandbox Code Playgroud)

我想有一个更像这样的方法:

public ReportResultObject GetReport(int[] someIds, bool includeAdditionalInformation)
Run Code Online (Sandbox Code Playgroud)

由于WCF不允许重载方法而不在OperationContract中指定Name属性,并且我不想打破当前客户端,是否存在这样的情况的命名约定?像GetReportV2或GetReportHeyUseMeInstead?

blo*_*art 6

通过再次做同样的事情,当你需要添加另一个参数时,你只需要为同样的"混乱"做好准备.我强烈建议您考虑使用单个参数作为数据合同;

public ReportResultObject GetReportTheSuperDooperWay(
    GetReportParameters parameters)
Run Code Online (Sandbox Code Playgroud)

这给你带来了什么?好

[DataContract]
public class GetReportParameters
{
 [DataMember(IsRequired=false)]
 public string parameters;

 [DataMember(IsRequired=false)]
 public int[] someIds;

 [DataMember(IsRequired=false)]
 bool includeAdditionalInformation
}
Run Code Online (Sandbox Code Playgroud)

因此,因为每个字段都是可选的,所以您可以在不破坏现有客户端的情 这是一个相当简单的示例,因为您还需要实现IExtensibleDataObject,并且您应该在服务数据协定级别通过命名空间进行版本控制.