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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:48:40+00:00 2026-06-10T17:48:40+00:00

I have a problem i am struggling to create a WCF Service Application form

  • 0

I have a problem i am struggling to create a WCF Service Application form this Data Access Layer :

public class DataAccess
{
    private SqlConnection connection = new SqlConnection("Data Source=LAPI;Initial Catalog=PrimierData;Integrated Security=True");
    private SqlDataReader dataReader;
    private SqlCommand command;
    private SqlTransaction transaction = null;
    private SqlParameter[] parameters = null;


    #region Conenction
    public void Open()
    {
        if (connection.State != ConnectionState.Open)
            connection.Open();
    }

    public void Close()
    {
        if (connection.State != ConnectionState.Closed)
            connection.Close();
    }

    #endregion




    #region Reader
    /// <summary>
    /// Executes the reader. For MultiRow Search
    /// </summary>
    /// <param name="commandType">Type of the command.</param>
    /// <param name="commandText">The command text.</param>
    /// <returns></returns>
    public SqlDataReader ExecuteReader(CommandType commandType, string commandText,SqlParameter[] readerparams)
    {
        Open();
        command = new SqlCommand(commandText, connection);
        command.CommandType = commandType;
        if (readerparams != null)
        {
            command.Parameters.AddRange(readerparams); 
        }
       this.dataReader = command.ExecuteReader();
        command.Parameters.Clear();
       // Close();
        return this.dataReader;
    }

   #endregion

    #region Execute
    /// <summary>
    /// Executes the non query. For Insert, Update and Delete
    /// </summary>
    /// <param name="commandType">Type of the command.</param>
    /// <param name="commandText">The command text.</param>
    /// <param name="parameters">The parameters.</param>
    /// <returns></returns>
    public int ExecuteNonQuery(CommandType commandType, string commandText,SqlParameter[] nonparams)
    {
        Open();
        command = new SqlCommand(commandText, connection);
        command.CommandType = commandType;
        command.Parameters.AddRange(nonparams);
        int returnValue = command.ExecuteNonQuery();
        command.Parameters.Clear();
        Close();
        return returnValue;
    }

  #endregion

}

I would like to use WCF but i get a Error

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.

And i tried to code it I am failing hard. The code works that i am using but when creating the WCF i am a complte noob.

[ServiceContract]
public interface IService1
{


   // TODO: Add your service operations here
    [OperationContract]
    void Open();

    [OperationContract]
    void Close();


    [OperationContract]
    SqlDataReader ExecuteReader(CommandType commandType, string commandText, SqlParameter[] readerparams);

    [OperationContract]
    int ExecuteNonQuery(CommandType commandType, string commandText, SqlParameter[] nonparams);
}

and my Service.svc

public class Service1 : IService1
{
    private SqlConnection connection = new SqlConnection("Data Source=LAPI;Initial Catalog=PrimierData;Integrated Security=True");
    private SqlDataReader dataReader;
    private SqlCommand command;
    private SqlTransaction transaction = null;
    private SqlParameter[] parameters = null;


    [OperationContract]
    public void Open()
    {
        if (connection.State != ConnectionState.Open)
            connection.Open();
    }

    [OperationContract]
    public void Close()
    {
        if (connection.State != ConnectionState.Closed)
            connection.Close();
    }

    [OperationContract]
    public int ExecuteNonQuery(CommandType commandType, string commandText, SqlParameter[] nonparams)
    {
        Open();
        command = new SqlCommand(commandText, connection);
        command.CommandType = commandType;
        command.Parameters.AddRange(nonparams);
        int returnValue = command.ExecuteNonQuery();
        command.Parameters.Clear();
        Close();
        return returnValue;
    }
    [OperationContract]
    public SqlDataReader ExecuteReader(CommandType commandType, string commandText, SqlParameter[] readerparams)
    {
        Open();
        command = new SqlCommand(commandText, connection);
        command.CommandType = commandType;
        if (readerparams != null)
        {
            command.Parameters.AddRange(readerparams);
        }
        this.dataReader = command.ExecuteReader();
        command.Parameters.Clear();
        // Close();
        return this.dataReader;
    }
  • 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-10T17:48:41+00:00Added an answer on June 10, 2026 at 5:48 pm

    Ok so did this myself oand it worked for me.
    On the Client Side DAL

    public SQLArray[] SQLtoArray(SqlParameter[] parama)
        {
            if (parama != null)
            {
                SqlParameter[] param = parama;
                int lenght = param.Count();
                SQLArray[] unner = new SQLArray[lenght];
    
                for (int i = 0; i < lenght; i++)
                {
                    unner[i] = new SQLArray();
                    unner[i].ParamaterName = param[i].ParameterName;
                    unner[i].Paramatertype = param[i].SqlDbType;
                    unner[i].ParamaterDirection = param[i].Direction;
                    unner[i].ParamaterValue = param[i].Value.ToString();
                }
                return unner;
            }
            return null;
        }
    

    And on the Server Side

    Interface

