1
My project has a class with the type property string which receives the XML of a Tax Note signed by SEFAZ. The system must send the property as a parameter to a WebService
that only returns an error.
Debugging I noticed that the property NotaFiscalXML
gets the result of the XML query without escape. When the system concatenates the property with the 'envelope' of the request the escapes are added. According to the developer’s support WS, it is necessary to remove the escapes so that there are no errors in the request. Having this answer I decided to use the function Regex.Unescape()
but even so property still contains Char Escape before quotation marks. The following code is a small example of how I am developing:
private string _notaFiscalXML {get; set;}
public string NotaFiscalXML {get => _notaFiscalXML; set => _notaFiscalXML = value;}
string EstruturaEnvelope ="";
string Envelope = "";
NotaFiscalXML = "<NFe xmlns="http://www.portalfiscal.inf.br/nfe"><infNFe id="NFe123" versao="4.00"> conteudo NF </NFe></infNFe>";
Estrutura += "<x:Envelope ";
Estrutura += " xmlns:x='http://schemas.xmlsoap.org/soap/envelope/'";
Estrutura += " xmlns:tem='http://tempuri.org/'> ";
Estrutura += " <x:Header/>";
Estrutura += " <x:Body> ";
Estrutura += " <tem:NotaFiscalIntegrar>";
Estrutura += " <tem:xml> ";
Estrutura += $" {NotaFiscalXML.Replace("<", "<").Replace(">", ">")} ";
Estrutura += " </tem:xml> ";
Estrutura += " </tem:NotaFiscalIntegrar> ";
Estrutura += " </x:Body> ";
Estrutura += "</x:Envelope> ";
Envelope = Regex.Unescape(Estrutura.Replace("'", "\""));
As a result I have the following envelope:
<x:Envelope xmlns:x=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:tem=\"http://tempuri.org/\">
<x:Header/>
<x:Body>
<tem:NotaFiscalIntegrar>
<tem:xml> <NFe xmlns=\"http://www.portalfiscal.inf.br/nfe\"><infNFe id=\"NFe123\" versao=\"4.00\"> conteudo NF </NFe></infNFe> </tem:xml>
</tem:NotaFiscalIntegrar>
</x:Body>
</x:Envelope>
Why are you concatenating this string to generate your xml?
– Leandro Angelo
According to Webservice support it is necessary to concatenate the XML with the envelope structure to send the request...
– Leonardo
But why don’t you import the contract and generate the objects in the proper way to take advantage of the serialization classes itself. net?
– Leandro Angelo