【发布时间】:2014-12-16 04:47:30
【问题描述】:
我刚刚开始使用 WCF。我已经创建了 WCF 服务并将其托管在控制台应用程序中。
我的自定义类在服务和客户端之间共享。
[Serializable]
public class clsPlinker
{
[Serializable]
public class Game : Object
{
public Game(string name, string desc, int GameNum)
{
_Name = name;
_Desc = desc;
_GameNum = GameNum;
}
}
}
这是我的界面
[ServiceContract]
public interface IPlinkerWCFservice
{
[OperationContract]
List<clsPlinker.Game> GetGameList();
}
这是我的服务
public class PlinkerWCFservice : IPlinkerWCFservice
{
public List<clsPlinker.Game> GetGameList()
{
List<clsPlinker.Game> lstGames = new List<clsPlinker.Game>();
// do stuff to load the lstGames
return lstGames;
}
}
在我的 Windows 客户端应用程序中,我调用了服务引用
PlinkerWCFservice.PlinkerWCFserviceClient wcfTest = new PlinkerWCFservice.PlinkerWCFserviceClient("NetTcpBinding_IPlinkerWCFservice");
List<clsPlinker.Game> lstGames = wcfTest.GetGameList().ToList();
代码无法编译,出现以下错误:
不能隐式转换类型
System.Collections.Generic.List<TabletController.PlinkerWCFservice.clsPlinkerGame>给System.Collections.Generic.List<PlinkerCommon.clsPlinker.Game>
TabletController 是我的 WinForms 应用程序的命名空间。
在另一种方法中,我可以返回单个 clsPlinker.Game,但尝试返回 List 让我很困惑。我已经搜索了几个小时,但无济于事。我做错了什么。
【问题讨论】:
标签: c# winforms wcf list serialization