Is it possible to return an XElement from a webservice (in C#/asp.net)?
Try a simple web service that returns an XElement:
[WebMethod]
public XElement DoItXElement()
{
XElement xe = new XElement("hello",
new XElement("message", "Hello World")
);
return xe;
}
This compiles fine but if you try and run it you get
Cannot use wildcards at the top level of a schema.
I found this post implying that this is a bug in .net.
So... Can I return an XElement from a web service? If so, how?
Thanks.
There appears to be an issue with how an XElement is serialized, check here...
You can try outing the XElement as a string or as the article suggests you could just use a class wrapper and place your XElement inside. If the point is to output the data in a universal format you'll be stuck with returning a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With