Mur*_*sli 1 c# wcf serialization
我无法添加System.Windows.Forms到我的WCF服务库.
我想List<ListViewItem>从我的方法返回一个GetItems(string path),我也尝试添加引用,System.Windows.Forms但没有发现它看起来像WCF服务库不支持它.
任何想法我怎么能这样做?
namespace WcfServiceLibrary1
{
[ServiceContract]
public interface IFileManager
{
[OperationContract]
List<ListViewItem> collection(string path);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Item.cs班级:
namespace WcfServiceLibrary1
{
[DataContract]
public class Item
{
[DataMember]
public string name;
[DataMember]
public string path;
[DataMember]
public long size;
[DataMember]
public DateTime date;
}
}
Run Code Online (Sandbox Code Playgroud)
WCF旨在成为可互操作的服务平台,因此我建议不要使用.NET特定的数据类型,例如服务ListViewItem中的返回类型.毕竟,PHP或Ruby客户端将如何处理这样的对象?
相反:使用您的Item类,返回WCF服务中的列表,并将其留给调用应用程序,以ListViewItem根据需要将其转换为s ....
另外:ListViewItem从WCF服务返回会严重限制该服务的功能.如果某个客户端想要获取该数据,但是以其他方式(不是a ListView)呈现它,他们就不能再使用该服务调用..... 只返回数据元素(如你的Item)类,你离开由调用者决定如何处理该数据,以及如何在屏幕上显示它.我认为这是件好事,不应该改变!