Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have developed WCF service in Visual Studio 2010 and following is the code which worked perfectly.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data.OracleClient;

namespace OracleEmpService
{
    public class Service1 : IService1
    {
        public List<Employee> getEmployees()
        {
            List<Employee> employees = new List<Employee>();
            string connectionString = "Data Source=orcl;Persist Security Info=True;" +
                   "User ID=scott;Password=ABC54321;Unicode=True";
            using (OracleConnection connection = new OracleConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();
                OracleCommand command = connection.CreateCommand();
                string sql;
                sql = "SELECT * FROM Emp where rownum<=100000";
                command.CommandText = sql;
                OracleDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Employee employee = new Employee();
                    employee.Employee_ID = Convert.ToInt32(reader["EmpNo"]);
                    employee.Employee_Name = Convert.ToString(reader["Ename"]);
                    employee.Employee_Job = Convert.ToString(reader["Job"]);
                    employees.Add(employee);
                }
                return employees.ToList();
            }
        }
        public Employee getEmployeesbyID(Int32 empId)
        {
            Employee employees = new Employee();
            string connectionString = "Data Source=orcl;Persist Security Info=True;" +
                   "User ID=scott;Password=ABC54321;Unicode=True";
            using (OracleConnection connection = new OracleConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();
                OracleCommand command = connection.CreateCommand();
                string sql = "SELECT * FROM Emp where EmpNo=" + empId;
                command.CommandText = sql;
                OracleDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    employees.Employee_ID = empId;
                    employees.Employee_Name = Convert.ToString(reader["EName"]);
                    employees.Employee_Job = Convert.ToString(reader["Job"]);
                }
            }
            return employees;
        }
    }
}

But when I developed ASMX web service and used the following code it is giving error on the name of object "Employee" ..Please guide whats the proper code for this task.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services;
using Microsoft.SharePoint;
using System.Data.OracleClient;

namespace WebServiceDemo
{
    public class MyCustomWebService : WebService
    {
        [WebMethod]
        public string getEmployees()
        {
            List<Employee> employees = new List<Employee>();

            string connectionString = "Data Source=orcl;Persist Security Info=True;" + "User ID=scott;Password=ABC54321;Unicode=True";
            using (OracleConnection connection = new OracleConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();
                OracleCommand command = connection.CreateCommand();
                string sql;
                sql = "SELECT * FROM Emp where rownum<=100000";
                command.CommandText = sql;
                OracleDataReader reader = command.ExecuteReader();

                if (reader.Read())
                {
                    Employee employee = new Employee();
                    employee.Employee_ID = Convert.ToInt32(reader["EmpNo"]);
                    employee.Employee_Name = Convert.ToString(reader["Ename"]);
                    employee.Employee_Job = Convert.ToString(reader["Job"]);
                    employees.Add(employee);

                    return (reader[0].ToString());
                }
            }
        }
    }
}
share|improve this question

1 Answer 1

Your Employee class does not exist in the WebServiceDemo namespace. You'll need to add a reference or an include directive.

share|improve this answer
    
How to add employee class in namespace? But as far as i remember i never included employee class in my WCF service also. –  user342944 Oct 9 '12 at 3:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.