This project has moved and is read-only. For the latest updates, please go here.


Web Api / HttpClient Example


I have an older net 4.0 web api 1 project that exposes iEnums and would love to expose iQueryables.

I done see any examples on how to HttpClient.GetAsync() an expression?
Am I missing something?
        public RemoteRepository(string uri)
            _dataProvider = async expression =>
//             using (var proxy = new ServiceProxy(uri))
                using( HttpClient proxyClient = new HttpClient() )
                    proxyClient.BaseAddress = new Uri(uri);
                    HttpResponseMessage result = await proxyClient.GetAsync(expression ??);
//                var result = proxy.ExecuteQueryAsync(expression);
                    return result;
Closed Aug 13, 2016 at 1:08 AM by ChristofSenn


ChristofSenn wrote Feb 15, 2016 at 8:24 PM

mpisano wrote Feb 25, 2016 at 8:31 PM

I have been looking through the WebApi samples but they are all built with Framework 4.5 where i'm stuck on 4.0

using the older WebAp (4.030506)i, I cannot overiide DefaultBodyModelValidator - ShouldValidateType()
So I cant
config.Services.Replace(typeof(IBodyModelValidator), new CustomBodyModelValidator());

I tried rebuilding both Aqua and RL using 4.0 and the Async BLC and had success compiling, but then I run the sample I get
"Method may only be called on a Type for which Type.IsGenericParameter"

I also tried using the 3.5 version of both AsyncRemoteQueryable is undefined

Any suggestions?

ChristofSenn wrote Feb 29, 2016 at 5:55 PM

Hi Mike

Basically you don't need a custom validator. It was just added for performance reason, to skip validation of Query objects as apparently DefaultBodyModelValidator takes rather long to validate query expressions.

Would you be able to provide a sample solution (e.g. attaching to this workitem as a zip file) using the configuration you're describing to reproduce the issue?


mpisano wrote Mar 4, 2016 at 5:54 PM

Thanks Christof,

I was able to build the Source as Net4 with the Async BCL, the only source change I had to make was

private static async Task<IEnumerable<T>> ExecuteAsync<T>(IQueryable<T> source)
{ enumerable = await Task.Factory.StartNew(() => source.ToList()).ConfigureAwait(false);
       //     enumerable = await Task.Run(() => source.ToList()).ConfigureAwait(false);

My two Final Errrors were I needed to
selfhostconfig.Formatters.Add(new System.Net.Http.Formatting.XmlMediaTypeFormatter());

I would like to use JSON, but having to many issues with [FromBody] with winapi V1 so I gave up for now.

I'm still struggling with CUD, although "Read" is working great with this lib.
looking into Webapi\Wcf\Odata..... but it's not well supported in Framework 4.0
If I go that route, not sure I need remote.linq then? Still experimenting, appreciate any suggestions


mpisano wrote Mar 6, 2016 at 3:58 PM

BTW - I'm lookiing at your N-Tier framework
I see it's built with a 35 version of remote.Linq, but if it fixed the CRUD issues it might be a solution.


mpisano wrote Mar 6, 2016 at 7:33 PM

Nice piece of work with N-Tier, but looks like more then I'm looking for.
Any reason why you didn’t implement a simple Delete(key) , Update(key,T), Add<T>(t) method to RemoteLinq?


ChristofSenn wrote Mar 7, 2016 at 5:10 PM

For providing OData services on .NET 4 I’d suggest using WCF Data Services. See link and link.

Write operations via Remote.Linq
Can you create/update/delete data using linq? It’s a query language.
That said you can still utilize expressions, either local or remotely, e.g. to select records for update or delete operations. Does that make sense?

N-Tier Entity Framework
This framework is aimed to provide rich functionality comparable to entity framework and beyond in n-tier scenarios. It might be perfect for you especially for create/update/delete operations as long you can use WCF between client and server.

mpisano wrote Mar 7, 2016 at 7:09 PM

N-Tier Entity Framework looks perfect, except I don't see any CodeFirst examples, and I would prefer to share the model as a DLL link Remote.Linq does and not have to deal with T4.

Remote.Linq query works perfectly, I'm having issues with Count() and joins using WCF\ODATA and prefer the passing of the expression tree. Keep in mind I'm stuck with .Net4.0 and WebApi V1 :(

I realize this is a Query only solution, just trying to see the best way to add writing the entities back.
Might just be easier to follow the WCF backend add methods for Add<T> Del<T> Update<T> and just call them from the client, but your true repository UOW would be nicer if I can get it to play with CodeFirst.

Thanks Again for your help and suggestions.

ChristofSenn wrote Mar 8, 2016 at 7:44 AM

For now N-Tier EF is pure EDMX first. It generates all layers based on EDMX using T4.
The model gets generated into its own assembly (dll) and is shared between client and server.