Esempio n. 1
0
        public async Task <SdiResponse> SendAsync(ElectronicInvoice invoice)
        {
            var invoiceXmlDoc       = XmlManipulator.Serialize(invoice);
            var signedInvoiceXmlDoc = XmlSigner.Sign(invoiceXmlDoc, SignatureCertificate);

            var signedInvoiceXml   = signedInvoiceXmlDoc.OuterXml;
            var signedInvoiceBytes = Encoding.UTF8.GetBytes(signedInvoiceXml);

            var messageBody = new ReceiveFile
            {
                Content  = signedInvoiceBytes,
                FileName = GetSignedInvoiceFileName(invoice)
            };

            var response = await SoapClient.SendAsync <ReceiveFile, ReceiveFileResponse>(messageBody, operation : "http://www.fatturapa.it/SdIRiceviFile/RiceviFile");

            if (response.ErrorSpecified)
            {
                return(new SdiResponse(GetSdiError(response.Error)));
            }

            return(new SdiResponse(new SdiFileInfo(
                                       receivedUtc: response.ReceivedOn,
                                       sdiIdentifier: response.SdiIdentification
                                       )));
        }
        private string Serialize(ElectronicInvoice invoice)
        {
            var xmlNamespaces = new XmlSerializerNamespaces();

            xmlNamespaces.Add("p", ElectronicInvoice.Namespace);

            var xml = XmlManipulator.Serialize(invoice, xmlNamespaces).OuterXml;

            return($@"{XmlFileHeader}{xml}");
        }