使用WCF从类库中公开对象 [英] Expose object from class library using WCF

查看:73
本文介绍了使用WCF从类库中公开对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个公开一些对象的类库.这些对象具有几个属性,可以保存我的客户需要的数据.我想创建一个WCF服务,将对象返回给我的客户端,但是我无法更新类库以添加DataContract和DataMember属性.暴露这些物体的最简单方法是什么?

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?

推荐答案

您可以使用

...您可以应用DataContract 属性归于Person类,但是 这并不总是可能的.为了 例如,Person类可以是 在单独的程序集中定义 您无法控制.

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

鉴于此限制,一种方法 序列化Person类是为了 用另一个类代替它 标记有DataContractAttribute 并将必要的数据复制到 新课.目的是使 Person类显示为 DataContract到 DataContractSerializer.请注意, 是序列化非数据的一种方法 合同类. ...

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

这篇关于使用WCF从类库中公开对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