【发布时间】:2011-11-18 18:22:28
【问题描述】:
我的 WPF 应用程序应该通过 WCF 从管道接收数据: 我是 MVVM 的新手,我不明白在哪里放一些东西。我很清楚什么是 View,但不清楚什么是 ViewModel,尤其是在我的情况下是什么 Model(如果涉及 WCF)问题是:
- 什么是型号?我需要特殊的类来代表模型吗?还是模型是 WCF 服务器应用程序?什么是有效的工作流 "WCF Server application ----命名管道-----> ViewModel View" 或 "WCF Server application ----命名管道-----> ModelViewModel View"
-
如何重构下面的代码?把所有这些初始化放在哪里?视图模型?到模型类(如果我需要的话),到特殊的“初始化”类?
public MainWindow() { ChannelFactory<IManagementConsole> pipeFactory = new ChannelFactory<IManagementConsole>( new NetNamedPipeBinding(), new EndpointAddress( "net.pipe://localhost/PipeMBClientManagementConsole")); IManagementConsole pipeProxy = pipeFactory.CreateChannel(); List<ConsoleData> datas = new List<ConsoleData>(); foreach (StrategyDescriptor sd in pipeProxy.GetStrategies()) { datas.Add(pipeProxy.GetData(sd.Id)); } this.DataContext = datas; }
我可以假设这是我的 MVVM 模型吗? :
[ServiceContract]
public interface IManagementConsole
{
[OperationContract]
ConsoleData GetData(int strategyId);
[OperationContract]
List<StrategyDescriptor> GetStrategies();
}
【问题讨论】: