locked
Exposing multiple web service end points in a single Data Service RRS feed

  • Question

  • Hi All,

     

    Is it possible to expose multiple services through a single data service? Without using a service operation on the single data service to go and call the separate services (so that the application can use a normal LINQ query)?

     

    The scenario is that there would be a single aggregate data service which would be the only entry point for a client application. This single service would then surface data from two other services say a customer service and an orders service.

    The client application would then be able to say something like:

     

    var result = from x in AggregateContext.AggregateEntities.CustomerSet

    select x;

     

    and

     

    var result2 = from x in AggregateContext.AggregateEntities.OrdersSet

    select x;

     

    Where AggregateContext is the single service context and AggregateEntities is the entity which surfaces the entities in the other two services.

     

    Is this at all possible?

     

    I know it sounds like a crazy question but we have the case where we're displaying a grid to the user which has a field which should belong to one service as well as a field which should belong to another service but we want to be able to populate the grid easily.

    Wednesday, October 8, 2008 1:40 AM

Answers

  • I think so.  You can still use linq queries to go against service methods if you return IQueryable all the way back (i.e. your service and your client proxy method.  Your query to the server is combined with what ever your service returns to form the final query which is returned over the wire.  Actually, that is pretty cool.

     

            // Code 

                var lq = from u in cs.GetUsers("%ill%")
                         where u.UserID >= 1
                         select u;
                Console.WriteLine(lq.ToString());

           
            // Proxy method at client. Return an IQueryable so you can compose.
            public IQueryable<Users> GetUsers(string pattern)
            {
                var db = GetDB();
                var q = db.CreateQuery<Users>("/GetUsers").AddQueryOption("pattern", "'"+pattern+"'");
                return q;
            }

     

    // Service
    [WebGet]
    public IQueryable<Users> GetUsers(string pattern)
    {
       // Build up your Users from two sources.
       list = ...
       return list.AsQueryable();
    }

    Thursday, October 9, 2008 12:26 AM

All replies

  • I think so.  You can still use linq queries to go against service methods if you return IQueryable all the way back (i.e. your service and your client proxy method.  Your query to the server is combined with what ever your service returns to form the final query which is returned over the wire.  Actually, that is pretty cool.

     

            // Code 

                var lq = from u in cs.GetUsers("%ill%")
                         where u.UserID >= 1
                         select u;
                Console.WriteLine(lq.ToString());

           
            // Proxy method at client. Return an IQueryable so you can compose.
            public IQueryable<Users> GetUsers(string pattern)
            {
                var db = GetDB();
                var q = db.CreateQuery<Users>("/GetUsers").AddQueryOption("pattern", "'"+pattern+"'");
                return q;
            }

     

    // Service
    [WebGet]
    public IQueryable<Users> GetUsers(string pattern)
    {
       // Build up your Users from two sources.
       list = ...
       return list.AsQueryable();
    }

    Thursday, October 9, 2008 12:26 AM
  • Hi William,

    Thank you very much for your reply. That's what I was looking for.

    It seems to work now for the querying.

    I've just got to get the updating working so I'm looking into implementing the IUpdatable interface which looks like it could be ...interesting....

    Thanks again!
    James
    Friday, October 10, 2008 5:06 AM