Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return xdocument from wcf service

How can i return xdocument from wcf service??? what i need to do to let wxf service's method return a object of xdocument?

like image 676
Radhi Avatar asked Mar 09 '10 04:03

Radhi


2 Answers

You can't. XDocument does not implements IXmlSerializable. XElement implement IXmlSerializable so you can transfer it through WCF.

You can also transfer a string instead of the XDocument and parse it locally.

Ex :

Server :

public string DoSomething()
{
    XDocument myXDocument = new XDocument();

    // Do stuff

    return myXDocument.ToString();
}

Client :

XDocument doc = XDocument.Parse(myWebService.DoSomething());
like image 140
Alexandre Pepin Avatar answered Oct 19 '22 04:10

Alexandre Pepin


You can also return an XElement object.

    public XElement DoSomething()
    {
        XDocument myXDocument = new XDocument();

        //  Load the XDocument.

        return myXDocument.Root;
    }
like image 34
user2961748 Avatar answered Oct 19 '22 04:10

user2961748