最初的问题是,当我使用类型调用webservice(asmx)方法时,类型始终为null。检查肥皂证实了这种类型是一个空元素。所以我尝试了一个简单的测试 这是我的类型,当然是从WSDL生成的
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://dto12.api.echosign")]
public partial class SendDocumentInteractiveOptions {
private bool authoringRequestedField;
private bool authoringRequestedFieldSpecified;
private bool autoLoginUserField;
private bool autoLoginUserFieldSpecified;
private bool noChromeField;
private bool noChromeFieldSpecified;
/// <remarks/>
public bool authoringRequested {
get {
return this.authoringRequestedField;
}
set {
this.authoringRequestedField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool authoringRequestedSpecified {
get {
return this.authoringRequestedFieldSpecified;
}
set {
this.authoringRequestedFieldSpecified = value;
}
}
/// <remarks/>
public bool autoLoginUser {
get {
return this.autoLoginUserField;
}
set {
this.autoLoginUserField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool autoLoginUserSpecified {
get {
return this.autoLoginUserFieldSpecified;
}
set {
this.autoLoginUserFieldSpecified = value;
}
}
/// <remarks/>
public bool noChrome {
get {
return this.noChromeField;
}
set {
this.noChromeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool noChromeSpecified {
get {
return this.noChromeFieldSpecified;
}
set {
this.noChromeFieldSpecified = value;
}
}
}
现在这里有一些简单的代码来序列化它。
SendDocumentInteractiveOptions sdio = new SendDocumentInteractiveOptions();
sdio.authoringRequested = true;
sdio.autoLoginUser = true;
sdio.noChrome = true;
XmlSerializer xmlSer = new XmlSerializer(typeof(SendDocumentInteractiveOptions));
XmlWriter xw = new XmlTextWriter(@"g:\test.xml", null);
xmlSer.Serialize(xw, sdio);
xw.Close();
这是生成的XML
<?xml version="1.0"?>
<SendDocumentInteractiveOptions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
所以我在这里错过了什么。为什么我的公共属性没有被序列化?
答案 0 :(得分:1)
这是一个老问题,但是哦。我认为解决方案可能是另一个问题"Why isn't my public property serialized by the XmlSerializer?"。部分答案列出了为什么属性不会被序列化并且该列表中
的原因在您的代码中,您可以设置各种布尔值,但设置相关的指定值。我遇到了类似的问题,并为我设置了指定值。