tags:

views:

78

answers:

1

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.

+2  A: 

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:

[...attributes...]
public Car[] GetCars2()

i.e. only the callers of the new GetCars2 method will ever see SportsCar results. 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.

Marc Gravell
Thanks - I thought (but hoped not!) that this would be the case.
ng5000