C# 用于调用服务的IService接口。每个方法一个代理或全局类级代理
我正在使用Silverlight应用程序(MVVM)和windows phone提供的WCF服务。我有一个服务类(自动生成)和一个IServiceRepository,如下所示C# 用于调用服务的IService接口。每个方法一个代理或全局类级代理,c#,mvvm,event-handling,windows-phone-7,mvvm-light,C#,Mvvm,Event Handling,Windows Phone 7,Mvvm Light,我正在使用Silverlight应用程序(MVVM)和windows phone提供的WCF服务。我有一个服务类(自动生成)和一个IServiceRepository,如下所示 public interface IServiceRepository { event EventHandler<SomeEventArgs> GetDataCompleted; void Data GetData(); // 10 more methods for fetching differ
public interface IServiceRepository
{
event EventHandler<SomeEventArgs> GetDataCompleted;
void Data GetData();
// 10 more methods for fetching different data.
}
public class ServiceRepository : IServiceRepository
{
public event EventHandler<SomeEventArgs> GetDataCompleted;
public void Data GetData()
{
var proxy = new ActualServiceRefClient();
proxy.GetDataCompleted += PrivateGetDataCompleted;
proy.GetDatAsync();
}
private void PrivateGetDataCompleted(object s, SomeEventArgs e)
{
// Error check and all
if(GetDataCompleted != null)
GetDataCompleted(this, new SomeEventArgs(...));
}
}
公共接口IServiceRepository
{
事件事件处理程序GetDataCompleted;
void Data GetData();
//还有10种获取不同数据的方法。
}
我的SerViceRepository如下所示
public interface IServiceRepository
{
event EventHandler<SomeEventArgs> GetDataCompleted;
void Data GetData();
// 10 more methods for fetching different data.
}
public class ServiceRepository : IServiceRepository
{
public event EventHandler<SomeEventArgs> GetDataCompleted;
public void Data GetData()
{
var proxy = new ActualServiceRefClient();
proxy.GetDataCompleted += PrivateGetDataCompleted;
proy.GetDatAsync();
}
private void PrivateGetDataCompleted(object s, SomeEventArgs e)
{
// Error check and all
if(GetDataCompleted != null)
GetDataCompleted(this, new SomeEventArgs(...));
}
}
公共类服务存储库:IServiceRepository
{
公共事件EventHandler GetDataCompleted;
公共void数据GetData()
{
var proxy=新的ActualServiceRefClient();
proxy.GetDataCompleted+=PrivateGetDataCompleted;
proy.GetDatAsync();
}
private void PrivateGetDataCompleted(对象s,SomeEventArgs e)
{
//错误检查和所有
如果(GetDataCompleted!=null)
GetDataCompleted(这是新的SomeEventArgs(…);
}
}
我从ViewModels调用此方法。现在我的问题是
希望这有帮助 问题是我有大约15个服务方法和15个事件要注册。我的每个视图模型都调用两个或三个服务方法。通常情况下,如果我将事件处理程序保留一段时间不会有问题,但在Windows phone 7中,最大峰值内存为90 Mb,我们担心内存问题。我想我会在每次需要时实例化服务存储库,并在每个方法中连接事件处理程序。让服务存储库超出范围,垃圾收集器将回收内存。谢谢。我想这是MVC和LINQDataContext的建议方式。虽然我找不到链接