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 4086686
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:45:33+00:00 2026-05-20T18:45:33+00:00

I set up a WCF Web Service in Visual Web Developer 2010 Express using

  • 0

I set up a WCF Web Service in Visual Web Developer 2010 Express using the 4.0 Framework and converted it to a RESTful service using this tutorial

I was able to modify it to my liking to accept url parameters like so:

namespace RestServicePublishing
{
[ServiceContract]
public interface IRestService
{
    [OperationContract(Name="GetXML")]
    [WebGet(UriTemplate = "/{param1}/{param2}")]
    XmlDocument GetXML(string param1, string param2);
}
}

The issue I am having is that I am getting a “Type ‘System.Xml.XmlDocument’ cannot be serialized” error when trying to return an XML document like this:

namespace RestServicePublishing
{
public class RestService : IRestService
    {

    public  XmlDocument GetXML(string param1, string param2)
    {

        //I am not using the parameters currently, I would just like to see if 
        //i can return XML first with this simple example:

        StringBuilder sb = new StringBuilder();
        System.Xml.XmlWriter writer = XmlWriter.Create(sb);
        writer.WriteStartDocument(); 
        writer.WriteStartElement("People");
        writer.WriteStartElement("Person"); 
        writer.WriteAttributeString("Name", "Nick"); 
        writer.WriteEndElement(); 
        writer.WriteStartElement("Person"); 
        writer.WriteStartAttribute("Name"); 
        writer.WriteValue("Nick"); 
        writer.WriteEndAttribute(); 
        writer.WriteEndElement();
        writer.WriteEndElement(); 
        writer.WriteEndDocument(); 
        writer.Flush();

        XmlDocument xmlDocument = new Xml.XmlDocument(); 
        xmlDocument.LoadXml(sb.ToString());
        return xmlDocument; 
    }

}
}

I know there has to be a better way to set up an XML document and return it.. Any help is greatly appreciated!

Thank you in advance!!

  • 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-20T18:45:33+00:00Added an answer on May 20, 2026 at 6:45 pm

    Yes – well…. the model for WCF says that you should not try to return an XmlDocument itself. Instead you return a custom type defined inside your programming environment. That type needs to be marked up to specify how it should be serialized into XML. Then when that method returns the custom type, WCF serializes it into an XML document implicitly.

    I think what you want to return is something like this:

    <People>
      <Person Name="Nick"/>
      <Person Name="Bonnie"/>
    </People>
    

    But the DataContractSerializer doesn’t like to emit attributes. So using WCF in the normal way to produce XML web services, you will instead get something like this:

    <People>
      <Person><Name>Nick</Name></Person>
      <Person><Name>Bonnie</Name></Person>
    </People>
    

    To do that, write your C# code like this:

    namespace RestServicePublishing
    {
        [ServiceContract]
        public interface IRestService
        {
            [OperationContract(Name="GetXML")]
            [WebGet(UriTemplate = "/{param1}/{param2}")]
            List<Person> GetXML(string param1, string param2);
        }
    }
    

    Then the type ought to look like this:

    [DataContract]
    public class Person
    {
        [DataMember]
        public string Name { get; set; }
    }
    
    [CollectionDataContract(Name = "People")]
    public class People : List<Person>
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asimple WCF HTTP/SOAP web service, the service implementation looks something like this:
I am writing a web service using WCF. I created data contracts. I created
I have a set of WCF web services connected to dynamically by a desktop
Will calling close on my WCF service kill all resources or set them up
I'm developing a WCF Service with a custom UserNamePasswordValidator with a basicHttpBinding. This configuration,
Trying to create an framework 4.0 WCF basicHttp service hosted by IIS (6) that
I have written a program in C# using Visual Studio 2010. At current it
I am implementing wcf service using the config-less available with WebScriptServiceHostFactory in dotNet 4.
:set ic ignores the case. How do you unset this?
I set up a website to use SqlMembershipProvider as written on this page .

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.