first_page

My WCF Approach

So, it’s WPF on the client and WCF on the server. In my last post about Entity Framework, of importance was working with a technology ‘safely’ within a conceptual framework—one might call this concept*-first programming*. With WCF the foremost concept is interface-based programming.

Developers who really like to write tests for code are attracted to interfaces because of the need for writing tests—a respectable design goal. With WCF, the use of interfaces is required for the application to run properly. It starts with the WCF ServiceContract attribute applied to the interface used for service operations. —Now, the first question I should have asked years ago is, ‘Why are DataContract definitions classes and not interfaces?’ The answer is “obvious” but does not really answer the question. A WCF endpoint needs to emit concrete types with flesh-and-blood data—so we can’t use interfaces for DataContract definitions. But…but we can design for DataContract classes to implement interfaces.

There are three practical reasons (that have nothing to do with testing) why my DataContract classes implement interfaces.

  • One: They provide ‘escape’ from the tangled complexity of Entity Framework 3.x tendrils on the server.
  • Two: They allow me to ‘confine’ Service Proxy Types on the client to a smaller area of concern. The data transfer interfaces can run rampant in a larger area. There is no reason why my ASP.NET MVC/WPF View needs to know about WCF proxy types. Yes, we have the wonders of “proxy-type reuse”—and, when I reuse my proxy types, the interfaces they implement are preserved and are ready for use!
  • Three: They allow me prepare data for input into the WCF service—without excessive knowledge of the WCF DataContract classes and associated proxy types.### Collections and Data Transfer Interfaces

The walk through how to get EntityCollection<MyEntity> to IList<IMyEntity> was one of the most time-consuming leg of my journey to this low-level of WCF understanding. The problem (for me) was in two parts: (i) getting out of EntityCollection<T> and (ii) getting WCF to transmit IList<IMyEntity> without it being a collection full of nulls. More on this later…

rasx()