Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expose object from class library using WCF

I'm using a class library that exposes a few objects. These objects have a couple of properties that hold data my clients need. I'd like to create a WCF service that returns the objects to my clients but I cannot update the class library in order to add the DataContract and DataMember attributes. What is the easiest way of exposing these objects?

like image 874
Kyle Russell Avatar asked Jan 24 '23 16:01

Kyle Russell


1 Answers

You can use a DataContractSurrogate.

...You can apply the DataContract attribute to the Person class, but this is not always possible. For example, the Person class can be defined in a separate assembly over which you have no control.

Given this restriction, one way to serialize the Person class is to substitute it with another class that is marked with DataContractAttribute and copy over necessary data to the new class. The objective is to make the Person class appear as a DataContract to the DataContractSerializer. Note that this is one way to serialize non-data contract classes. ...

like image 137
Brian Avatar answered Jan 31 '23 06:01

Brian