tags:

views:

333

answers:

4

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:

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 ?

+1  A: 

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.

ChrisF
A: 

If your WCF service is RESTful, does it matter if bool includeAdditionalInformation is passed or not?

mattRo55
It does use REST in some instances, but all other protocols (tcp, ipc and ws HTTP) will be used as well.
Mike_G
+5  A: 

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.

blowdart
A: 

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.

David Yancey