    [ServiceContract]
    [ServiceKnownType(typeof(SqlParameter[]))]
    [ServiceKnownType(typeof(object))]
    [ServiceKnownType(typeof(SqlDbType))]
    [ServiceKnownType(typeof(ParameterDirection))]
    [ServiceKnownType(typeof(SqlDateTime))]
    public interface IServerService
    {
        [OperationContract]
        DataSet ExecuteDataSet(CommandType commandType, string commandText, SQLArray[] dsparams);
    
        [OperationContract]
        int ExecuteNonQuery(CommandType commandType, string commandText, SQLArray[] nonparams);
    
    
    }
    [DataContract]
    [KnownType(typeof(SqlParameter[]))] 
    [KnownType(typeof(object))]
    [KnownType(typeof(SqlDbType))]
    [KnownType(typeof(ParameterDirection))]
    [KnownType(typeof(SqlDateTime))]
    public class SQLArray
    {
      //  private SqlParameter[] array;
        private string paramaterName;
        private string paramaterValue;
        private ParameterDirection paramaterDirection;
        private SqlDbType paramatertype;
    
    
       [DataMember]
    
        public string ParamaterName
        {
            get { return paramaterName; }
            set { paramaterName = value; }
        }
        [DataMember]
        public string ParamaterValue
        {
            get { return paramaterValue; }
            set { paramaterValue = value; }
        }
        [DataMember]
        public ParameterDirection ParamaterDirection
        {
            get { return paramaterDirection; }
            set { paramaterDirection = value; }
        }
        [DataMember]
        public SqlDbType Paramatertype
        {
            get { return paramatertype; }
            set { paramatertype = value; }
        }
    }
    

    CSV

    [Serializable]
    public class ServerService : IServerService
    {
        #region Class Members
    
      // private ServerDataAccess dataAccess;
        SqlConnection connection = new SqlConnection("Data Source=LAPI;Initial Catalog=PrimierData;Integrated Security=True");
       // SqlDataReader dataReader;
        SqlCommand command;
       // SqlTransaction transaction = null;
       // SqlParameter[] parameters = null;
    
        #endregion
    
        #region Constructor
    
       public ServerService()
        {
    
    
        }
        public SqlParameter[] ArrayToSQL(SQLArray[] parama)
        {
           // bool outahere = false;
            int count = 0;
            foreach (SQLArray array in parama)
                count++;
            SqlParameter[] unner = new SqlParameter[count];
            for (int i = 0; i < count; i++)
            {
                unner[i] = new SqlParameter();
                unner[i].ParameterName = parama[i].ParamaterName;
                unner[i].SqlDbType = parama[i].Paramatertype;
                unner[i].Direction = parama[i].ParamaterDirection;
                unner[i].Value = parama[i].ParamaterValue;
            }
            return unner;
        }
        public SQLArray[] SQLtoArray(SqlParameter[] parama)
        {
            int count = 0;
            foreach (SqlParameter parameter in parama)
                count++;
            SQLArray[] unner = new SQLArray[count];
    
            for (int i = 0; i < parama.Count(); i++)
            {
                unner[i] = new SQLArray();
                unner[i].ParamaterName = parama[i].ParameterName;
                unner[i].Paramatertype = parama[i].SqlDbType;
                unner[i].ParamaterDirection = parama[i].Direction;
                unner[i].ParamaterValue = parama[i].Value.ToString();
            }
            return unner;
        }
        #endregion
    
        public void Open()
        {
            if (connection.State != ConnectionState.Open)
                connection.Open();
        }
    
        public void Close()
        {
            if (connection.State != ConnectionState.Closed)
                connection.Close();
        }
    
        #region Methods
        /// <summary>
        /// Executes the non query. For Insert, Update and Delete
        /// </summary>
        /// <param name="commandType">Type of the command.</param>
        /// <param name="commandText">The command text.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public int ExecuteNonQuery(CommandType commandType, string commandText, SQLArray[] nonparams)
        {
           Open();
            command = new SqlCommand(commandText, connection);
            command.CommandType = commandType;
            command.Parameters.AddRange(ArrayToSQL(nonparams));
            int returnValue = command.ExecuteNonQuery();
            command.Parameters.Clear();
            Close();
            return returnValue;
        }
        public DataSet ExecuteDataSet(CommandType commandType, string commandText, SQLArray[] dsparams)
        {
    
                Open();
                command = new SqlCommand(commandText, connection);
                command.CommandType = commandType;
                if (dsparams != null)
                {
                    command.Parameters.AddRange(ArrayToSQL(dsparams));
                }
                SqlDataAdapter dataAdapter = new SqlDataAdapter();
                dataAdapter.SelectCommand = command;
                DataSet dataSet = new DataSet();
                dataAdapter.Fill(dataSet);
                command.Parameters.Clear();
                Close();
    
                return dataSet;
    
    
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling to solve this problem in R. I have data like this: item
I have been struggling to find a solution to this problem. In my code,
Struggling with this one. I have set up a basic email/enquiry form for a
My essential problem is that I have read only access to a large data
I have been struggling with this problem for the last few hours, and it
I'm currently struggling with this problem. The situation is that I have a user
I've been struggling with this annoying problem. I have a Model, Editor and controller:
I'm new to Hibernate and I'm struggling with problem: I have 3 tables and
I've been struggling with Zend_Navigation all weekend, and now I have another problem, which
I have a question about a problem I'm struggling with. Hope you can bear

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.