Hi
how are you.
I am facing a problem in post method. i am trying to update in server but service saying end point not found.
The thing is that web get method is working but post method is not working here is code :
namespace Healthcare
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "EmpRecord"
)]
List<EmpRecord> GetEmployeeLIst();
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "EmpRecord/{id}")]
EmpRecord GetemById(string id);
[OperationContract(Name = "PostSampleMethod")]
[WebInvoke(Method = "POST",
UriTemplate = "PostSampleMethod")]
string PostSampleMethod(string city);
}
i am successfully calling service with get mehtod with this url : http://localhost:57325/Service1.svc/emprecord
but when calling PostSampleMethod it saying method not found with url :
http://localhost:57325/Service1.svc/PostSampleMethodPostSampleMethod
if i put parameter
http://localhost:57325/Service1.svc/PostSampleMethod/usa
then it say end point not found
the service code
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.Configuration;
using System.Data.SqlClient;
using System.Data;
using Emp.Interface;
namespace Healthcare
{
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public List<EmpRecord> GetEmployeeLIst()
{
string connStr = ConfigurationManager.ConnectionStrings["constr"].ToString();
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand();
comm.CommandText = "select city,address from tblemployee";
comm.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds, "StudentRecord");
conn.Close();
List<EmpRecord> stuList = new List<EmpRecord>();
if (ds.Tables != null)
{
int recordCount = ds.Tables["StudentRecord"].Rows.Count;
if (recordCount > 0)
{
DataTable dtab = ds.Tables["StudentRecord"];
for (int i = 0; i < recordCount; i++)
{
EmpRecord objemp = new EmpRecord();
objemp.city = dtab.Rows[i]["city"].ToString();
objemp.address = dtab.Rows[i]["address"].ToString();
stuList.Add(objemp);
}
}
}
comm.Dispose();
return stuList;
}
public EmpRecord GetemById(string id)
{
try
{
int bookId = Convert.ToInt32(id);
string connStr = ConfigurationManager.ConnectionStrings["constr"].ToString();
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand();
comm.CommandText = "select Empkey,city,[Address] from tblemployee where Empkey="+bookId;
comm.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds, "StudentRecord");
conn.Close();
EmpRecord objemp = new EmpRecord();
if (ds.Tables != null)
{
int recordCount = ds.Tables["StudentRecord"].Rows.Count;
if (recordCount > 0)
{
DataTable dtab = ds.Tables["StudentRecord"];
objemp.city = dtab.Rows[0]["city"].ToString();
objemp.address = dtab.Rows[0]["address"].ToString();
}
}
comm.Dispose();
return objemp;
}
catch
{
throw new FaultException("Something went wrong");
}
}
public string PostSampleMethod(string city)
{
try
{
string m = "True";
string connStr = ConfigurationManager.ConnectionStrings["constr"].ToString();
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand();
comm.CommandText = "update tblemployee set city='rupndagr' where city=" + city;
comm.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter(comm);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
return m;
}
catch
{
throw new FaultException("Something went wrong");
}
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
Please help here is web.config
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="constr" connectionString="Data Source=.;Initial Catalog=dbHealthcare;Integrated Security=false;Persist Security Info=True;User Id=sa;Password=nic123" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="Healthcare.Service1" behaviorConfiguration="ServiceBehaviour">
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" name="webHttpBinding" binding="webHttpBinding" contract="Healthcare.IService1" behaviorConfiguration="webHttp">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
</endpoint>
<endpoint name="mexHttpBinding"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="1"></serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>