Expose object from class library using WCF

爱⌒轻易说出口 提交于 2019-12-01 18:54:34

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

If you can't set the [DataContract] and [DataMember] attributes on your object, you'll have to find a way to expose them using the XmlSerializer.

You can define a service or an operation to use the XmlSerializer by specifying the [XmlSerializerFormat] attribute on either your Service contract, or an individual OperationContract.

Does that help maybe?

Marc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!