今天写了一个webservice接口,返回类型是DataTable ,运行的时候报以下错误:
System.InvalidOperationException: 生成 xml 文档时出错。 --->
System.InvalidOperationException: 无法序列化 DataTable。未设置 DataTable 名称。在 System.Data.DataTable.WriteXmlSchema(XmlWriter writer, Boolean writeHierarchy)在 System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter writer)在 System.Xml.Serialization.XmlSerializationWriter.WriteSerializable(IXmlSerializable serializable, String name, String ns, Boolean isNullable, Boolean wrapped)在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_DataTable(Object o)在 Microsoft.Xml.Serialization.GeneratedAssembly.DataTableSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)在 System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)--- 内部异常堆栈跟踪的结尾 ---在 System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)在 System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)在 System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)在 System.Web.Services.PRotocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)在 System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)在 System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)在 System.Web.Services.Protocols.WebServiceHandler.Invoke()
解决方法:
给定义的Datatable命名。代码:
DataTable table= new DataTable();
table.TableName = "tmp";
新闻热点
疑难解答