Database Reference
In-Depth Information
There are two problems with dynamic proxies and WCF. The first problem has to do with the serialization of the
proxy. The DataContractSerializer can only serialize and deserialize known types, such as the Client entity in our
example. However, as Entity Framework generates a dynamic proxy class for the Client entity, we need to serialize the
proxy class, not the Client. Here is where DataContractResolver comes to the rescue. It can map one type to another
during serialization. ProxyDataContractResolver derives from DataContractResolver and maps proxy types to POCO
classes, such as our Client entity. To use the ProxyDataContractResolver, we created an attribute (see Listing 9-34) to
resolve proxies into POCO classes. We applied this attribute to the GetClient() method in Listing 9-36. This causes
the dynamic proxy for the Client entity returned by the GetClient() to be correctly serialized for its journey to the
user of the WCF service.
The second problem with dynamic proxies and WCF has to do with lazy loading. When the
DataContractSerializer serializes the entity, it accesses each of the properties of the entity that would trigger lazy
loading of navigation properties. This, of course, is not what we want. To prevent this, we explicitly turned off lazy
loading in Listing 9-36.
 
Search WWH ::




Custom Search