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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:14:41+00:00 2026-05-26T09:14:41+00:00

I build a WCF Rest service to provide data for another process. suppose that

  • 0

I build a WCF Rest service to provide data for another process. suppose that his name is GetData.
This one provide a xml response having this structure :

<?xml version="1.0" encoding="utf-8"?>
<GetDataResponse xmlns="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <GetDataResult>
    <DataMessage>   
      <a></a>
      <b></b>
      <c></c>
    </DataMessage>
  </GetDataResult>
</GetDataResponse>

the service interface :

    [XmlSerializerFormat]
    [OperationContract(Name = "GetData")]
    [WebInvoke(Method = "GET",
               ResponseFormat = WebMessageFormat.Xml,
               BodyStyle = WebMessageBodyStyle.Wrapped,
               UriTemplate = "Data/{Param}")]
    List<DataMessage> GetData(string Params);

I would like to deserialize the xml after saving it, following the DataMessage class. So, I would like to have this schema :

<?xml version="1.0" encoding="utf-8"?>
<DataMessages xmlns="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <DataMessage>
      <a></a>
      <b></b>
      <c></c>
    </DataMessage>
</DataMessages>

What should I do to define the service response schema to have it like this?

Thank you.

  • 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-26T09:14:42+00:00Added an answer on May 26, 2026 at 9:14 am

    You can use some attributes in the System.Xml.Serialization namespace to define an object graph which maps to the schema you have. The code below does that.

    public class StackOverflow_7905186
    {
        [XmlType(TypeName = "DataMessage", Namespace = "http://tempuri.org/")]
        public class DataMessage
        {
            public string a;
            public string b;
            public string c;
        }
        [XmlRoot(ElementName = "DataMessages", Namespace = "http://tempuri.org/")]
        public class DataMessages
        {
            [XmlElement(ElementName = "DataMessage")]
            public List<DataMessage> Messages;
        }
        [ServiceContract]
        public class Service
        {
            [XmlSerializerFormat]
            [OperationContract(Name = "GetData")]
            [WebGet(ResponseFormat = WebMessageFormat.Xml,
                    BodyStyle = WebMessageBodyStyle.Bare,
                    UriTemplate = "Data/{Param}")]
            [return: MessageParameter(Name = "DataMessages")]
            public DataMessages GetData(string Param)
            {
                return new DataMessages
                {
                    Messages = new List<DataMessage>
                    {
                        new DataMessage
                        {
                            a = "1",
                            b = "2",
                            c = "3",
                        }
                    }
                };
            }
        }
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            WebServiceHost host = new WebServiceHost(typeof(Service), new Uri(baseAddress));
            host.Open();
            Console.WriteLine("Host opened");
    
            WebClient c = new WebClient();
            Console.WriteLine(c.DownloadString(baseAddress + "/Data/foo"));
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a REST & json based WCF service that takes
I have a WCF-REST service with one method which returns a string: [ServiceContract] public
I am using WCF REST Start kit to build a RESTFul service. I defined
WCF REST service works great in a way that it will reply/accept JSON or
I want to build a WCF REST service, consumed by a Silverlight app, and
I have written a WCF service with the REST template that has the defaultOutgoingResponseFormat
What is the best API to build a rest service: WCF and ASP MVC.
I'm trying to manually build a WCF Data Service using a POCO data model
I would like to start using the WCF Rest Starter Kit's HttpClient to build
I've build a WCF Service to accept a file and write it to disk.

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.