如何通过WCF公开对象?对象、WCF

2023-09-03 06:01:38 作者:烟火つ

我的项目分解成一个典型的3层结构的Silverlight应用程序。那就是:

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

在基层,这是一个包含所有的业务对象,逻辑,数据访问等类库。 系统中间层是与通信的WCF服务; 在我的Silverlight前端

我的问题是,目前BO的通过WCF暴露在我的UI只包含私有变量,并且没有一个propertys或方法。

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?

推荐答案

看来你期待中标记为已DataContracts导出为.NET对象到客户端code WCF服务使用内部类(Silverlight的UI)。 WCF不支持此功能。标记为DataContract甲类就是这样,一个数据结构的没有方法。如果你需要一个很好的资源为undestanding WCF,尝试学习WCF:一个动手在导游米歇尔Bustamente 。

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.

@约翰费舍尔确实勾画出暴露.NET对象同时在客户端和放大器的一种方式;服务,但这可能不是Silverlight的一种选择。这里是一个博客条目讲解如何从Silverlight的访问基于REST的服务。

@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.