I have a method exposed as an OperationContract for my WCF service that i would like to rework. The previous programmer had written something like:
我有一个方法暴露为我的WCF服务的OperationContract,我想重做。以前的程序员写过类似的东西:
public ReportResultObject GetReport(string stringContainingParameters)
I would like to have a method that is something more like this:
我想有一个更像这样的方法:
public ReportResultObject GetReport(int[] someIds, bool includeAdditionalInformation)
Since WCF doesnt allow for overloaded methods without specifying the Name attribute in the OperationContract, and I dont want to break current clients, is there a naming convention for situations like this? Something like GetReportV2 or GetReportHeyUseMeInstead ?
由于WCF不允许重载方法而不在OperationContract中指定Name属性,并且我不想打破当前客户端,是否存在这样的情况的命名约定?像GetReportV2或GetReportHeyUseMeInstead?
4 个解决方案
#1
By doing the same thing again you're just setting yourself up for the same "mess" when you need to add another parameter. I would strongly suggest that you look at having a single parameter which is a data contract;
通过再次做同样的事情,当你需要添加另一个参数时,你只需要为同样的“混乱”做好准备。我强烈建议您考虑使用单个参数作为数据合同;
public ReportResultObject GetReportTheSuperDooperWay(
GetReportParameters parameters)
What does this give you? Well
这给你带来了什么?好
[DataContract]
public class GetReportParameters
{
[DataMember(IsRequired=false)]
public string parameters;
[DataMember(IsRequired=false)]
public int[] someIds;
[DataMember(IsRequired=false)]
bool includeAdditionalInformation
}
So because each field is optional you can add new fields without breaking existing clients. This is a rather simplistic example, as you'll also want to implement IExtensibleDataObject too and you should be versioning via namespaces at both the service and data contract levels.
因此,因为每个字段都是可选的,所以您可以在不破坏现有客户端的情这是一个相当简单的示例,因为您还需要实现IExtensibleDataObject,并且您应该在服务和数据协定级别通过命名空间进行版本控制。
#2
I'd go with something that made sense, making it more likely that people would recognise it and use it appropriately.
我会选择一些有意义的东西,让人们更有可能认出它并适当地使用它。
public ReportResultObject GetReportWithAdditionalInformation(...)
might be a bit too much though!
可能有点太多了!
I'd certainly avoid GetReportV2
or similar.
我当然会避免使用GetReportV2或类似的东西。
#3
Create a new operationalcontract and add a namespace to it. Then have your clients using the new contract call it by the way of the namespace. This will simulate versioning.
创建一个新的Operationalcontract并为其添加命名空间。然后让您的客户使用新合约通过命名空间的方式调用它。这将模拟版本控制。
#4
If your WCF service is RESTful, does it matter if bool includeAdditionalInformation
is passed or not?
如果您的WCF服务是RESTful,那么是否传递bool includeAdditionalInformation是否重要?
#1
By doing the same thing again you're just setting yourself up for the same "mess" when you need to add another parameter. I would strongly suggest that you look at having a single parameter which is a data contract;
通过再次做同样的事情,当你需要添加另一个参数时,你只需要为同样的“混乱”做好准备。我强烈建议您考虑使用单个参数作为数据合同;
public ReportResultObject GetReportTheSuperDooperWay(
GetReportParameters parameters)
What does this give you? Well
这给你带来了什么?好
[DataContract]
public class GetReportParameters
{
[DataMember(IsRequired=false)]
public string parameters;
[DataMember(IsRequired=false)]
public int[] someIds;
[DataMember(IsRequired=false)]
bool includeAdditionalInformation
}
So because each field is optional you can add new fields without breaking existing clients. This is a rather simplistic example, as you'll also want to implement IExtensibleDataObject too and you should be versioning via namespaces at both the service and data contract levels.
因此,因为每个字段都是可选的,所以您可以在不破坏现有客户端的情这是一个相当简单的示例,因为您还需要实现IExtensibleDataObject,并且您应该在服务和数据协定级别通过命名空间进行版本控制。
#2
I'd go with something that made sense, making it more likely that people would recognise it and use it appropriately.
我会选择一些有意义的东西,让人们更有可能认出它并适当地使用它。
public ReportResultObject GetReportWithAdditionalInformation(...)
might be a bit too much though!
可能有点太多了!
I'd certainly avoid GetReportV2
or similar.
我当然会避免使用GetReportV2或类似的东西。
#3
Create a new operationalcontract and add a namespace to it. Then have your clients using the new contract call it by the way of the namespace. This will simulate versioning.
创建一个新的Operationalcontract并为其添加命名空间。然后让您的客户使用新合约通过命名空间的方式调用它。这将模拟版本控制。
#4
If your WCF service is RESTful, does it matter if bool includeAdditionalInformation
is passed or not?
如果您的WCF服务是RESTful,那么是否传递bool includeAdditionalInformation是否重要?