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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:13:35+00:00 2026-06-18T07:13:35+00:00

i have a data access class which uses certain stored procedures to select/insert/update data

  • 0

i have a data access class which uses certain stored procedures to select/insert/update data in the database. How can I convert this class into web service and all methods as web methods? I’m using vs 2012 and c#. An example of the section of this datacess class is

namespace HPS.Thesaurus.Data
{
public class TermDB : DbObjectStatic
{
    #region Public Methods

    #region CRUD Methods                

    public static int Add(Term term, string useString, string useForString, string broaderTermString, string narrowerTermString, string relatedTermString, string userName, ref int historyTermId)
    {
        int rowsAffected = 0;
        SqlParameter[] parameter = 
        { 
            new SqlParameter("@name", SqlDbType.VarChar, 200),
            new SqlParameter("@type", SqlDbType.Int),
            new SqlParameter("@scope", SqlDbType.VarChar, 2000),
            new SqlParameter("@hpspublic", SqlDbType.Bit),
            new SqlParameter("@additionalnotes",SqlDbType.VarChar,2000),
            new SqlParameter("@usestring", SqlDbType.VarChar, 2000),
            new SqlParameter("@useforstring", SqlDbType.VarChar, 2000),
            new SqlParameter("@broaderstring", SqlDbType.VarChar, 2000),
            new SqlParameter("@narrowerstring", SqlDbType.VarChar, 2000),
            new SqlParameter("@relatedstring", SqlDbType.VarChar, 2000),
            new SqlParameter("@changedby", SqlDbType.VarChar, 15),
            new SqlParameter("@id", SqlDbType.Int),
            new SqlParameter("@historytermid", SqlDbType.Int)
        };

        parameter[0].Value = term.Name;
        parameter[1].Value = term.Type;
        parameter[2].Value = term.Scope;
        parameter[3].Value = term.HPSPublic;
        parameter[4].Value = term.AdditionalNotes;

        if (useString.Trim().Length > 0)
        {
            parameter[5].Value = useString;
        }

        if (useForString.Trim().Length > 0)
        {
            parameter[6].Value = useForString;
        }

        if (broaderTermString.Trim().Length > 0)
        {
            parameter[7].Value = broaderTermString;
        }

        if (narrowerTermString.Trim().Length > 0)
        {
            parameter[8].Value = narrowerTermString;
        }

        if (relatedTermString.Trim().Length > 0)
        {
            parameter[9].Value = relatedTermString;
        }

        if (userName.Trim().Length > 0)
        {
            parameter[10].Value = userName;
        }

        parameter[11].Direction = ParameterDirection.Output;
        parameter[12].Direction = ParameterDirection.Output;

        try
        {
            RunProcedure("Term_Add", parameter, out rowsAffected, AppConfiguration.ConnectionString());
        }
        catch
        {
            return -1;
        }

        historyTermId = (int)parameter[12].Value;
        return (int)parameter[11].Value;
    }

    public static bool Delete(Term term)
    {
        int rowsAffected = 0;

        SqlParameter[] parameter = 
        { 
            new SqlParameter("@id", SqlDbType.Int) 
        };

        parameter[0].Value = term.Id;

        try
        {
            RunProcedure("Term_Delete", parameter, out rowsAffected, AppConfiguration.ConnectionString());
        }
        catch
        {
            return false;
        }

        return rowsAffected > 0;
    }

    public static Term GetTerm(int termId)
    {
        SqlParameter[] parameters = 
        { 
            new SqlParameter("@id", SqlDbType.Int)
        };

        parameters[0].Value = termId;

        using (DataTable dt = RunProcedure("Term_Get", parameters, "terms", AppConfiguration.ConnectionString()))
        {
            if (dt.Rows.Count > 0)
            {
                return FillData(dt.Rows[0]);
            }
            else
            {
                return null;
            }
        }
    }

    public static Term GetTerm(string termName)
    {
        SqlParameter[] parameters = 
        { 
            new SqlParameter("@name", SqlDbType.VarChar, 1000)
        };

        parameters[0].Value = termName;

        using (DataTable dt = RunProcedure("Term_GetByName", parameters, "terms", AppConfiguration.ConnectionString()))
        {
            if (dt.Rows.Count > 0)
            {
                return FillData(dt.Rows[0]);
            }
            else
            {
                return null;
            }
        }
    }

