WCF 数据服务的客户端通道工厂
由于许多不同的原因,我讨厌使用服务引用,而是使用接口和 System.ServiceModel.ChannelFactory
我希望在连接到 WCF 数据服务时能够使用类似的东西。
我的意思是,当我创建 DataService 端点时,它只是 DataService,为什么我不能在创建客户端时新建 DataServiceContext 并有权访问 MyDataService 中的所有 IQueryable。
例如,
公共
public interface IMyDataService
{
public IQueryable<Foo> Foos {get;set;}
public IQueryable<OtherFoo> OtherFoos {get;set;}
}
服务器
public class MyDataService : IMyDataService
{
public IQueryable<Foo> Foos {get;set;}
public IQueryable<OtherFoo> OtherFoos {get;set;}
}
public class DataService : DataService<MyDataService>
{
}
客户端
var context = new DataServiceContext<IMyDataService>();
var foo = context.Foos.First(f=>f.Id = 5);
var otherFoos = contact.OtherFoos.Where(of=>of.width > 6);
编辑:我有一个解决方案,我创建 IMyDataService 的代理类,但是我的理解是,这在服务器上非常困难。任何人都知道使用此处详述的方法创建代理对性能的影响:http://www.codeproject.com /KB/cs/dynamicproxy.aspx
I hate using service references for many different reasons, instead I use interfaces and System.ServiceModel.ChannelFactory
I would like to be able to use something similar when connecting to WCF Data Services.
I mean when I'm creating the DataService Endpoint it's just DataService why can't I new up a DataServiceContext when creating the client and have access to all the IQueryables in MyDataService.
eg
Common
public interface IMyDataService
{
public IQueryable<Foo> Foos {get;set;}
public IQueryable<OtherFoo> OtherFoos {get;set;}
}
Server
public class MyDataService : IMyDataService
{
public IQueryable<Foo> Foos {get;set;}
public IQueryable<OtherFoo> OtherFoos {get;set;}
}
public class DataService : DataService<MyDataService>
{
}
Client
var context = new DataServiceContext<IMyDataService>();
var foo = context.Foos.First(f=>f.Id = 5);
var otherFoos = contact.OtherFoos.Where(of=>of.width > 6);
Edit: I have a solution where I create a proxy class of IMyDataService however it's my understanding that this would be pretty hard on a server. Anyone know anything about the performance impact of creating a proxy using the method detailed here: http://www.codeproject.com/KB/cs/dynamicproxy.aspx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论