Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expose objects through WCF?

My project is split up into a typical 3 layer structure for a Silverlight app. That is:

  • A base layer, which is a class library that contains all my business objects, logic, data access etc.
  • A middle layer which is a WCF service which communicates with;
  • My Silverlight front end

The problem I have is that currently the BO's exposed through WCF to my UI only contain the private variables, and none of the propertys or methods.

Is there an easy way to expose the full object (via attributes or configuration)?

What is the best solution?

like image 671
mwjackson Avatar asked Dec 28 '25 14:12

mwjackson


1 Answers

It seems that you are expecting internal classes used in the WCF service which you have marked as DataContracts to be exported as .NET objects to your client code (the Silverlight UI). WCF does not support this capability. A class marked as a DataContract is just that, a data structure with no methods. If you need a good resource for undestanding WCF, try Learning WCF: A Hands-on Guide by Michele Bustamente.

@John Fisher does sketch out a way of exposing .NET objects to both the client & service but this may not be an option for Silverlight. Here is a blog entry explaining how to access REST-based services from Silverlight.

like image 136
Sixto Saez Avatar answered Dec 31 '25 04:12

Sixto Saez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!