简体   繁体   English

WCF数据服务自定义实现

[英]WCF data service custom implementation

How to pass parameters from client to method in server in order to get entity data. 如何从客户端向服务器中的方法传递参数以获取实体数据。

At Server side : 在服务器端:

List<Foo> getFoos = _serverObject.GetFoos(p1, p2); //Here's how I am getting foo from another server

class FooProvider
{ 
   public IQueryable<Foo> Foos
   {
      get{return getFoos.AsQueryable();}
   }
}

At Client Side : 在客户端:

var res = from f in ctx.Foos
          where f.p1 == p1_val && f.p2 == p2_val
          select f;

Now what I am trying to get is all Foo record depend on p1_val and p2_val parameters, but I would have to pass it to _serverObject.GetFoos(p1, p2) ; 现在我要获取的是所有Foo记录都取决于p1_valp2_val参数,但是我必须将其传递给_serverObject.GetFoos(p1, p2) so that the p1 and p2 are set from client not from the server. 因此p1p2是从客户端而不是从服务器设置的。

Please suggest some mechanism 请提出一些机制

I do believe what you try to achieve is mostly related to 我确实相信您尝试实现的目标与

Using an ADO.NET Entity Framework DataSource(WCF Data Services) 使用ADO.NET实体框架数据源(WCF数据服务)

and passing a parameter from client to server is only the tip of the iceberg however if I am wrong and all your problems will be resolved by only passing complex types p1, and p2 from client to server then do the following: 并将参数从客户端传递到服务器只是冰山一角,但是,如果我错了,并且仅通过将复杂类型p1和p2从客户端传递到服务器即可解决所有问题,那么请执行以下操作:

  1. In your WCF server simply define 2 new Data Contracts and call them p1 and p2 with all your desired fields 在您的WCF服务器中,只需定义2个新的数据合约 ,并使用所有所需字段将它们称为p1和p2
  2. Now on the client side when you add a service reference to the newly created service, you will be able to populate p1 and p2 and pass them to your server from your Proxy class when you call your service method 现在,在客户端上,当您向新创建的服务添加服务引用时,您将能够填充p1和p2,并在调用服务方法时将它们从Proxy类传递给服务器。

Moral of the story: You need to define those two types in your service as Data Contracts so you can use them as parameter in your proxy class on the client side. 故事的寓意:您需要在服务中将这两种类型定义为数据合同,以便可以将它们用作客户端代理类中的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM