2010-03-09 137 views

回答

7

你不能。 XDocument不實現IXmlSerializable。 XElement實現IXmlSerializable,因此您可以通過WCF傳輸它。

您也可以傳輸字符串而不是XDocument並在本地解析它。

例:

服務器:

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

    // Do stuff 

    return myXDocument.ToString(); 
} 

客戶:

XDocument doc = XDocument.Parse(myWebService.DoSomething()); 
1

您也可以返回一個的XElement對象。

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

     // Load the XDocument. 

     return myXDocument.Root; 
    } 
+0

50%的編程是找到正確的咒語。謝謝! – 2017-08-28 19:45:11