using System.Data;
using System.Data.SqlClient;
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Text;
namespace VotingPanel.Web
{
[ServiceContract]
public interface Iservice1
{
[OperationContract]
List<Vote> GetChartData();
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
// [ServiceContract]
public class Service1 : Iservice1
{
SqlConnection Conn;
SqlCommand Cmd;
# region Iservice1 members
[OperationContract]
public List <Vote> GetChartData()
{
DataClasses1DataContext db = new DataClasses1DataContext();
var query = from c in db.Votes select c;
return query.Take(10).ToList();
}
# endregion
[OperationContract]
public void Insertdata(String vote, DateTime dt)
{
Conn = new SqlConnection("Data Source=IRAM-PC;Initial Catalog=Voting;User Id=sa;Password=sa;Integrated Security=SSPI");
Cmd = new SqlCommand();
Conn.Open();
Cmd.Connection = Conn;
Cmd.CommandText = "insert into votes values ('" + vote + "', '"+dt+"' )";
int ins = Cmd.ExecuteNonQuery();
//if (ins > 0)
//{
// Inserted = true;
//}
Conn.Close();
}
public void GetData()
{
bool Inserted = false;
Conn = new SqlConnection("Data Source=IRAM-PC;Initial Catalog=Voting;User Id=sa;Password=sa;Integrated Security=SSPI");
Cmd = new SqlCommand();
Conn.Open();
Cmd.Connection = Conn;
Cmd.CommandText = "SELECT votingtext, COUNT(Votingtext) AS count FROM votes group by Votingtext";
int ins = Cmd.ExecuteNonQuery();
if (ins > 0)
{
Inserted = true;
}
Conn.Close();
//return Inserted;
}
// Add more operations here and mark them with [OperationContract]
}
}
i was getting an error while adding service reference
There was an error downloading 'http://localhost:1289/Service1.svc'.
The request failed with the error message:
--
<html>
<head>
<title>The contract name 'VotingPanel2.Web.Service1' could not be found in the list of contracts implemented by the service 'Service1'.</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>The contract name 'VotingPanel2.Web.Service1' could not be found in the list of contracts implemented by the service 'Service1'.</i> </h2></span>
<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
<br><br>
<b> Exception Details: </b>System.InvalidOperationException: The contract name 'VotingPanel2.Web.Service1' could not be found in the list of contracts implemented by the service 'Service1'.<br><br>
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>
[InvalidOperationException: The contract name 'VotingPanel2.Web.Service1' could not be found in the list of contracts implemented by the service 'Service1'.]
System.ServiceModel.Description.ConfigLoader.LookupContract(String contractName, String serviceName) +11726487
System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress) +11725539
System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection) +55
System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, String configurationName) +35
System.ServiceModel.ServiceHostBase.ApplyConfiguration() +69
System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +190
System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses) +32
System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +139