Return XML string in WCF

0

I need to send the result of this XML by a WCF method.

<?xml version="1.0" encoding="utf-8"?><Siape>
<matricula>8707350</matricula>
<matricula_inst />
<nome>SOLANGE ALMEIDA MORAES</nome>
<data_nascimento>06/01/1961</data_nascimento>
<cargo>035</cargo>
<tipo>Servidor</tipo>
<num_orgao>36207</num_orgao>
<nome_orgao>AGENCIA NACIONAL DE VIGILANCIA SANITARIA</nome_orgao>
<margem>0,19</margem>
<margem_cartao>454,20</margem_cartao>
<saldo_devedor>44,00</saldo_devedor>
<emprestimos>
<num_rubrica>34116</num_rubrica>
<nome_rubrica>BB</nome_rubrica>
<valor_emprestimo>0,00</valor_emprestimo>
<valor_parcela>1.112,87</valor_parcela>
<qtd_parcelas>96</qtd_parcelas>
<qtd_parcelas_aberto>80</qtd_parcelas_aberto>
<contrato>845575496</contrato>
<banco>BB</banco>
</emprestimos>
<emprestimos>
<num_rubrica>34123</num_rubrica>
<nome_rubrica>BANCO ITAU CONSIGNADO</nome_rubrica>
<valor_emprestimo>0,00</valor_emprestimo>
<valor_parcela>313,32</valor_parcela>
<qtd_parcelas>96</qtd_parcelas>
<qtd_parcelas_aberto>79</qtd_parcelas_aberto>
<contrato>542771688</contrato>
<banco>ITAU</banco>
</emprestimos>
<emprestimos>
<num_rubrica>34123</num_rubrica>
<nome_rubrica>BANCO ITAU CONSIGNADO</nome_rubrica>
<valor_emprestimo>0,00</valor_emprestimo>
<valor_parcela>300,97</valor_parcela>
<qtd_parcelas>96</qtd_parcelas>
<qtd_parcelas_aberto>79</qtd_parcelas_aberto>
<contrato>548271401</contrato>
<banco>ITAU</banco>
</emprestimos>
<emprestimos>
<num_rubrica>34123</num_rubrica>
<nome_rubrica>BANCO ITAU CONSIGNADO</nome_rubrica>
<valor_emprestimo>0,00</valor_emprestimo>
<valor_parcela>992,31</valor_parcela>
<qtd_parcelas>96</qtd_parcelas>
<qtd_parcelas_aberto>79</qtd_parcelas_aberto>
<contrato>548671154</contrato>
<banco>ITAU</banco>
</emprestimos>
</Siape>

I tried to send the XML as a string

public string ConsultaSiapeEmprestimo(string usuario, string senha, string cpf, string matricula, string tipo)

But when you send the data, WCF returns it like this:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <ConsultaSiapeEmprestimoResponse xmlns="http://tempuri.org/">
      <ConsultaSiapeEmprestimoResult>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;Siape&gt;
