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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:09:06+00:00 2026-06-18T09:09:06+00:00

I have a WCF based webservice and inside the method I am executing a

  • 0

I have a WCF based webservice and inside the method I am executing a stored procedure and filling dataset then at the end returning the dataset back..like one column and multiple rows. But my requirement is different now as I am calling this webservice through some other product which expects the output based on XML like this. (its a sample XML format) but i want something in the same manner. so how do i generate the xml and return it..I would appreciate if someone can make corrections in the given code as I am not XML guy this is the first time I am going to deal with XML. I would like something

<xml>
   <Approvers>
      <Approver>
          <Approvername>John</Approvername>
      </Approver>
   </Approvers>
</xml>

Sample XML format which i want to follow.

enter image description here

public DataSet getRequisitionApprovers(string pEmail, string pLocationType)
        {
            //Read Datasource properties from Web.config file to access Oracle EBS Database 
            string SDataSource = System.Configuration.ConfigurationManager.AppSettings["SQLDataSource"].ToString();
            string SUserID = System.Configuration.ConfigurationManager.AppSettings["SQLUserID"].ToString();
            string SPassword = System.Configuration.ConfigurationManager.AppSettings["SQLPassword"].ToString();

            //Build connection string based on retrieved parameters from web.config file
            string connectionString = "Data Source=" + SDataSource + ";Persist Security Info=True;" + "User ID=" + SUserID + ";Password=" + SPassword;

            using (SqlConnection connection = new SqlConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();

                SqlCommand command = connection.CreateCommand();

                command.CommandType = System.Data.CommandType.StoredProcedure;

                // Name of procedure or function to be execu
                command.CommandText = "Get_RequisitionApprovers";

                command.Parameters.Add(new SqlParameter("theEmail", SqlDbType.VarChar)).Value = pEmail;
                command.Parameters.Add(new SqlParameter("LocationType", SqlDbType.VarChar)).Value = pLocationType;

                //Create New DataSET & DataTable
                DataSet dsApprovers = new DataSet();
                DataTable dtApprovers = new DataTable();

                //Create DataTable Columns and define the data type 
                dtApprovers.Columns.Add("Approver1", typeof(string));


                //Add DataTable to DataSource
                dsApprovers.Tables.Add(dtApprovers);

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    //Create new Data Row
                    DataRow theRow = dsApprovers.Tables[0].NewRow();

                    theRow[0] = reader[0].ToString() ;   //Add -> Approver

                    dsApprovers.Tables[0].Rows.Add(theRow);
                }

                return dsApprovers;
            }
        }
  • 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-06-18T09:09:07+00:00Added an answer on June 18, 2026 at 9:09 am

    As you can see in the video, you’re pretty close to figuring this out.

    Make sure you set the DataTable.TableName because if you don’t, it won’t serialize.

    All that remains is setting up the WCF Service and defining a WebMethod returning an XML string from your DataTable.

    After setting up your WebService, defining a WebMethod and returning the XML goes like this:

    //StringWriter requires System.IO
    using System.IO;
    
    //This are hypothetical Class and WebMethod names, of course
    public class RequisitionApprovers : System.Web.Services.WebService
    {
        [WebMethod]
        public string ReturnRequisitionApproversAsXMLString(DataSet ds)
        {
            StringWriter writer = new StringWriter();
            ds.WriteXml(writer, XmlWriteMode.IgnoreSchema);
            string xmlResult = writer.ToString();
    
            return xmlResult;
        }
    }
    

    All that’s left now is to remove the “\r\n” and the whitespaces from the xml string where needed and you end up with a clean xml string to have your WebMethod return.

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

Sidebar

Related Questions

I have a WCF based service that I use to expose AJAX functionality. Sometimes
I have a self hosted TCP based WCF service. I am now building a
Background: I have spun up a simple Proxy thing for my Wcf client based
I have a WCF client connecting to a Java based Axis2 web service (outside
I have a WCF based web service hosted in windows sever 2003 machine. The
I have a WCF web service that returns a string to a Java based
I have a WCF web service that is setup to use Message based security.
I have a webservice with a method that takes a parameter of abstract base
I have a SOAP based web service with an associated reference.cs file (not WCF).
If I have a WCF SOAP (C#) based web service running in my local

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.