Locally augmenting a partial class
-
3 มีนาคม 2555 22:42
Tell me if this is possible or if I am pursuing the right approach.
I have a set of XSDs that define various types. I notice that when the xsd tool generates classes from these XSDs all of the classes are 'partial'. So theoretically I could augment these classes with method or members that are not a part of the original XSD definition. The question comes when the objects are serialized/deserialized from a service that does not share my augmented class. So when I use the XmlSerializer class with a typeof(X) X will be the augmented type (because that is what I have access to) but the serial bytes coming from the web service will have no knowledge of any change to the class. When I deserialize such a stream what values will the added members take on? Will I even be able to deserialize the stream since the definition of the type differs? Hopefully the added members will take on a 'default' value (NULL or zero). What about the other way around? If I try to serialize the augmented type the serial stream will contain serial versions of the members that I have added. When the web service deserializes the stream will it just throw away the members that it doesn't know about?
Thank you.
Kevin
Kevin Burton
ตอบทั้งหมด
-
4 มีนาคม 2555 19:04ผู้ดูแล
With ASMX services, no class you create on the server will ever be seen on the client, and vice versa.
See Basics: How Web Services Work.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
4 มีนาคม 2555 19:50
I don't want the class to be seen on the server. I was more concerned that an error/exception would occur if I tried to deserialize to a type that has been changed on the client side or if I serialized an augmented type what the server would do with the extra serialization information. If the server sees this extra information would it also throw an exception?
Kevin
Kevin Burton
-
4 มีนาคม 2555 23:02ผู้ดูแล
Simply don't add any public read/write properties, or if you do, decorate them with [XmlIgnore].John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects- ทำเครื่องหมายเป็นคำตอบโดย KevinBurton 7 มีนาคม 2555 21:52