c# - .NET 4.8 - WCF 复杂架构 - 使用 XmlSerializer 将派生类型作为基础呈现
问题描述
由于继承,我在使用具有复杂架构的 SOAP 服务时遇到重大问题
我有一个基本类型ProcessMessage
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ProcessCustomerMessage))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.8.3928.0")]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public abstract class ProcessMessage
{
}
然后我有多个派生类型,例如ProcessCustomerMessage
ProcessRepairMessage
继承基类。
问题是我需要将派生类型作为基础,以便服务接受它
我已经遵循了我可以添加的文档XmlInclude
以及XmlType
在需要的地方...
/// <remarks/>
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlType(TypeName = "ProcessMessage", AnonymousType = true, Namespace = "http://www.mynamespace.org")]
public class ProcessCustomerMessage: ProcessMessage {
private ProcessCustomerInformationPayload payloadField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order = 0)]
public ProcessCustomerInformationPayload payload {
get {
return this.payloadField;
}
set {
this.payloadField = value;
}
}
}
上面的代码将正确序列化,但服务拒绝它并出现以下错误
Unknown type {tran:ProcessMessage} specified in xsi:type attribute
这是因为xsi:type="tran:ProcessMessage"
在 Xml
<tran:ProcessMessage xsi:type="tran:ProcessMessage" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
我看不到如何xsi:type
从 Xml中删除它
我使用的是 XmlSerializer 而不是 DCS,因为架构非常复杂,不受 DCS 支持,我也无法控制架构作为其第 3 方服务。
解决方案
推荐阅读
- python - 如何识别字符串的最小形式?
- unity3d - 无法使用“屏幕空间叠加”在画布中获取对象的真实位置
- angular - ASP.Net Core 服务器中的 Angular PWA - Serviceworker-Cache 不起作用
- verilog - verilog/系统verilog中的最大线位宽度是多少
- python - 有哪些方法可以为 Flask 应用程序播种?
- python - 如何删除换行符但在文本文件中保留空白行?
- mysql - 将动态参数传递给 gman_do mysql udf 函数
- apache-nifi - 通过 SplitJson 和 MergeContent 过滤 JSON
- sql - 查找同一列的时间戳差异,但依赖于其他列的事件
- python - Selenium Webscraping 与循环列表