Webサービスのコンテキストでは、クラスMammalから継承した次のクラスがあります。 Mammalクラスはプロキシで定義されています。私はそのクラスの定義を変更することはできません。クライアントサイドのMammalクラスにいくつかのメソッドを追加する必要があるので、私はMammalを継承し、Giraffeを作成しました。WebService、WebMethodおよび継承
namespace TestApplication
{
public class Giraffe : Mammal
{
public Giraffe()
{
}
}
}
私はタイプの哺乳類のオブジェクトを期待するWebメソッドを呼び出すと、私はキリンが期待されていないことを私に言って、次の例外を取得します。
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を追加することはできません...
私はこのケースでは部分的なクラスを使用することはできません怖いです。このスレッド http://stackoverflow.com/questions/20084/xml-serialization-and-inherited-types –