Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning an XElement from a web service

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.

like image 295
SAL Avatar asked Mar 01 '23 03:03

SAL


1 Answers

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.

like image 58
Agies Avatar answered Mar 05 '23 16:03

Agies