I'm writing a .net WCF service. I've written a few classes that I want to return to the calling code from the WCF service; hence, I decorate them with the DataContract
attribute.
Let's suppose that my WCF service is called FooService
. It contains a method called FooMethod
which returns an object of type FooData
(which is decorated with the DataContract
attribute. Suppose that FooData
contains a list of numbers and a method called FooAverage
which returns the average value of the numbers.
In Visual Studio, I create a new application to consume the service. I add a new "Service Reference" to my WCF Service and give it the namespace myWcfService
. In my client code, I instantiate a proxy class and get a connection to the service. To get the FooData
object from my proxy, the method call is myWcfService.FooMethod()
. It returns an object of type myWcfService.FooData
, which is a type determined from the FooService
metadata.
Now that I have my object of type myWcfService.FooData
, how can I get this data into an object of type FooData
as the original type from the service code so that I can call FooData.FooAverage()
?
Edit: I am entirely aware of the fact that data comes down the pipe in XML format and that the logic of the methods in a class decorated with DataContract
does not get returned by the service; it isn't serializable. What I'm asking is: if I can reference the class that contains the DataContract
class used in the service, is there a straightforward way to de-serialize the data into the class that it was serialized from?
I am willing to accept the answer that it is not possible with the current .net framework.