Hi guys, I'm building a WCF web service which returns a composite object that looks similar to the following:
[DataContract]
public class WebServiceReturn
{
...
[DataMember]
public XmlElement Results { get; set; }
...
}
When I return a WebServiceReturn object with the following code, everything is fine:
XElement cities = new XElement("Cities",
from r in results
select new XElement("City", r));
using (XmlReader xmlReader = cities.CreateReader())
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlReader);
WebServiceReturn response = new WebServiceReturn();
response.Results = xmlDoc.DocumentElement;
}
However, when I use the code below, which takes an XmlElement from the results of a stored procedure call that returns an XmlDataDocument, a CommunicationException is thrown (which has no inner exceptions).
XmlDataDocument xdd = DataAccess.ExecuteXML("MyStoredProc", parameter);
response.Results = xdd.DocumentElement;
The confusing part is if I convert the XmlDataDocument.DocumentElement (which is an XmlElement) into an XElement and then back into an XmlElement, there are no problems (wow that was a mouthful) - so the following code returns with no problem.
XmlElement xe = DataAccess.ExecuteXML("MyStoredProc", parameter).DocumentElement;
XDocument xDoc = new XDocument();
using (XmlWriter xmlWriter = xDoc.CreateWriter()){
xe.WriteTo(xmlWriter);
}
using (XmlReader xmlReader = xDoc.Root.CreateReader())
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlReader);
response.Results = xmlDoc.DocumentElement;
}
The communicationexception details are:
[CommunicationException: The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.]
I have also updated the service reference in my test application multiple times which has had no effect.
Is the problem with my test code that is calling the web service? Why would converting an XmlElement into an XElement and then back into an XmlElement fix the issue? Any information at all would be much appreciated! :)