XML 序列化程序在序列化后丢失对象的值
XML Serializer looses values of the object after serialization
我有一个 wsdl 文档第 3 方并尝试将请求序列化到 XML。
我发现设置为对象实例的某些值(如 PaymentType)没有序列化。其他人(如 PersonName)。
这种问题的原因可能是什么以及如何解决?
问题不在 XML 本身,而是代理生成的。看起来上一步或某些设置应该有不同的原因。
这是一个例子:
以及第3方服务的XML类
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3056.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://fedex.com/ws/rate/v24")]
public partial class CustomsClearanceDetail {
private BrokerDetail[] brokersField;
private ClearanceBrokerageType clearanceBrokerageField;
private bool clearanceBrokerageFieldSpecified;
private CustomsOptionDetail customsOptionsField;
private Party importerOfRecordField;
private RecipientCustomsId recipientCustomsIdField;
private Payment dutiesPaymentField;
private InternationalDocumentContentType documentContentField;
private bool documentContentFieldSpecified;
private Money customsValueField;
private FreightOnValueType freightOnValueField;
private bool freightOnValueFieldSpecified;
private Money insuranceChargesField;
private bool partiesToTransactionAreRelatedField;
private bool partiesToTransactionAreRelatedFieldSpecified;
private CommercialInvoice commercialInvoiceField;
private Commodity[] commoditiesField;
private ExportDetail exportDetailField;
private RegulatoryControlType[] regulatoryControlsField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Brokers")]
public BrokerDetail[] Brokers {
get {
return this.brokersField;
}
set {
this.brokersField = value;
}
}
/// <remarks/>
public ClearanceBrokerageType ClearanceBrokerage {
get {
return this.clearanceBrokerageField;
}
set {
this.clearanceBrokerageField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool ClearanceBrokerageSpecified {
get {
return this.clearanceBrokerageFieldSpecified;
}
set {
this.clearanceBrokerageFieldSpecified = value;
}
}
/// <remarks/>
public CustomsOptionDetail CustomsOptions {
get {
return this.customsOptionsField;
}
set {
this.customsOptionsField = value;
}
}
/// <remarks/>
public Party ImporterOfRecord {
get {
return this.importerOfRecordField;
}
set {
this.importerOfRecordField = value;
}
}
/// <remarks/>
public RecipientCustomsId RecipientCustomsId {
get {
return this.recipientCustomsIdField;
}
set {
this.recipientCustomsIdField = value;
}
}
/// <remarks/>
public Payment DutiesPayment {
get {
return this.dutiesPaymentField;
}
set {
this.dutiesPaymentField = value;
}
}
/// <remarks/>
public InternationalDocumentContentType DocumentContent {
get {
return this.documentContentField;
}
set {
this.documentContentField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool DocumentContentSpecified {
get {
return this.documentContentFieldSpecified;
}
set {
this.documentContentFieldSpecified = value;
}
}
/// <remarks/>
public Money CustomsValue {
get {
return this.customsValueField;
}
set {
this.customsValueField = value;
}
}
/// <remarks/>
public FreightOnValueType FreightOnValue {
get {
return this.freightOnValueField;
}
set {
this.freightOnValueField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool FreightOnValueSpecified {
get {
return this.freightOnValueFieldSpecified;
}
set {
this.freightOnValueFieldSpecified = value;
}
}
/// <remarks/>
public Money InsuranceCharges {
get {
return this.insuranceChargesField;
}
set {
this.insuranceChargesField = value;
}
}
/// <remarks/>
public bool PartiesToTransactionAreRelated {
get {
return this.partiesToTransactionAreRelatedField;
}
set {
this.partiesToTransactionAreRelatedField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool PartiesToTransactionAreRelatedSpecified {
get {
return this.partiesToTransactionAreRelatedFieldSpecified;
}
set {
this.partiesToTransactionAreRelatedFieldSpecified = value;
}
}
/// <remarks/>
public CommercialInvoice CommercialInvoice {
get {
return this.commercialInvoiceField;
}
set {
this.commercialInvoiceField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Commodities")]
public Commodity[] Commodities {
get {
return this.commoditiesField;
}
set {
this.commoditiesField = value;
}
}
/// <remarks/>
public ExportDetail ExportDetail {
get {
return this.exportDetailField;
}
set {
this.exportDetailField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("RegulatoryControls")]
public RegulatoryControlType[] RegulatoryControls {
get {
return this.regulatoryControlsField;
}
set {
this.regulatoryControlsField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3056.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://fedex.com/ws/rate/v24")]
public partial class Payment {
private PaymentType paymentTypeField;
private bool paymentTypeFieldSpecified;
private Payor payorField;
/// <remarks/>
public PaymentType PaymentType {
get {
return this.paymentTypeField;
}
set {
this.paymentTypeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool PaymentTypeSpecified {
get {
return this.paymentTypeFieldSpecified;
}
set {
this.paymentTypeFieldSpecified = value;
}
}
/// <remarks/>
public Payor Payor {
get {
return this.payorField;
}
set {
this.payorField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3056.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://fedex.com/ws/rate/v24")]
public enum PaymentType {
/// <remarks/>
SENDER,
}
对于这些类型和其他一些类型,在生成的 类 中有一个额外的 属性。例如,如果其中一个不起作用的属性被命名为 "Property1",那么还有另一个 属性 被命名为 "Property1Specified"。序列化将忽略这些属性,除非“...Specified”属性设置为 true。将所有这些属性指定的属性设置为 true 现在允许序列化显示所有预期的元素。
正如我所说,这与 XML 属性、结构或类似的 smht 无关。原因是 XML 和要序列化的对象的设置
我有一个 wsdl 文档第 3 方并尝试将请求序列化到 XML。 我发现设置为对象实例的某些值(如 PaymentType)没有序列化。其他人(如 PersonName)。 这种问题的原因可能是什么以及如何解决? 问题不在 XML 本身,而是代理生成的。看起来上一步或某些设置应该有不同的原因。
这是一个例子:
以及第3方服务的XML类
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3056.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://fedex.com/ws/rate/v24")]
public partial class CustomsClearanceDetail {
private BrokerDetail[] brokersField;
private ClearanceBrokerageType clearanceBrokerageField;
private bool clearanceBrokerageFieldSpecified;
private CustomsOptionDetail customsOptionsField;
private Party importerOfRecordField;
private RecipientCustomsId recipientCustomsIdField;
private Payment dutiesPaymentField;
private InternationalDocumentContentType documentContentField;
private bool documentContentFieldSpecified;
private Money customsValueField;
private FreightOnValueType freightOnValueField;
private bool freightOnValueFieldSpecified;
private Money insuranceChargesField;
private bool partiesToTransactionAreRelatedField;
private bool partiesToTransactionAreRelatedFieldSpecified;
private CommercialInvoice commercialInvoiceField;
private Commodity[] commoditiesField;
private ExportDetail exportDetailField;
private RegulatoryControlType[] regulatoryControlsField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Brokers")]
public BrokerDetail[] Brokers {
get {
return this.brokersField;
}
set {
this.brokersField = value;
}
}
/// <remarks/>
public ClearanceBrokerageType ClearanceBrokerage {
get {
return this.clearanceBrokerageField;
}
set {
this.clearanceBrokerageField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool ClearanceBrokerageSpecified {
get {
return this.clearanceBrokerageFieldSpecified;
}
set {
this.clearanceBrokerageFieldSpecified = value;
}
}
/// <remarks/>
public CustomsOptionDetail CustomsOptions {
get {
return this.customsOptionsField;
}
set {
this.customsOptionsField = value;
}
}
/// <remarks/>
public Party ImporterOfRecord {
get {
return this.importerOfRecordField;
}
set {
this.importerOfRecordField = value;
}
}
/// <remarks/>
public RecipientCustomsId RecipientCustomsId {
get {
return this.recipientCustomsIdField;
}
set {
this.recipientCustomsIdField = value;
}
}
/// <remarks/>
public Payment DutiesPayment {
get {
return this.dutiesPaymentField;
}
set {
this.dutiesPaymentField = value;
}
}
/// <remarks/>
public InternationalDocumentContentType DocumentContent {
get {
return this.documentContentField;
}
set {
this.documentContentField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool DocumentContentSpecified {
get {
return this.documentContentFieldSpecified;
}
set {
this.documentContentFieldSpecified = value;
}
}
/// <remarks/>
public Money CustomsValue {
get {
return this.customsValueField;
}
set {
this.customsValueField = value;
}
}
/// <remarks/>
public FreightOnValueType FreightOnValue {
get {
return this.freightOnValueField;
}
set {
this.freightOnValueField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool FreightOnValueSpecified {
get {
return this.freightOnValueFieldSpecified;
}
set {
this.freightOnValueFieldSpecified = value;
}
}
/// <remarks/>
public Money InsuranceCharges {
get {
return this.insuranceChargesField;
}
set {
this.insuranceChargesField = value;
}
}
/// <remarks/>
public bool PartiesToTransactionAreRelated {
get {
return this.partiesToTransactionAreRelatedField;
}
set {
this.partiesToTransactionAreRelatedField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool PartiesToTransactionAreRelatedSpecified {
get {
return this.partiesToTransactionAreRelatedFieldSpecified;
}
set {
this.partiesToTransactionAreRelatedFieldSpecified = value;
}
}
/// <remarks/>
public CommercialInvoice CommercialInvoice {
get {
return this.commercialInvoiceField;
}
set {
this.commercialInvoiceField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Commodities")]
public Commodity[] Commodities {
get {
return this.commoditiesField;
}
set {
this.commoditiesField = value;
}
}
/// <remarks/>
public ExportDetail ExportDetail {
get {
return this.exportDetailField;
}
set {
this.exportDetailField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("RegulatoryControls")]
public RegulatoryControlType[] RegulatoryControls {
get {
return this.regulatoryControlsField;
}
set {
this.regulatoryControlsField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3056.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://fedex.com/ws/rate/v24")]
public partial class Payment {
private PaymentType paymentTypeField;
private bool paymentTypeFieldSpecified;
private Payor payorField;
/// <remarks/>
public PaymentType PaymentType {
get {
return this.paymentTypeField;
}
set {
this.paymentTypeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool PaymentTypeSpecified {
get {
return this.paymentTypeFieldSpecified;
}
set {
this.paymentTypeFieldSpecified = value;
}
}
/// <remarks/>
public Payor Payor {
get {
return this.payorField;
}
set {
this.payorField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3056.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://fedex.com/ws/rate/v24")]
public enum PaymentType {
/// <remarks/>
SENDER,
}
对于这些类型和其他一些类型,在生成的 类 中有一个额外的 属性。例如,如果其中一个不起作用的属性被命名为 "Property1",那么还有另一个 属性 被命名为 "Property1Specified"。序列化将忽略这些属性,除非“...Specified”属性设置为 true。将所有这些属性指定的属性设置为 true 现在允许序列化显示所有预期的元素。
正如我所说,这与 XML 属性、结构或类似的 smht 无关。原因是 XML 和要序列化的对象的设置