Thursday, 15 January 2015

c# - WCF to WPF - DataContract to Model -



c# - WCF to WPF - DataContract to Model -

this might odd question, been nagging @ me little.

i'm looking @ converting between datacontract objects on wcf service , info models in wpf client.

the way see there 3 options:

create objects on both wpf , wcf sides, , have method converts 1 other. create single object, , utilize on both sides. create object on wpf side wraps around datacontract object returned wcf service.

now favoring 1. wondered if there downfalls had not foreseen.

here's excerpt pp.81 of "prism 5 wpf" on "the model class":

typically, model represents client-side domain model application. can define info structures based on application's info model , supporting business , validation logic. model may include code back upwards info access , caching, though typically separate info repository or service employed this. often, model , info access layer generated part of info access or service strategy, such ado.net entity framework, wcf info services, or wcf ria services.

typically, model implements facilities create easy bind view. means supports property , collection changed notification through inotifypropertychanged , inotifycollectionchanged interfaces. models classes represent collections of objects typically derive observablecollection class, provides implementation of inotifycollectionchanged interface.

the model may back upwards info validation , error reporting through idataerrorinfo (or inotifydataerrorinfo) interfaces. idataerrorinfo , inotifydataerrorinfo interfaces allow wpf info binding notified when values alter ui can updated. enable back upwards info validation , error reporting in ui layer.

what if model classes not implement required interfaces?

sometimes need work model objects not implement inotifypropertychanged, inotifycollectionchanged, idataerrorinfo, or inotifydataerrorinfo interfaces. in cases, view model may need wrap model objects , expose required properties view. values these properties provided straight model objects. view model implement required interfaces properties exposes view can info bind them.

i gather word on high somewhere between #1 (use them directly) , #3 (use wrapper), wcf proxy class model , wrapper class view model. per mvvm pattern, model (proxy) class should encapsulate business logic, while view model class should wrap proxy class , incorporate presentation logic.

you add together model-wrapper around proxy classes in cases need them back upwards additional interface such idataerrorinfo.

c# wpf wcf

No comments:

Post a Comment