在 asp.net SOAP 服务中使用抽象、派生、虚拟或接口

Using abstract, derived, virtual or interface in an asp.net SOAP servive

我想知道是否有任何方法可以在 asp.net SOAP 网络服务中使用抽象 classes(分别派生 children)?..

想法如下:我有一个 SOAP 服务,需要输入一个 Departure object 和一个目的地 Destination object。但 Departure 和 Destination 实际上都是以下 object 之一:DepartureCity、DepartureRegion、DepartureCountry、...(源自通用 parent class DepartureDestination)

问:是否可以在 SOAP 服务中使用派生的 objects(无需严重侵入 .NET 框架)?也许通过使用抽象、虚拟、接口或 "regular" 派生 child objects?

感谢任何建议!

KnownType 仅适用于 WCF,不适用于 SOAP。但是我弄清楚了它是如何工作的,以防其他人正在寻找解决方案:我只需要为 child 类 添加 XmlInclude 并且 - 令人惊讶 - 派生的 child 类也出现在WSDL中:

public class Airport : Location
{
    [XmlElement(IsNullable = true)]
    public string Code;
}

public class City : Location
{
    [XmlElement(IsNullable = true)]
    public string Code;
}

[XmlInclude(typeof(Airport))]
[XmlInclude(typeof(City))]
public abstract class Location
{
    public LocationType Type
    {
        get
        {
            if (this.GetType().Name == typeof(Airport).Name)
            {
                return LocationType.Airport;
            }
            else if (this.GetType().Name == typeof(City).Name)
            {
                return LocationType.City;
            }
            else throw new NotImplementedException("Unknown LocationType");
        }
    }
}