    public static bool Update(Term term, string useString, string useForString, string broaderTermString, string narrowerTermString, string relatedTermString, string changedBy, ref int historyTermId)
    {
        int rowsAffected = 0;
        SqlParameter[] parameter = 
        {   
            new SqlParameter("@id", SqlDbType.Int),
            new SqlParameter("@name", SqlDbType.VarChar, 200),
            new SqlParameter("@type", SqlDbType.Int),
            new SqlParameter("@scope", SqlDbType.VarChar, 2000),
            new SqlParameter("@hpspublic", SqlDbType.Bit),
            new SqlParameter("@additionalnotes",SqlDbType.VarChar,2000),
            new SqlParameter("@usestring", SqlDbType.VarChar, 2000),
            new SqlParameter("@useforstring", SqlDbType.VarChar, 2000),
            new SqlParameter("@broaderstring", SqlDbType.VarChar, 2000),
            new SqlParameter("@narrowerstring", SqlDbType.VarChar, 2000),
            new SqlParameter("@relatedstring", SqlDbType.VarChar, 2000),
            new SqlParameter("@changedBy", SqlDbType.VarChar, 15),
            new SqlParameter("@historyTermId", SqlDbType.Int),      
        };

        parameter[0].Value = term.Id;
        parameter[1].Value = term.Name;
        parameter[2].Value = term.Type;
        parameter[3].Value = term.Scope;
        parameter[4].Value = term.HPSPublic;
        parameter[5].Value = term.AdditionalNotes;
        if (useString.Trim().Length > 0)
        {
            parameter[6].Value = useString;
        }

        if (useForString.Trim().Length > 0)
        {
            parameter[7].Value = useForString;
        }

        if (broaderTermString.Trim().Length > 0)
        {
            parameter[8].Value = broaderTermString;
        }

        if (narrowerTermString.Trim().Length > 0)
        {
            parameter[9].Value = narrowerTermString;
        }

        if (relatedTermString.Trim().Length > 0)
        {
            parameter[10].Value = relatedTermString;
        }

        if (changedBy.Trim().Length > 0)
        {
            parameter[11].Value = changedBy;
        }

        parameter[12].Direction = ParameterDirection.Output;

        try
        {
            RunProcedure("Term_Update", parameter, out rowsAffected, AppConfiguration.ConnectionString());
        }
        catch
        {
            return false;
        }

        historyTermId = (int)parameter[12].Value;
        return rowsAffected > 0;
    }

    #endregion

    public static TermList GetAll()
    {
        TermList tl = null;

        using (DataTable dt = RunProcedure("Term_GetAll", new IDataParameter[] { }, "terms", AppConfiguration.ConnectionString()))
        {
            tl = new TermList();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    tl.Add(FillData(dr));
                }
            }
        }

        return tl;
    }
  • 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-18T07:13:37+00:00Added an answer on June 18, 2026 at 7:13 am

    To convert the methods to Webservice You need to Declare all the methods as [Operation Contract] and all the Custom Classes as [Data Contract] Attribute. Very simple answer for your example would be

    [Operation Contract]
    public static int Add(Term term, string useString, string useForString, string broaderTermString, string narrowerTermString, string relatedTermString, string userName, ref int historyTermId);
    

    Also to approach this try to create a separate Webservice Project in WCF so you get all default configuration then manually add the methods with appropriate contracts and operations should work.

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

Sidebar

Related Questions

I have data stored as below in an MS Access database: Date User 20090101
I'm creating an app which uses a Data Access Object class to load values
I have created a data access layer in my web app which uses ObjectDataSource
I have three classes: A data holder class CDataHolder, which uses a Pimpl pattern
I have a data access class that took me a while to get working.
I have created a Data Access Layer using .NET. Everywhere that I update a
I have an application which uses a SQL database. This is encapsulated by a
I'm developing for a legacy C++ application which uses ODBC for it's data access.
I have created a library which can download JSON data which is then placed
Our legacy web application heavily uses stored procedures. We have a central interface through

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.