本文介绍了有关反序列化的SVC服务错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图从svc服务获取目录的子目录列表,但它显示错误 - 类型System.IO.FileSystemInfo无法反序列化,因为它没有参数少的公共构造函数。 请帮助我解决这种情况。 代码片段 -Hi,I am trying to get the list of sub-directories of a directory from svc service, but it shows an error --The type System.IO.FileSystemInfo cannot be deserialized as it doesn''t has parameter less public constructor.Please help me out from this situation.Code Snippet--[OperationContract]private System.Collections.Generic.List<DirectoryInfo> GetSubDirectories(string directoryPath){ try { DirectoryInfo dir = new DirectoryInfo(directoryPath); DirectoryInfo[] dirs = dir.GetDirectories(); System.Collections.Generic.List<DirectoryInfo> childs = new System.Collections.Generic.List<DirectoryInfo>(); foreach (DirectoryInfo dir1 in dirs) { // XmlObjectSerializer xml_serial = new XmlObjectSerializer(typeof(XML_directory)); childs.Add(dir1); } return childs; } catch (Exception) { return null; } //return null;}推荐答案[DataContract]public Class DirectoryInfoDTO{ [DataMember] public DateTime CreationTime {get ; set;} [DataMember] public string Name {get ; set;}} 然后是代码: // 包括:System.Linq;And then the code: // Include: System.Linq;var result = dirs.Select((a,b) => new DirectoryInfoDTO() { Name = a.FullName, CreationTime = a.CreationTime } 结果将是DirectoryInfoDTO的集合the result will be a collection of DirectoryInfoDTO 这篇关于有关反序列化的SVC服务错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 10:28