.net webservice with XElement return type
There is a way to make a webservice that returns a parameter of the type XElement? Now I'm working with XmlNode 开发者_JAVA百科return type, but I want to get rid of using this old xml library.
I'm using this:
XDocument doc = new XDocument();
XElement xml = new XElement("produtos");
doc.Add(xml);
//...
var xmlDoc = new XmlDocument();
using (var xmlReader = doc.CreateReader())
{
xmlDoc.Load(xmlReader);
}
return xmlDoc;
I can't figure out why the webservice dont work with the XmlLinq lib
You should be able to do this:
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XElement GetSomething()
{
return new XElement("Something");
}
I used an extension method to convert the XElement to an XmlElement (per suggestion of @Ocelot20):
<System.Runtime.CompilerServices.Extension()> _
Public Function ToXmlElement(value As XElement) As XmlElement
Dim xmlDoc = New XmlDocument()
xmlDoc.LoadXml(value.ToString())
Return xmlDoc.DocumentElement
End Function
Seems to work fine!
精彩评论