0

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,

User Model

public User
{
 Firstname { get; set}
 Surname { get; set}
}

Web API

public bool Add(mUser use)
{
}

MVC

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.

http://social.msdn.microsoft.com/Forums/vstudio/en-US/c81ee004-67f6-4f9e-8b72-1e46378b39c0/how-to-pass-several-objects-to-web-api-method?forum=csharpgeneral

any help or advise would be greatly appreciated.

Jason Evans
29.2k15 gold badges95 silver badges157 bronze badges
asked Nov 23, 2013 at 21:01
3
  • 2
    Why? Why would you want to handle an HTTP request, by issuing another HTTP request to a service that you control? Why not just allow your MVC site to access your businesss layer directly? Commented Nov 24, 2013 at 1:05
  • This is because the web API will be released separately, and we will require multiple application to communicate with this service. This service will act as a gateway Commented Nov 24, 2013 at 9:28
  • It is not uncommon to have a web api in between in case where the service needs to talk to several applications, it is NOT using an http request to access another one, it's an extra layer which allows your application to be more robust Commented Nov 24, 2013 at 20:16

1 Answer 1

1

Basically there are 2 approaches:

  1. The MVC application performs a full HTTP request to the Web API 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/
  2. The Web API and MVC application are hosted in the same ASP.NET process and the MVC application consumes the Web API with direct calls using an 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.

answered Nov 24, 2013 at 13:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.