Solved

best place to use a web service in MVC4

Posted on 2013-10-23
3
240 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 74

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 74

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now