简体   繁体   English

实现IXmlSerializable的WCF词典

[英]WCF Dictionary implementing IXmlSerializable

I have some WCF services which employes default DataContractSerialization. 我有一些使用默认DataContractSerialization的WCF服务。 Some of the service methods return Dictionary objects. 一些服务方法返回Dictionary对象。 One of the clients are generating XSD files from WCF services (biztalk related) and he is requesting to convert all dictionary types to a new dictionary type which implements IXmlSerializable. 其中一个客户端正在从WCF服务(与biztalk相关)生成XSD文件,并且他正在请求将所有词典类型转换为实现IXmlSerializable的新词典类型。 I wonder, if there will be any unexpected results of this conversion which may affect the DataContract serialization somehow? 我想知道这种转换是否会出现任何意外的结果,从而可能以某种方式影响DataContract的序列化?

Update: Server and client share the same domain dlls, clients do not generate them from service. 更新:服务器和客户端共享相同的域dll,客户端不会从服务生成它们。 Maybe in the question I was missing the main point; 也许在这个问题上,我没有提到要点。 I wonder if an object is to be serizalized through datacontract serialization, implementing IXmlSerializable in the object will cause any problems. 我想知道是否要通过数据合同序列化来序列化对象,在对象中实现IXmlSerializable会引起任何问题。

There is an unexpected problem; 有一个意想不到的问题。 since domain objects are already implementing data contract serialization, there is no way to implement IXmlSerializable without modifying the whole serialization mechanism. 由于域对象已经在实现数据协定序列化,因此如果不修改整个序列化机制就无法实现IXmlSerializable。

Is your client sharing dlls with the service? 您的客户端与服务共享dll吗?

Unless he is sharing libraries (dlls) with service then making changes at the service end won't make any difference. 除非他与服务共享库(dll),否则在服务端进行更改不会有任何区别。 Your WCF is returning data, not classes. 您的WCF正在返回数据,而不是类。 That data is being reconstituted into classes which are created by the client based on the definitions in the WSDL your service returns. 该数据将重构为由客户端根据您的服务返回的WSDL中的定义创建的类。 You can't control those generated libraries (by making chnages on the server) unless you share dlls between the client and the server. 除非您在客户端和服务器之间共享dll,否则您将无法控制这些生成的库(通过在服务器上进行更改)。

If he wants to wrap the generated dictionaries in an IXmlSerializable dictionary then he can, or if he wants to generate a different type of dictionary then he can probably do that as well, but I don't think there is anything you can do server side. 如果他想将生成的字典包装在IXmlSerializable字典中,那么他可以,或者如果他想生成其他类型的字典,那么他也可以做​​到这一点,但是我认为您无法在服务器端做任何事情。

Tell your client to use the following serializable dictionary when they need to serialize a dictionary result from a service call: C# Serializable Dictionary – a Working Example 告诉您的客户端,当他们需要对服务调用中的字典结果进行序列化时,使用以下可序列化的字典: C#序列化字典–工作示例

It accepts an ordinary dictionary as constructor argument thus converts any dictionary into a serializable one. 它接受普通字典作为构造函数参数,从而将任何字典转换为可序列化的字典。 You can also return SerializableDictionary type as the service call result if you like. 如果愿意,您还可以返回SerializableDictionary类型作为服务调用结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在集合对象上实现IXmlSerializable - Implementing IXmlSerializable on a collection object 为包含集合的类实现IXmlSerializable - Implementing IXmlSerializable for Classes Containing Collections 反序列化实现 IXmlSerializable 的类型集合永远运行 - Deserializing collection of types implementing IXmlSerializable runs forever 在具有XmlTypeAttribute的生成类上实现IXmlSerializable - Implementing IXmlSerializable on a generated class that has XmlTypeAttribute WCF REST 无法反序列化实现 IXMLSerializable 的类 - WCF REST is failing to deserialize class that implements IXMLSerializable 为包含或不带有CDATA标签的数据的内容实现IXmlSerializable - Implementing IXmlSerializable for content containing data with or without CDATA tags 在实现IXmlSerializable接口时处理字符串的空值 - handle null values for string when implementing IXmlSerializable interface C#:带有IXMLSerializable成员的WCF服务变为DataSet - C# : WCF Service with IXMLSerializable member turns into DataSet 序列化只读集合,而无需实现IXmlSerializable - Serialize read-only collection without implementing IXmlSerializable 我可以在不实现IXmlSerializable的情况下为XmlSerializer提供自定义序列化吗? - Can I provide custom serialization for XmlSerializer without implementing IXmlSerializable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM