Serialization of derived classes

Discussion in 'ASP .Net Web Services' started by Angel, Feb 2, 2006.

  1. Angel

    Angel Guest

    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 ?
     
    Angel, Feb 2, 2006
    #1
    1. Advertising

  2. Angel

    Josh Twist Guest

    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?
     
    Josh Twist, Feb 2, 2006
    #2
    1. Advertising

  3. 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.

    "Angel" <> wrote in message
    news:...
    >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 ?
    >
     
    Richard Purchas, Feb 16, 2006
    #3
  4. Angel

    Josh Twist Guest

    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/
     
    Josh Twist, Feb 16, 2006
    #4
  5. 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) ?

    "Josh Twist" <> wrote in message
    news:...
    > 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/
    >
     
    Richard Purchas, Feb 27, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Goudie
    Replies:
    6
    Views:
    477
    Victor Bazarov
    Jan 26, 2004
  2. Manuel
    Replies:
    8
    Views:
    644
    Manuel
    Jan 5, 2006
  3. Replies:
    6
    Views:
    381
  4. Replies:
    1
    Views:
    397
    myork
    May 23, 2007
  5. Replies:
    1
    Views:
    390
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page