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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:43:25+00:00 2026-06-12T00:43:25+00:00

I am a noob to ASP.NET/C#. I am trying to use a web service

  • 0

I am a noob to ASP.NET/C#. I am trying to use a web service to return a JSON object from the database. I am getting an error in Firebug that I am creating a circular reference. The stack trace is in JSON format. When I view the web service directly in the browser, it is returning valid XML for some strange reason. Here is my web service.

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public DataSet Posts() {
    string connString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["XXX"].ConnectionString;
    SqlConnection conn = new SqlConnection(connString);
    string sql = "SELECT * FROM Posts";
    SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
    DataSet ds = new DataSet();
    sda.Fill(ds);
    return ds;
}

I’m new to C# so I don’t know if this is written correctly. What I want is a DataSet in JSON format. Am I doing this correctly? Here is the jQuery that is calling the web service.

<script>
    $(function () {
         $.ajax({
            type: "POST",
            url: "WebServices/MessageBoard.asmx/Posts",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(data) { console.log(data) },
            failure: function (msg) {
                //alert(msg);
            }
        });

    });
</script>
  • 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-12T00:43:26+00:00Added an answer on June 12, 2026 at 12:43 am

    The reason you’re getting XML is because the the DataSet serializes to XML. However, you can use JSON.NET to turn the XML into JSON. Here is an example:

    using System;
    using System.Collections.Generic;
    using System.Data;
    
    using Newtonsoft.Json;
    
    class Program
    {
        static void Main(string[] args)
        {
            var dataSet = new DataSet();
            var dataTable = new DataTable();
            for (int i = 0; i < 5; i++) { dataTable.Columns.Add(string.Format("Column{0}", i), typeof(string)); }
            for (int i = 0; i < 5; i++)
            {
                var vals = new List<object>();
                for (int j = 0; j < 5; j++) { vals.Add(string.Format("Value {0}", j)); }
                dataTable.LoadDataRow(vals.ToArray(), true);
            }
    
            dataSet.Tables.Add(dataTable);
            dataSet.AcceptChanges();
    
            Console.WriteLine(JsonConvert.SerializeObject(dataSet));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm totally noob to asp.net mvc and currently i'm writing an web app which
I confess I am a noob to asp.net and web forms. I'm having an
What I am trying to do using asp.net MVC3: -User selects a Category from
Sorry if this sounds like a noob question. I downloaded this asp.net project from
I'm just getting started with ASP.NET/MVC3, jquery, c#, you name it. I'm trying to
I am a noob in ASP.NET and building a website currently... I want the
I am an ASP.Net MVC noob. I cannot get checkboxes to render correctly i.e.
I'm very noob when it comes to ASP.NET MVC. I'm looking at the starter
Excuse the 'noob' question, but can someone please explain the way ASP.NET's buttons work.
Very noob question, In asp.net can you explain in the simplest possible way what

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.