可以在WCF服务中同时使用DataContractSeriali

可以在WCF服务中同时使用DataContractSeriali

本文介绍了是否可以在WCF服务中同时使用DataContractSerializer和XmlSerializer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

是否可以在WCF服务中同时使用DataContractSerializer和XmlSerializer(将它们组合),并且也可以使用一种方法?

我有一个带有大约50个带有DataContract-attributes标记的类的项目.我也有一些必须使用的外部XSD方案,它与DataContractSerializer不兼容(集合未在标签中分组).我从这些模式中生成了带有XmlSerializer-attributes标记的类(另50个).我的解决方案与此类似:

标记为DataContracts的类:
-驱动程序
-车轮
-ConnectionInfo

标记为XmlSerializable的类:
-StandarizedCar
-MyCustomCar:StandarizedCar

因此,Standarized汽车是从XSD生成的,并带有XmlSerializable属性标记.我制作了一个MyCustomCar类,它扩展了StandarizedCar并添加了一些属性(例如wheel和driver,请注意Wheel是DataContract).我想通过以下方法进行服务:

Hi!

Is it possible to use both DataContractSerializer and XmlSerializer (combine them) in a WCF-service, and maybe also in one method?

I have a project with approximately 50 classes marked with DataContract-attributes. I altso have some external XSD-schemas I have to use wich is not compatible with DataContractSerializer (collections are not grouped in a tag). I have generated classes (another 50) marked with XmlSerializer-attributes from these schemas. My solution looks similar to this:

Classes marked as DataContracts:
- Driver
- Wheel
- ConnectionInfo

Classes marked as XmlSerializable:
- StandarizedCar
- MyCustomCar : StandarizedCar

So, Standarized car is generated from XSD and marked with XmlSerializable-attributes. I made a class MyCustomCar wich extends StandarizedCar and adds some properties (like wheels and a driver, notice that Wheel is a DataContract). I want to make a service with the following methods:

void:Connect(ConnectionInfo info)
MyCustomCar:GetCustomCar(int carID)
void:AddWheel(Wheel wheel)



我的问题:

1.我的服务可以同时使用DataContractSerializer和XmlSerializer吗?
2.我的方法GetCustomCar()可以同时使用DataContractSerializer和XmlSerializer,还是必须为每种方法选择一个?
3.是否可以同时使用DataContractSerializer属性和XmlSerializer属性标记Wheel?
4.即使Wheels没有任何XmlSerializer属性,即使我用[XmlSerializerFormat]标记它,GetCustomCar也会起作用吗?



My question(s):

1. Can my Service use both DataContractSerializer and XmlSerializer?
2. Can my method GetCustomCar() use both DataContractSerializer and XmlSerializer, or do I have to choose one for each method?
3. Can I mark Wheel with both DataContractSerializer-attributes AND XmlSerializer attributes?
4. Will GetCustomCar work if I mark it with [XmlSerializerFormat] even though Wheels don''t have any XmlSerializer-attributes)?

推荐答案


这篇关于是否可以在WCF服务中同时使用DataContractSerializer和XmlSerializer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 08:45