我有一个 Class1
的 Web 服务。 Class1
有一个属性的图像列表
[Serializable]
[SoapInclude(typeof(Bitmap))]
public class Class1
{
private static List<Image> _myList = new List<Image>();
public List<Image> MyList
{
get { return _myList; }
set
{
_myList = value;
}
}
}
在MyList
上进行获取时,发生以下错误。有什么想法吗?
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Drawing.Bitmap was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write4_Image(String n, String ns, Image o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write5_Class1(String n, String ns, Class1 o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write6_HelloWorldResponse(Object[] p) at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer1.Serialize(Object objectToSerialize, XmlSerializationWriter writer) at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream) at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues) at System.Web.Services.Protocols.WebServiceHandler.Invoke() --- End of inner exception stack trace ---
最佳答案
我在以下网址找到了答案。我需要 [XmlInclude] 标签而不是 [SoapInclude] 标签
Troubleshooting Common Problems with the XmlSerializer
[Serializable]
[XmlInclude(typeof(Bitmap))]
public class Class1
{
}
关于c# - Web 服务序列化复杂对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10321456/