首页 新闻 赞助 找找看

WebService 返回xml报错

0
[待解决问题]
WebService 自定义一个类ServiceEntity作为返回值,format用户控制返回xml或json 


[WebMethod(Description = "xxxx")] public ServiceEntity Getxxx(string format, string xxx) { var entity = new ServiceEntity(); ....... return entity; } public dynamic Data { get; set; } /// <summary> /// 返回值 0-为成功 非0-失败 /// </summary> public int Ret { get; set; } /// <summary> /// 返回错误代码 /// </summary> public string ErrCode { get; set; } /// <summary> /// 错误信息 /// </summary> public string Msg { get; set; }


其中Data可能是list<entity> 也可能是Entity,转化json正常,默认返回Xml时报错,

报错信息

System.InvalidOperationException: 生成 XML 文档时出错。 ---> System.InvalidOperationException: 类型 System.Collections.Generic.List`1[[Galaxy.Entity.SysBpmDProcessEntity, Galaxy.Entity, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]] 不能在此上下文中使用。
   在 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.Write2_ServiceEntity(String n, String ns, ServiceEntity o, Boolean isNullable, Boolean needType)
   在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write4_Root(Object o)
   在 Microsoft.Xml.Serialization.GeneratedAssembly.ServiceEntitySerializer.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.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()

 

MissJacker的主页 MissJacker | 初学一级 | 园豆:59
提问于:2014-03-06 11:19
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册