I have a WSE 3.0 based web service, and a WinForms client application that makes use of the types defined in that service's References.cs, but subclasses them to provide some additional functionality required by the client.
However, when I pass an instance of the subclass back to the web service, even though I explicitly cast back to the original type, I get the dreaded:
Use the XmlInclude or SoapInclude attribute to specify types that are not kno开发者_开发技巧wn statically.
in reference to my derived type.
Code summary:
public class DefinedInReferenceCs
{
// ...
}
public class ClientSubclass : DefinedInReferenceCs
{
// My extra stuff
}
public class MyClient
{
public CallTheWebService(ClientSubclass obj)
{
// obj is an instance of ClientSubclass, cast as DefinedInReferenceCs
svc.MyMethod((DefinedInReferenceCs)obj);
// Throws an exception complaining that ClientSubclass is not statically known
}
}
I can get around this by explicitly creating a DefinedInReferenceCs instance and performing a deep copy of the relevant fields. Is there a better way?
Since the XML Serializer uses Reflection to work with objects, there is no way to keep it from seeing that your base class reference references an instance of your derived class. Yes, you must use XmlInclude
.
OTOH, have you considered using partial classes to add functionality to the original proxy classes? That way, you would not need a derived class at all.
精彩评论