How to create xml or json data and return it, as a web service, in C#?

TrillaGooN

New Member
I am creating a C# ASP.NET Web Service application. I need to access data from a SQL database and return this data as XML or JSON. When you run the HelloWorld method (see the code below), it returns the data in XML. But I need to make my own XML tags from the SQL data. How is this done?In an addition, how can I make the web service use JSON, not XML?As an example, say I'm returning a table set of 2 rows and 2 columns from SQL and I format it in XML:\[code\]<returnSet> <row1> <FirstName> David </FirstName> <LastName> Faustino </LastName> </row1> <row2> <FirstName> Henry </FirstName> <LastName> Irons </LastName> </row2></returnSet>\[/code\]Thank you very much for any assistance.\[code\]using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;namespace WebApplication2{ /// <summary> /// Summary description for WebService1 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } }}\[/code\]
 
Back
Top