在 Web 服务上下文中,我有以下类继承自 Mammal 类。Mammal 类是在代理中定义的。我无法更改该类的定义。因为我需要在客户端给 Mammal 类添加一些方法,所以我继承了 Mammal 并创建了 Giraffe。
namespace TestApplication
{
public class Giraffe : Mammal
{
public Giraffe()
{
}
}
}
当我调用一个期望 Mammal 类型对象的 WebMethod 时,我收到以下异常,告诉我不需要 Giraffe。
Error: System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type Giraffe was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterPaymentRequestAuthorization.Write6_Tender(String n, String ns, Tender o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterPaymentRequestAuthorization.Write12_PaymentRequestAuthorization(String n, String ns, PaymentRequestAuthorization o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterPaymentRequestAuthorization.Write13_PaymentRequestAuthorization(Object o)
--- End of inner exception stack trace ---
有解决方法吗?我不能真正添加 XmlInclude ...