We're trying to pass objects from an MVC application to a webapi application. Basically our set up is :-
Models project MVC 4 web project - references the models project WEB API project - references the models project
from the mvc application, we want to pass a populated model to the web api,
public User
{
Firstname { get; set}
Surname { get; set}
}
public bool Add(mUser use)
{
}
http headers? URL string? should we be using http client? also, are there any samples? I've only found 1 but unable to get this to work.
any help or advise would be greatly appreciated.
Basically there are 2 approaches:
using an HTTP client
. This allows you to have your Web API hosted in a separate process than the MVC application and scale it independently. The Web API could be hosted on a separate web farm than the MVC application and both will have completely different lifetimes/ HttpMessageInvoker
as shown in this post
. The advantage here is that the client is not paying the overhead of an HTTP call being made. The drawback is that the 2 applications are tightly coupled and relying on the fact that are hosted in the same process. The 2 approaches are valid, it's up to you to decide which one fits better your needs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.