If I have a web service method, e.g.
[WebMethod] [XmlInclude(typeof(SportsCar)), XmlInclude(typeof(FamilyCar))] public Car[] GetCars() { Car[] cars = new Car[2]; cars[0] = new FamilyCar(); cars[1] = new SportsCar(); return cars; }
If I want to add a new car type to my service, I would have to add a new XmlInclude attribute to the web method. Unfortunately the clients (AFAIK) would now need to update their web service reference, rebuild and re-deploy. Otherwise they would get an XML document generation error.
What strategies exist to deal with this?
Thanks.
If you have clients that can’t yet understand the different cars, perhaps the most reliable option is to treat it as closed, and add a separate method:
i.e. only the callers of the new
GetCars2method will ever seeSportsCarresults. Taking this to the extreme, you could have a v2 endpoint, and leave the original v1 unchanged. You can then migrate clients to the new API as-and-when.