System.InvalidOperationException:生成XML文档时出错。 ---> System.InvalidOperationException:不期望WebService.Property.Property_Users类型。使用XmlInclude或SoapInclude属性指定静态未知的类型。 at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name,String ns,Object o,Boolean xsiType) 在Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n,String ns,Object o,Boolean isNullable,Boolean needType) 在Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write8_ArrayOfAnyType(Object o) 在Microsoft.Xml.Serialization.GeneratedAssembly.ListOfObjectSerializer.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名称空间) 在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()
public List<object> GetDataByModuleName(string ModuleName)
{
List<Property_Users> obj_UserList = new List<Property_Users>();
// performing some operation that add data to obj_UserList
List < Object > myList = new List<object>();
return ConvertToObjectList<Property_Users>(obj_UserList);
}
public List<Object> ConvertToObjectList<N>(List<N> sourceList)
{
List<Object> result = new List<Object>();
foreach (N item in sourceList)
{
result.Add(item as Object);
}
return result;
}
[WebMethod]
public List<object> GetDataByModuleName(string ModuleName)
{
List<object> obj_list = new List<object>();
obj_list = BAL_GeneralService.GetDataByModuleName(ModuleName);
return obj_list;
}
答案 0 :(得分:2)
序列化程序无法序列化object
如果要返回任意类型的列表,则必须Use the XmlInclude or SoapInclude attribute
给序列化程序一个提示。
此外,列表必须是同质的,包含只有一种类型的元素。例如您无法返回包含Foo
和Bar