Question

This should be easy for someone familiar with the best practices of versioning service/data contracts. I want to make sure that I will use this versioning in the correct way.

So, let's say we have a service contract:

[ServiceContract(Namespace="http://api.x.com/Svc1")]
public interface IService1
{
   [OperationContract(Name = "AddCustomer")]
   bool AddCustomer(DTOCustomer1 customer);
}

and data contract:

[DataContract(Name="Customer", Namespace="http://api.x.com/Svc1/2011/01/DTO")]
public class DTOCustomer1
{
   [DataMember(Name="Name")]
   public string Name { ... }
}

if I really need to change the latter into something else: (the following is just example)

[DataContract(Name="Customer", Namespace="http://api.x.com/Svc1/2012/01/DTO")]
public class DTOCustomer2
{
   [DataMember(Name="Name")]
   public string Name { ... }

   [DataMember(Name="Address")]
   public DTOAddress Address { ... }
}

...then how shall I use DTOCustomer2 instead of DTOCustomer1 from the service so that old and new clients will be compliant? What is recommended in this case? Will my service contract change? AFAIK I won't need to change the service contract. How will the service contract look like? Do I need a new endpoint? Do I need a new operation contract making use of the new data contract?

EDIT1: Simply changing

bool AddCustomer(DTOCustomer1 customer);

into

bool AddCustomer(DTOCustomer2 customer);

will do?

EDIT2: Answer to EDIT1 is No, since DTOCustomer2 has different namespace, but it might work if it has the same namespace. Still I don't know what is the best thing here and expect somebody to come up with a good answer.

Thank you in advance!

Was it helpful?

Solution

I ended up answering to this question with the help of another question here: WCF - handle versioning

OTHER TIPS

Please find some useful links that describe the best practise for Data contract versioning.

  1. Best Practices: Data Contract Versioning
  2. Data Contract Versioning

The 2nd link describes on how you handle when you want to add or removed attributes of your data contract and few other scenarios.

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top