Converting Serialized WCF Objects to Native Objects

I miss the .Net days when I could just send an object over the wire and it would work on both sides of the middle layer with little effort. That's why:

I was given an assignment. I am creating a Logic / Data Abstraction layer (stupid PCI compliance) so that we can move our database servers from the corporate network to a secure network. I have done such a project once under .Net 2.0 with deletion. I built a middleware object and sent that object to the client and the client had my .Net object to work with. But WCF requires serialization in order to be able to send things up and down the pipe, and serialization takes my fancy methods that do incredible things with the fields I have.

I have developed two different strategies to get around this: (1) Move the methods from the class itself to the static utility class, and (2) "Deserialize" the data on the client side and rebuild the native data object from the serialized object.

nativeObject.Name = serializedObject.Name;

      

The downside to the second method is that I have to re-serialize the object before I can send it back to the middle layer.

serializedObject.Name = nativeObject.Name;

      

Both methods work, but the write objects are taking much longer than they should due to all the serialization mess caused by the middle tier. I'll go back to .Net Remoting, but the architect says he wants this abstraction layer to be done in WCF because (my words, not his) are new and sexy.

So how does one deal with .Net native objects on both sides of a WCF connection ... without putting in 1000 lines of glue code.

+1


source to share


1 answer


You can create a proxy and tell it to use a specific set of classes instead of creating new ones. I believe this is done using the / r svutil.exe option. If you are using the IDE (VS2008), you can do this by adding the service reference, click Advanced and make sure Reuse types in assemblies are selected (which I think is the default).



+1


source







All Articles