How to save Return from a Webservice to disk?

Asked

Viewed 81 times

1

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

How do I save the value of this variable ret in an archive xml.

Return: XML of type Results.xsd

I tried so:

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 error return:

Cannot convert an object of type 'System.String' in type 'Modulolabels.Results'.

  • var ret = ws.getResultado(login, senha, xml); returns an object or an xml?

  • Returns an XML.

  • And you want to put the xml in a file?

  • string return = Ws.getResult(login, password, xml); precise saves the return variable in an xml.xml for another system to load that file.

1 answer

1


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

One way to do it 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);
}
  • 1

    Wonderful, that’s what was missing. Thank you for your attention.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.