but when i published my wcf service in server i can't get response from server.can any `one` pls help me to solve this problem here i will attach my code below
and i have used ms sql with wcf rest services my client side code will be jquery.
here my wcf interface service
[OperationContract]
[WebInvoke(UriTemplate = "InsertScore", Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
int InsertScore(string ename, int eno);
this s my class service to call inter face( service1.svc)
public class Service1 : IService1
{
string strConString = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
my method for insertion
public int InsertScore(string ename, int eno)
{
int resule;
Debugger.Break();
try
{
using (SqlConnection con = new SqlConnection(strConString))
{
using (SqlCommand cmd = new SqlCommand("insert into employee1 values ('" + ename + "'," + eno + ")", con))
{
con.Open();
resule = cmd.ExecuteNonQuery();
con.Close();
return resule;
}
}
}
catch (Exception ex)
{
clsLog objLog = new clsLog(AppDomain.CurrentDomain.BaseDirectory + "Log\\log.txt", 0);
objLog.Write(ex.ToString());
//return -1;
//return "error";
return -1;
}
}
this is my jquery function:
$(".submit").click(function () {
$.ajax({
cache: false,
async: true,
type: "POST",
dataType: "json",
//
url: " http://test.gloriatech.in:601/Service1.svc/InsertScore",
data: '{ "ename": "' + $("#Name").val() + '", "eno" : "' + $("#no").val() + '" }',
contentType: "text/json;charset=utf-8",
success: function (r) { alert("Successfully Registered!!!"); },
error: function (e) { alert(e.statusText); }
});
});
});
html tag:
finally i am attaching web config
Hemant KumarPosted Oct 15, 2011, 6:01 AM
Here is a Good BlogPost For You : http://pranayamr.blogspot.com/2011/03/rest.html
http://www.codeproject.com/KB/ajax/jQueryWCFRest.aspx
REST service with WCF and Consume using jQuery