Serialization questions.
-
Hi fellow developers. I come with 2 questions today around the area of serialization. I would normally try these things out myself, but I am away from my development machine today and I was wondering you if you could provide some assistance. If you added a new property to an existing class that your web service serializes and returns to clients, would it break for existing clients? If you changed the data type of an existing property of an existing class that your web service serialises and sends to clients, would it break for existing clients? Many thanks, TF
-
Hi fellow developers. I come with 2 questions today around the area of serialization. I would normally try these things out myself, but I am away from my development machine today and I was wondering you if you could provide some assistance. If you added a new property to an existing class that your web service serializes and returns to clients, would it break for existing clients? If you changed the data type of an existing property of an existing class that your web service serialises and sends to clients, would it break for existing clients? Many thanks, TF
Hi, Adding a new property would normally not break existing clients. Since this is a web service and the client might consume the soap-formatted XML responses in any way there is no guarantee. For example, a client *could* have been implemented in such a way that it assumes the fifth childnode of some element to be "dateOfBirth" and parse it's text as a date, and this would obviously fail if the message format changed so that dob no longer was the fifth childnode. However, part of the point of using XML is of course to enable to use the node names instead, so picking nodes by index is bad practice. Changing the type of an existing property is much more likely to break existing clients, though it need not always happen. Again things are fuzzy since a client could be implemented in any of a number of technologies, and with any number of tools. Changing from "int" to "byte" might be safe, but might not. I don't know the type definitions in W3C's standards, but generally the only safe changes you can make (that cannot break properly implemented clients) would be thos that result in the property still mapping to the same type in the SOAP message. You might be thinking of only a subset of the possible clients though, such as .NET clients generated with Visual Studio. Even then there are a few varieties; at least two: WCF clients configured to connect to a web service endpoint, and "pure" web service clients. Adding a property to a class won't affect such clients. Changing the type will also be fine as long as the values actually returned from the service are valid for the old type. Changing from Int32 to byte for example breaks nothing (but also doesn't achieve much), while changing from int to double works (but is pointless) only so long as the values returned fit in an int.