i created a small program that does
connection to db and perform a select.
that's works fine for me.

now,i want to make it a web service,
but how can i return the result of the select query from it?
please help...

this is my code...

using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Text;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace WebService3
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Service1 : System.Web.Services.WebService

        public string Main(string[] args)
            string host = "localhost";
            string database = "articles";
            string user = "root";
            string password = "08031976";
            string strSQL = "SELECT * FROM users";
            return "some string";

            string strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;
                MySqlConnection mysqlCon = new MySqlConnection(strProvider);

                if (mysqlCon.State.ToString() == "Open")
                    Console.WriteLine("Database Connection Open");

                    MySqlCommand mysqlCmd = new MySqlCommand(strSQL, mysqlCon);
                    MySqlDataReader mysqlReader = mysqlCmd.ExecuteReader();


                    while (mysqlReader.Read())
                        Console.WriteLine(mysqlReader.GetInt32(0) + "\t" + mysqlReader.GetString(1) + "\t" + mysqlReader.GetString(2));




            catch (Exception er)
                Console.WriteLine("An Error Occured" + er.Message);

7 Years
Discussion Span
Last Post by Ramesh S

Can the Console class even be used in web services?

You can return any object of array of objects (except for certain objects that implement certain interfaces, like IDictionary) from a web service.

If you're using it in a windows application then the web reference you create to connect with the service, this reference generates the objects used for input parameters and return values if they don't already exist (no need to generate a string class for example).

If you're using it for an ASP.Net service then the same thing applies, but these classes are generated in javascript, all you have to do then is have a scriptmanager that correctly references your service and you're set to go.


I am using it for an ASP.Net service.

what do u mean " a scriptmanager" ?


The ASP.Net Ajax tools have a <asp:Scriptmanager> tag.
If, however, you're not actually using this webservice for AJAX purposes but to call one website's functionality from another website then I imagine you will have to create a web reference and then probably the same thing applies as with a windows application.

Edited by ryuslash: added icode tags

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.