質問

UPDATE 1 The problem is not multiple namespace. I dont know why, but if create the object from generated class, assigned Signature field manually and serialize the object, the namespace of Signature node node is :

<Signature xmlns="http://www.abrasf.org.br/nfse.xsd">

instead

<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">

If i assign the xml usign certificate, the namespace of Signature is

<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">

With the first namespace, i can deseralizate without problem, but i need to sign.

Generated Class from wsdl using wsdl.exe

WSDL


EnviarLoteRpsEnvio of nfse.xsd

schema EnviarLoteRpsEnvio class:

/// <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;
        }
    }

From the generated classes, was generated the follow xml :

xml generated

But when i try to deserealize this xml, using the function:

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);
}

The event deSerializer_UnknownNode is invoked ( node unknow, Signature ). The object is generated, but the node signature is not assigned.

This happens because the xml contains multiple namespaces?

What i need to do in this case ?

Ps: I don't post all xml and schemas because is too large.

役に立ちましたか?

解決

I solve my problem, in fact the problem was not my.

I needed to edit manually the class generated by wsdl.exe and add XmlRootAttribute on :

partial class EnviarLoteRpsEnvio:

[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.abrasf.org.br/nfse.xsd", IsNullable = false)]

Partial class Signature:

[System.Xml.Serialization.XmlRootAttribute("Signature", Namespace = "http://www.w3.org/2000/09/xmldsig#", IsNullable = false)]

And on porperty SignatureType Signature of partial class EnviarRpsEnvio:

[System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.w3.org/2000/09/xmldsig#")]

I know that we must never alter the generated class, but i had no alternative in this case.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top