Serialization of derived classes

A

Angel

I have a Web service that has a method returning a class, so complex
type.
This class is serializable. It works just fine.

I created a secoind method that returns a class derived from the first
one.
The SOAP response lists only the extra fields I added. The fields from
the
base class are not shown. I would like to have all fields included in
the
SOAP response. What should I do ?
 
J

Josh Twist

WSDLs have inheritence too (from XSD) so normally, inherited classes
should work just fine, but only the extra fields in the complex type
are displayed.

if you have two classes ClassA and ClassB where ClassB inherits ClassA
- you'd expect to see something like this in the WSDL:

<s:complexType name="ClassB">
<s:extension base="s0:ClassA">
<s:sequence>
<!-- the additional properties added by ClassB go here -->
</s:sequence>
</s:extension>
</s:complexType>

The s:extension node is essentially inheritence - says this class (B)
extends class A.

Does that help? Have you tried your service? Are you sure that
something is wrong?
 
R

Richard Purchas

XML serialization has problems such as this (and other issues, such as not
serializing private fields etc.). One option is to binary serialize the
custom class and pass as array of byte. This has worked well for me, and
also suppresses generation of proxies for the complex types as well.
 
J

Josh Twist

Hi Richard,

Your suggestion kind of defeats the points of Web Services - self
description, interoperability. A client using such a service (with
binary serialization) isn't going to understand anything about your
service from the WSDL and has to be written in .NET.

You might as well use Enterprise services or (dare I say it) Remoting
and avoid the overhead of asmx.

Josh
http://www.thejoyofcode.com/
 
R

Richard Purchas

I see your point and agree whole-heartedly, but understand where my comments
came from:

Firstly, the web services I am talking about are used only for internal
purposes. I have a project with dozens of business classes that are passed
to these internal web services. If a Developer uses the out-of-box tools to
create a reference to our web services then they end-up with dozens of
proxies created in my consuming projects, which is a really undesirable
situation to be in.

Additionally, stand XML serialisation simply didn't cut the mustard; private
fields aren't serialised etc.

What alternatives can you offer to get around these two issues (whilst still
permitting use of the tools I refer to) ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Serialization 0
Different Serialization Technique In .NET 0
Serialization 10
serialization 3
Serializing a derived class 0
Automating Serialization? 0
Object Serialization Issue 0
Type "assurance" of derived classes 8

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top