更新1 問題不是多個命名空間。 我不知道爲什麼,但如果手動創建生成的類的對象,分配的簽名字段和序列化對象,簽名節點節點的命名空間爲:Xml反序列化c#與多個命名空間
<Signature xmlns="http://www.abrasf.org.br/nfse.xsd">
代替
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
如果我給你在XML usign證書,簽名的命名空間是
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
有了第一個命名空間,我可以毫無問題deseralizate,但我需要 標誌。
Generated Class from wsdl using wsdl.exe
EnviarLoteRpsEnvio類的EnviarLoteRpsEnvio nfse.xsd:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.abrasf.org.br/nfse.xsd")]
public partial class EnviarLoteRpsEnvio
{
private tcLoteRps loteRpsField;
private SignatureType signatureField;
/// <remarks/>
public tcLoteRps LoteRps
{
get { return this.loteRpsField; }
set { this.loteRpsField = value; }
}
/// <remarks/>
public SignatureType Signature
{
get { return this.signatureField; }
set { this.signatureField = value; }
}
}
SignatureTypeClass:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2000/09/xmldsig#")]
public partial class SignatureType {
private SignedInfoType signedInfoField;
private SignatureValueType signatureValueField;
private KeyInfoType keyInfoField;
private ObjectType[] objectField;
private string idField;
/// <remarks/>
public SignedInfoType SignedInfo {
get {
return this.signedInfoField;
}
set {
this.signedInfoField = value;
}
}
/// <remarks/>
public SignatureValueType SignatureValue {
get {
return this.signatureValueField;
}
set {
this.signatureValueField = value;
}
}
從生成的類,產生後續的xml:
但是,當我嘗試deserealize這個XML,使用功能:
public static object DeserializarParaObjeto(string xmlStr, Type tipo)
{
TextReader tx = new StringReader(xmlStr);
XmlSerializer deSerializer = new XmlSerializer(tipo);
deSerializer.UnknownAttribute += deSerializer_UnknownAttribute;
deSerializer.UnknownElement += deSerializer_UnknownElement;
deSerializer.UnknownNode += deSerializer_UnknownNode;
deSerializer.UnreferencedObject += deSerializer_UnreferencedObject;
return deSerializer.Deserialize(tx);
}
事件deSerializer_UnknownNode被調用(節點未知,簽名)。 生成對象,但未分配節點簽名。
發生這種情況是因爲xml包含多個名稱空間?
在這種情況下我需要做什麼?
Ps:我沒有發佈所有的XML和模式,因爲太大。