tags:

views:

100

answers:

3

I plan on writing a WPF app following the MVVM pattern for the first time but something is not quite clear to me. Let's say that the view has a "Save" button and when that is hit I need to save the current state of my data (the model). This will be done by sending a SOAP message to a SOAP service.

Where in my MVVM setup do these SOAP request/response handlers live? Does the view model make the SOAP call itself whenever the save button is hit? Should the view model notify the model to save itself instead? Maybe it's some other way, completely separate from the MVVM?

My thinking was that (at least in this specific case) the view model would handle it since it needs to disable the save button in the view until the current save request has completed.

+1  A: 

I typically put a logical client-side application/business layer between the viewmodel and the SOAP/WCF/Webservice layer. This layer is where all the non-view business logic and processing logic lives. Remember, the viewmodel is the model of the view, not the model of the domain. Therefore, you want to hand off control to the next layer down ASAP.

In this scenario, I would have the view trigger a save command on the the viewmodel, which would in turn call into the application layer, which would in turn make any calls to remote services.

Daniel Auger
A: 

The ViewModel, should not do such an operation. It only should trigger it. Therefore the model has to do it (or another intermediate layer that is responsible for the load-and save-operations, but not the ViewModel itself).

The ViewModel can observe the save-operation and may provide state-information about the progress for the View.

HCL
A: 

I would create a service handler that can be accessed by the ViewModel. Pass this into the constructor of the viewmodel, and call the methods exposed by the service handler.

Robaticus