Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 501739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:13:14+00:00 2026-05-13T06:13:14+00:00

I’m building a WCF web service which returns a composite object that looks similar

  • 0

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! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:13:14+00:00Added an answer on May 13, 2026 at 6:13 am

    I don’t know anything odd about XmlDataDocument, but you don’t necessarily need the XDocument – try:

    XmlDocument newDoc = new XmlDocument();
    newDoc.Load(new XmlNodeReader(doc.DocumentElement));
    return newDoc.DocumentElement;
    

    Still not ideal, but it looks cleaner to me…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.