开发者

return xdocument from wcf service

开发者 https://www.devze.com 2022-12-22 03:14 出处:网络
How can i return xdocument from wcf service??? what i need 开发者_Go百科to do to let wxf service\'s method return a object of xdocument?You can\'t.XDocument does not implements IXmlSerializable.XEleme

How can i return xdocument from wcf service??? what i need 开发者_Go百科to do to let wxf service's method return a object of xdocument?


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());


You can also return an XElement object.

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

        //  Load the XDocument.

        return myXDocument.Root;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消