Solved

best place to use a web service in MVC4

Posted on 2013-10-23
3
243 Views
Last Modified: 2013-10-30
Hi, I have inherited a MVC4 application that was using a database to retrieve customer data, but now that information is available as a web service.

My confusion is should I access this web service in the ViewModel or should I go all the way to the Model?

pls note I'm new to MVC in ASP.net, not to mention MVC4.

thanks!
0
Comment
Question by:olmuser
  • 2
3 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39596288
A viewmodel is used to only represent the data of your view (hence the name). It would not make sense to call this data from such classes. Since the web service is effectively your data store, I would say that the model would be the place to retrieve your data.
0
 
LVL 1

Author Comment

by:olmuser
ID: 39599476
But what if the information gathered from the web service is only relevant to the view? Say a picture that is used in the view but never stored back in the model or in the underlying database? thanks!
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39600384
What if the service definition changes, or what if it comes from a different source? If the structure of the view is driven by what the user needs to see, regardless of the source, then you wouldn't want to couple your view to the underlying model (of the service). If you did, then any time the service definition changes you would have to change the view as well. If the structure of the view is driven by displaying whatever the service returns, then perhaps it would be OK to just display the model associated with the service, because if the service definition ever changed, you would have to update the view to accommodate the new or missing fields anyway.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to add <appSettings> to the webconfig file 2 27
Where can I ask about my ASP.NET MVC project? 6 36
Crystal reports vb.net 2 40
Where did System.Data.Objects go? 2 27
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question