Search code examples
c#.netasmx

How to consume a method of web service (asmx) that receives and returns xml


I have a web service asmx that has various methods receiving and returning xml.

From visual basic I use them this way and I work great:

Dim WEBS As New WebServiceH.HUMANOWSSoapClient

xml_result.LoadXml(WEBS.Cars(xml_send.DocumentElement).OuterXml)

I'm trying to do this in c # and I could not make it work properly, here an example of what I do.

WebServiceH.HUMANOWSSoapClient WEBS = new WebServiceH.HUMANOWSSoapClient();

xml_result.LoadXml(WEBS.Cars(xml_send.DocumentElement).OuterXml);

The method of the Web service receives an XML document but in visual studio tells me that the method receives an Xelement, try to convert the document to xml Xelement this way but does not work:

XElement xml_convert = XElement.Parse(xml_entrada.ToString());
xml_result.LoadXml(WEBS.Cars(xml_convert).OuterXml);

Anyone know how I can consume this method correctly passing a xml as parameter in c #


Solution

  • The quickest solution I found was to convert the xml that is sent in Xelement, then as the method returns a Xelement I convert it to string and load it as xml, if not the best solution here is.

    xml_result.LoadXml((WEBS.Cars(XElement.Parse(xml_send.OuterXml))).ToString());