How to call a .Net 4.51 RESTFUL API from a 2.0 .net web form - webforms

I have some legacy applications that needs to call a new .net RESTFul API. What I am not sure of is if I can call a 4.51 API from a 2.0 web form.

For such a general question, I can give you a general answer.
Use HttpClient to make web requests to your REST API from your code behind, or make http requests from your javascript.
If you need to make requests to your REST API from your code behind, you will likely need JSON.NET to serialize the data from json to a .net object.
JSON.NET is available as a nuget package.

Related

Consume many web api endpoints (identical)

I have a list of identical web api endpoints.
URL1/Products
URL2/Products
URL3/Products
......
The result of each of them is JSON (also identical)
I need to combine the results from each API in one "main" result.
How to consume web api list? And get combined result?
What approach should be used? Best practices?
Thanks.
P.S. ASP WebAPI, using now RestSharp as a client, .Net Framework 4.5.2

Use BreezeJS and JayData Without OData

Can we use BreezeJS or JayData, with all of their features without OData (i.e using only ASP.NET Web API but without OData)?
Breeze already supports this as it's default. Breeze, by default, uses an OData format over the wire for query purposes, but this does NOT require that the server be implemented as an OData service. The standard Breeze WebApi server controller can understand this format without you having to implement an OData service. ( the same is true of our Mongo and Ruby server examples).
In fact, most of the Breeze examples show Breeze communicating directly with ASP.NET Web Api without using any of the WebApi OData implementation.

Does Web Api OData Support For Generic Action?

I have an OData service based on the Web Api 4, and I wan't to add an action to this service, but the action method is generic, so is this supported?
Thanks
No, the OData protocol does not support generics for actions or functions. You'll need to create a separate action for each type you want to support, unfortunately.
You can publish context-level service operations (function imports) using WCF Data Services... this requires to migrate your code from WebAPI.

WCF Data Service vs WebAPI

I have been catching up with MVC4 Web API and WCF Data Service. From the surface, they both seem to be able to work with oData in the consuming client. I wonder which one is better for separation of concern (separate data service layer from UI layers). In my current solution, I have a plain MVC 3 style Intranet project and a MVC Data Service project. The 1st project has a Service Reference to the 2nd project. My goal is to write the data service once and make it available to all projects that would need to access underline database. When I read about Web API, it seems to me that the ApiControllers can return oData compliant result to the consuming client without MVC Data Service. My confusion is how I am going to expose this Web API MVC project as a service endpoint. Should I wrap it in WCF? Thanks.
You just create a controller inheriting ApiController and decorate one action with [Queryable] attribute, Rest depends on your route setup. Easy-Peasy.
Which one better? Web API. Since it has all the goodness of HTTP and you are not restricted to ATOM format.
You may use PocoHttp for seamless access of the data from your client.

What replaced HttpOperationHandler in WCF Web API to ASP.NET Web API

In upgrading an old project that was built using WCF Web API to now use ASP.NET Web API, I have run into a few classes that implement HttpOperationHandler<HttpRequestMessage, T>. I'm unable to find an equivalent class in the new assemblies. Does something similar exist or will I need a different approach?
The concept of Operation handlers has been replaced with Filters and model binders.
Here are some links that you might find useful:
How to Migrate from WCF Web API to ASP.NET Web API
Mike's blog on How WebAPI does Parameter Binding
Getting started tutorials on ASP.NET WebAPI page.
Hope this helps.

Resources