Search code examples
c#wcfodatawcf-data-services

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); so that the p1 and p2 are set from client not from the server.

Please suggest some mechanism


Solution

  • I do believe what you try to achieve is mostly related to

    Using an ADO.NET Entity Framework DataSource(WCF Data Services)

    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:

    1. In your WCF server simply define 2 new Data Contracts and call them p1 and p2 with all your desired fields
    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

    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.