Wednesday, November 3, 2010

How to consume WCF Restful service in ASP.Net

Under Button Click write this code:

string baseAddress = "http://" + Environment.MachineName + ":8000/Service";

ServiceHost host = new ServiceHost(typeof(SampleImplementation), new Uri(baseAddress));

ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(ISampleInterface), new WebHttpBinding(), "");

endpoint.Behaviors.Add(new WebHttpBehavior());

host.Open();

Console.WriteLine("Host opened");



ChannelFactory factory = new ChannelFactory(new WebHttpBinding(), new EndpointAddress(baseAddress));

factory.Endpoint.Behaviors.Add(new WebHttpBehavior());

ISampleInterface proxy = factory.CreateChannel();

SampleDataContract sample = new SampleDataContract();
sample = proxy.GetSampleDataContract(TextBox1.Text);

Response.Write(sample.BranchName );


((IClientChannel)proxy).Close();

factory.Close();

host.Close();

DataBase Design Issues

DataBase Design Mistakes:
http://www.simple-talk.com/sql/database-administration/ten-common-database-design-mistakes/

For Fine Tunning the DataBase:

http://www.simple-talk.com/sql/database-administration/fine-tuning-your-database-design-in-sql-2005/

Get Nth Highest Salary in SQL Server

Using Inline View:
SELECT * FROM (
SELECT EID,ESalary,Row_number() OVER (ORDER BY ESalary) AS Row
FROM YourEmployeeTableName
) t1
WHERE Row=2

Using Dense_Rank:
SELECT * FROM
(SELECT DISTINCT Salary,
DENSE_RANK() OVER (ORDER BY Salary DESC) AS rnk
FROM YourEmployeeTableName
WHERE Salary IS NOT NULL) AS s
WHERE rnk = 3 ;

Using SubQueries :
SELECT TOP 1 salary FROM emp WHERE salary
NOT IN(SELECT TOP 3 salary FROM emp ORDER BY salary DESC) ORDER BY DESC
(Here Change Top 3 based on the Nth value)