I have searched this question , and got too many links ,and tried most of them , but my problem is not solved . I'm running my VS in admin mode. I created new project then add WCF service to my project .I want to call my service through ajax.
this is my code in Sevice.cs and Iservice.cs
namespace WcfWithAjax
{
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
string GetEmployeeList();
}
}
and
namespace WcfWithAjax
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service : IService
{
[OperationContract]
public string GetEmployeeList()
{
string str = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;
IList<Employee> employeeList = new List<Employee>();
using (SqlConnection con = new SqlConnection(str))
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from Employee", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
employeeList.Add(new Employee()
{
Id = dr.GetInt32(0),
Name = dr.GetString(1),
Position = dr.GetString(2),
Age = dr.GetInt32(3),
Salary = dr.GetInt32(4)
});
}
con.Close();
}
JavaScriptSerializer objJson = new JavaScriptSerializer();
return objJson.Serialize(employeeList);
}
}
}
and then configured my web.config file as follow
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="WcfWithAjax.Service" behaviorConfiguration="metadataBehavior">
<endpoint address="" binding="webHttpBinding" contract="WcfWithAjax.IService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
now I'm Debuging my project but it's showing
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
Here is some link i got but unable to solve my problem
failed-to-add-a-service-service-metadata-may-not-be-accessible-make-sure-your