7375

What should keep into this design approach

Question:

My Project solution is as below:

<ol><li>MVC Project (Containing reference of both projects listed below)</li> <li>WCF Service containing business methods (Containg reference of below listed project)</li> <li>Common Project for DTO or BusinessOBject</li> </ol>

IN MVC - Calling the WCF service method is as follow - IList<Employee> RetriveData() it is called from MVC - ServiceClient.RetrieveData() , now problem is return object Employee point to ServiceHost.Employee object instead of - Common.DTO.Employee object (Library project) so, it gives type casting error.

Can any one suggest me what is the solution over here or i should remove "Common.DTO" project refernece from MVC and only use Servicehost.Employee object.

Please guide me on this design, what should use.

NOTE: all objects are DATACONTRACT (serilizable). In MVC applicaiton, after retrieing DTO object, i do convert them into Viewmodel (It also internally refer any collection object like IList<ServiceHost.LookupItem> . Does it ok to use all generated serilized object directly OR , do i have to convert/cast each return object into common.DTO. object and then convert into ViewModel ?

Thank You

Answer1:

<strong>Don't</strong> use <em>Visual Studio's</em> <strong>Add Service Reference</strong>. Doing so will result in <em>multiple types</em> being defined in the solution and <em>client-proxies</em> that over time will become <em>out of sync</em>.

It is much better to define a common contracts assembly that your whole solution uses.

Please see <em><a href="http://www.devx.com/codemag/Article/39837" rel="nofollow" title="WCF the Manual Way…the Right Way">WCF the Manual Way…the Right Way</a></em> specifically page 3

You should try to follow patterns such as canonical data model whenever possible. This means the same type for POCO ORM; WCF; and as aggregates in your view model. Data conversion is expensive; leads to increased maintenance and possible fidelity loss. <a href="http://www.soapatterns.org/" rel="nofollow">http://www.soapatterns.org/</a> <a href="http://www.eaipatterns.com/" rel="nofollow">http://www.eaipatterns.com/</a>

Answer2:

This really depends on what level of abstraction you want.

If ServiceHost.Employee is your domain model and MVC is your presentation layer then it would make sense to use a DTO to bridge the gap here. Given that's the approach you seem to want to use then the solution would be to have ServiceClient.RetrieveData return IList<Common.DTO.Employee> instead of IList<ServiceHost.Employee>.

Recommend

  • Centering bootstrap navbar hamburger
  • Array splitting based on value
  • Soap and Rest on same service returns status 404/endpoint not found for soap endpoint
  • How to set endpoint in runtime
  • WCF Multiple channels for one service instance
  • WCF Udp Discovery in mono
  • Multiple Dispatch with Generics
  • OpenCV imread with foreign characters
  • Cast uint -> double invalid?
  • Redshift Querying: error xx000 disk full redshift
  • C++ pointer value changes with static_cast
  • Rails Find when some params will be blank
  • Deselecting radio buttons while keeping the View Model in synch
  • Nant, Vault & Windows Integrated Authentication
  • Regex thinks I'm nesting, but I'm not
  • What is the “return” in scheme?
  • Fetching methods from BroadcastReceiver to update UI
  • Bug in WPF DataGrid
  • TFS: Get latest causes slow project reloading
  • Controls, properties, events and timers running in design time
  • Running a C# exe file
  • Join two tables and save into third-sql
  • How to model a transition system with SPIN
  • ORA-29908: missing primary invocation for ancillary operator
  • How can I estimate amount of memory left with calling System.gc()?
  • AT Commands to Send SMS not working in Windows 8.1
  • How to disable jQuery.jplayer autoplay?
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Linking SubReports Without LinkChild/LinkMaster
  • Is it possible to post an object from jquery to bottle.py?
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?
  • Converting MP3 duration time
  • How to push additional view controllers onto NavigationController but keep the TabBar?