Webservice XMLSerialization Question
-
hi there, I'm currently building a webservice and I've got three questions: is there anything special i need to know about the returned xml? right now, I just return an object (for expample an instance of my Vehicle class) from the WebMethod and this looks fine to me. The second question is, if I use the automated xml serialization with a class which is derived from a base class I defined (e.g. I've got a Car class which derives from the Vehicle class), the properties of the baseclass are not serialized. Properties of the derived class look fine. Why is that? Last but not least: What is the correct way to return an error from a WebMethod if, for example the expected parameters are invalid or an exception occured. thanks a lot!
/matthias
I love deadlines. I like the whooshing sound they make as they fly by.
[Douglas Adams] -
hi there, I'm currently building a webservice and I've got three questions: is there anything special i need to know about the returned xml? right now, I just return an object (for expample an instance of my Vehicle class) from the WebMethod and this looks fine to me. The second question is, if I use the automated xml serialization with a class which is derived from a base class I defined (e.g. I've got a Car class which derives from the Vehicle class), the properties of the baseclass are not serialized. Properties of the derived class look fine. Why is that? Last but not least: What is the correct way to return an error from a WebMethod if, for example the expected parameters are invalid or an exception occured. thanks a lot!
/matthias
I love deadlines. I like the whooshing sound they make as they fly by.
[Douglas Adams]The answer to question 1 is that you don't pass the object. Whenever you pass something back from a web-service, you are passing based on a contract. This is important. Basically, you say that your data will look like this, and the SOAP message will contain a representation of that object. 2. Is the base class marked as Serializable as well? 3. It really depends on what you want to achieve. It is perfectly legitimate to throw an exception back from a web-service, but be aware that the exception you get back will not be the exception you threw. (Go on, try it - you'll get a SOAP exception back).
Deja View - the feeling that you've seen this post before.
-
The answer to question 1 is that you don't pass the object. Whenever you pass something back from a web-service, you are passing based on a contract. This is important. Basically, you say that your data will look like this, and the SOAP message will contain a representation of that object. 2. Is the base class marked as Serializable as well? 3. It really depends on what you want to achieve. It is perfectly legitimate to throw an exception back from a web-service, but be aware that the exception you get back will not be the exception you threw. (Go on, try it - you'll get a SOAP exception back).
Deja View - the feeling that you've seen this post before.
hey pete, thanks for your reply. as for 1: i understand that my object makes up the contract you've mentioned (the structure of the returned xml). So I believe I as long as I don't change my returned object, everything should work fine for my clients. how would you do it? whats the best practise. in the article of chris (http://www.codeproject.com/cs/webservices/myservice.asp[^]), he's doing the same and the documentation doesn't really give me any useful information. as for 2: yes, it has the
SerializableAttribute
. 3: I'd like to tell my clients, well, if you have no permission, you'll get this type of response, if you passed in invalid arguments, you'll get that type of exception. my english is not so good, I hope you understand what I mean./matthias
I love deadlines. I like the whooshing sound they make as they fly by.
[Douglas Adams]