Sorry, stupid outlook.

>From MSDN:

When applying the XmlIncludeAttribute, specify the Type of the derived
class. When the XmlSerializer serializes objects that include both the
base and the derived class, it can then recognize both object types.

You can use the XmlIncludeAttribute to include derived classes in
service description documents that are written in the Web Services
Description Language (WSDL). For example, if a method returns an Object,
apply the XmlIncludeAttribute to the method and specify the actual types
that should be returned.

Also from MSDN:

The following example defines a class named Group, which contains a
field named Employees that retuns an array of Employee objects. The
example derives the Manager class from the Employee class, and applies
the XmlIncludeAttribute to the Employee class. When the example creates
a Group object, it inserts a Manager object into the Employee array.
Lastly, the example serializes the Group object.

public class Group
{   
   public Employee[] Employees;
}

// Instruct the XmlSerializer to accept Manager types as well.
[XmlInclude(typeof(Manager))]
public class Employee
{
   public string Name;
}

public class Manager:Employee
{
   public int Level;
}



It looks like for the definitions in WSDL to be correct you apply it to
the method, but for derived classes to work through the XmlSerializer
you add it to the class level.  Though I don't implicitly trust MSDN,
for example it tells me to put a [SoapMethod] attribute the client
method that calls the server side soap method.  

Regardless I've tried it both ways, and neither way works except as in
my original post.

Does anyone know what method WSE uses to serialize objects into XML?
Perhaps this is a bug, or oversight in WSE, but I cannot find any
information that will help.

Thanks,

Josh


-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Martijn de
Haas
Sent: Monday, January 03, 2005 12:23 AM
To: [email protected]
Subject: Re: Using WSE to pass message objects derived from a common
base

Hi,

You are using the XmlInclude attribute incorrectly. You have to use it
on
WebMethod level. Not on class level. See example below (source: MSDN
library)

Regards,

Martijn de Haas
http://www.artifactory.nl

[C#]
public class Vehicle{}

public class Car:Vehicle{}

public class Truck:Vehicle{}

public class Sample
{
[WebMethodAttribute]
[XmlInclude(typeof(Car))]
[XmlInclude(typeof(Truck))]
public Vehicle ReturnVehicle(int i){
   if(i == 0)
      return new Car();
   else
      return new Truck();
   }
}

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor�  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to