Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everyone goodafternoon i am new to the .net and i got work on wcf data service i am able to create the wcf data services and getting the results and now i got problem is that i have to give authentication for wcf data service and i searched in the google and i got some example but i don't how i can integrate that to my application and i got link which is explain about the basic authentication the link is http://blogs.msdn.com/b/astoriateam/archive/2010/07/21/odata-and-authentication-part-6-custom-basic-authentication.aspx[^]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
 
namespace Wcfdataserviceconsole
{
   public class Employee
    {
        public int id { get; set; }
        public string name { get; set; }
     
       public Employee()
        {
        }
    }
        public class EmployeeDetails
        {
            public string ConnectionString = "Data Source=(local);Initial Catalog=Employee;Integrated Security=True";
            public SqlConnection Con =null;
           
            public List<Employee> Implementation()
            {
                  
                List<Employee> employee= new List<Employee>();
                Con = new SqlConnection(ConnectionString);
                Con.Open();
                string str = "select * from Employee";
                SqlCommand Cmd = new SqlCommand(str, Con);
                SqlDataReader sqlDataReader = Cmd.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    Employee emp = new Employee();
                    emp.id = sqlDataReader.GetInt32(0);
                    emp.name = sqlDataReader.GetString(1);
                    employee.Add(emp);
                }
                return employee;
            }
            public IQueryable<Employee> EmployeeContext
            {
                get
                {
                    return new EmployeeDetails().Implementation().AsQueryable();
                }
            }
        }
    }


C#
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;

namespace WcfDataService2
{
    public class OdataCustomDataService : DataService<MyCustomDataSource>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
             config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
             //config.SetServiceOperationAccessRule("GetEmployeeByName", ServiceOperationRights.All);
           // config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;        }


so can anyone tell me how to use this to my application please......

thanks in advance
Posted
Updated 21-Jun-11 23:04pm
v3
Comments
Ilya Builuk 21-Jun-11 9:34am    
I'm sorry, but I think this link contains the full information that covers your topic. You should try to understand what the authors of WCF Data services explain in the article if the basic capabilities of the technology aren't enough for you.
MURARI00 22-Jun-11 4:49am    
thanks for the response but i am new to be honest i am not understanding how i can implemnt this so asked you for help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900