How to save the return of a Webservice to disk?

1

I need to save a return of a webservice to the directory.

How do I write the value of this ret variable to a xml file.

Return: XML of type Results.xsd

I tried this way:

WSHP.XMLServer ws = new WSHP.XMLServer();
var xml = GerarXMLConsulta();
string login = "12000";
string senha = "4329";
var ret = ws.getResultado(login, senha, xml);
XmlSerializer ser = new XmlSerializer(typeof(Resultados));
FileStream arquivo = new FileStream("D:\downloads\Retorno.xml", FileMode.CreateNew);
ser.Serialize(arquivo, ret);

The Visual Studio return error:

  

Can not convert an object of type 'System.String' to type 'ModulesTags.Results'.

    
asked by anonymous 02.10.2018 / 19:58

1 answer

1

If I understood your question correctly, the return of ws.getResultado(login, senha, xml); is already an xml and you just want to save it to the directory, so there is no need for serialization / decerialization in your code.

One way to do this would be like this:

WSHP.XMLServer ws = new WSHP.XMLServer();
var xml = GerarXMLConsulta();
string login = "12000";
string senha = "4329";
var ret = ws.getResultado(login, senha, xml);

using (StreamWriter myWriter = new StreamWriter("D:\downloads\Retorno.xml"))
{
    myWriter.Write(ret);
}
    
02.10.2018 / 21:41