&lt;matricula&gt;8707350&lt;/matricula&gt;
&lt;matricula_inst /&gt;
&lt;nome&gt;SOLANGE ALMEIDA MORAES&lt;/nome&gt;
&lt;data_nascimento&gt;06/01/1961&lt;/data_nascimento&gt;
&lt;cargo&gt;035&lt;/cargo&gt;
&lt;tipo&gt;Servidor&lt;/tipo&gt;
&lt;num_orgao&gt;36207&lt;/num_orgao&gt;
&lt;nome_orgao&gt;AGENCIA NACIONAL DE VIGILANCIA SANITARIA&lt;/nome_orgao&gt;
&lt;margem&gt;0,19&lt;/margem&gt;
&lt;margem_cartao&gt;454,20&lt;/margem_cartao&gt;
&lt;saldo_devedor&gt;44,00&lt;/saldo_devedor&gt;
&lt;emprestimos&gt;
&lt;num_rubrica&gt;34116&lt;/num_rubrica&gt;
&lt;nome_rubrica&gt;BB&lt;/nome_rubrica&gt;
&lt;valor_emprestimo&gt;0,00&lt;/valor_emprestimo&gt;
&lt;valor_parcela&gt;1.112,87&lt;/valor_parcela&gt;
&lt;qtd_parcelas&gt;96&lt;/qtd_parcelas&gt;
&lt;qtd_parcelas_aberto&gt;80&lt;/qtd_parcelas_aberto&gt;
&lt;contrato&gt;845575496&lt;/contrato&gt;
&lt;banco&gt;BB&lt;/banco&gt;
&lt;/emprestimos&gt;
&lt;emprestimos&gt;
&lt;num_rubrica&gt;34123&lt;/num_rubrica&gt;
&lt;nome_rubrica&gt;BANCO ITAU CONSIGNADO&lt;/nome_rubrica&gt;
&lt;valor_emprestimo&gt;0,00&lt;/valor_emprestimo&gt;
&lt;valor_parcela&gt;313,32&lt;/valor_parcela&gt;
&lt;qtd_parcelas&gt;96&lt;/qtd_parcelas&gt;
&lt;qtd_parcelas_aberto&gt;79&lt;/qtd_parcelas_aberto&gt;
&lt;contrato&gt;542771688&lt;/contrato&gt;
&lt;banco&gt;ITAU&lt;/banco&gt;
&lt;/emprestimos&gt;
&lt;emprestimos&gt;
&lt;num_rubrica&gt;34123&lt;/num_rubrica&gt;
&lt;nome_rubrica&gt;BANCO ITAU CONSIGNADO&lt;/nome_rubrica&gt;
&lt;valor_emprestimo&gt;0,00&lt;/valor_emprestimo&gt;
&lt;valor_parcela&gt;300,97&lt;/valor_parcela&gt;
&lt;qtd_parcelas&gt;96&lt;/qtd_parcelas&gt;
&lt;qtd_parcelas_aberto&gt;79&lt;/qtd_parcelas_aberto&gt;
&lt;contrato&gt;548271401&lt;/contrato&gt;
&lt;banco&gt;ITAU&lt;/banco&gt;
&lt;/emprestimos&gt;
&lt;emprestimos&gt;
&lt;num_rubrica&gt;34123&lt;/num_rubrica&gt;
&lt;nome_rubrica&gt;BANCO ITAU CONSIGNADO&lt;/nome_rubrica&gt;
&lt;valor_emprestimo&gt;0,00&lt;/valor_emprestimo&gt;
&lt;valor_parcela&gt;992,31&lt;/valor_parcela&gt;
&lt;qtd_parcelas&gt;96&lt;/qtd_parcelas&gt;
&lt;qtd_parcelas_aberto&gt;79&lt;/qtd_parcelas_aberto&gt;
&lt;contrato&gt;548671154&lt;/contrato&gt;
&lt;banco&gt;ITAU&lt;/banco&gt;
&lt;/emprestimos&gt;
&lt;/Siape&gt;</ConsultaSiapeEmprestimoResult>
    </ConsultaSiapeEmprestimoResponse>
  </s:Body>
</s:Envelope>

How can I return correctly?

    
asked by anonymous 02.08.2016 / 05:29

2 answers

1

The best thing to do is to let WCF serialize your XML. For this you must generate a class with the structure next to the XML result that you want to return, for example:

public class Siape
{
    public int matricula { get; set; }
    public string matricula_inst { get; set; }  
    // e todas as outras propriedades  
}

And your service should return this class.

public Siape ConsultaSiapeEmprestimo(string usuario, string senha, string cpf, string matricula, string tipo)
    
11.10.2016 / 18:47
0

This is normal to happen. In order to avoid conflicts of the content to be transferred with the SOAP package that is created, the framework automatically (and very well) escapes the characters that can create conflicts.

Although the message appears like this, on the client side when you receive the information everything should appear normally.

    
02.08.2016 / 14:01