强制 WCF 使用 NetDataContractSerializer\DataContractSerializer [英] Force WCF to use NetDataContractSerializer\DataContractSerializer

查看:21
本文介绍了强制 WCF 使用 NetDataContractSerializer\DataContractSerializer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何告诉某个 WCF 服务使用 DataContractSerializer 或 NetDataContractSerializer?

How can I tell a certain WCF Service to use DataContractSerializer or NetDataContractSerializer?

假设我成功了,生成的代理会自动识别并使用正确的吗?

Suppose I succeed, will the proxy generated automatically identify it and use the correct one?

推荐答案

DataContractSerializer 默认使用.在服务端,您可以通过行为控制使用的序列化程序.默认情况下,您有可用的 DataContractFormatXmlSerializerFormat 属性.这些属性可以应用于服务合同、服务实现或操作.在客户端,如果类型描述可通过 DataContractSerializer 序列化,则 svcutil 将使用数据协定序列化,否则它将使用 XmlSerializer.

DataContractSerializer is used by default. On the service side you can control used serializers with behaviors. By default you have available DataContractFormat and XmlSerializerFormat attributes for this. These attributes can be applied on service contract, service implementation or on operations. On client side svcutil will use data contract serialization if types description are serializable by DataContractSerializer otherwise it will use XmlSerializer.

NetDataContractSerializer 没有准备好行为 - 您必须自己创建它.它也不会被客户端识别,因为当您使用 NetDataContractSerializer 时,您将与客户端共享具有类型(数据合同、服务合同)的程序集,因此您也可以共享行为并直接用该行为标记服务合同.

NetDataContractSerializer doesn't have behaviour prepared - you must create it yourselves. It is also not recognized by clients because when you use NetDataContractSerializer you will share assemblies with types (data contracts, service contracts) with client so you can share behaviour as well and mark service contract with that behaviour directly.

这篇关于强制 WCF 使用 NetDataContractSerializer\DataContractSerializer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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