c# - NetworkError: 405 Method Not Allowed in WCF -
i trying phone call wcf rest service method using jquery ajax phone call , getting error
"networkerror: 405 method not allowed - http://localhost:55911/service1.svc/testing"
here code
$(document).ready(function () { $("#button2").click(function () { var input = { userid: "11111" }; $.ajax({ type: "post", url: " http://localhost:55911/service1.svc/testing", data: json.stringify(input), contenttype: "application/json; charset=utf-8", datatype: "json", success: function (response) { alert("success"); }, error: function (xhr, status, error) { alert("failure"); alert(stattus.tostring); } }); }); });
and
[operationcontract] [webinvoke(method = "post", uritemplate = "/testing", bodystyle = webmessagebodystyle.bare, requestformat = webmessageformat.json, responseformat = webmessageformat.json)] string testing(int userid);
and
public string testing(int userid) { sqlconn = new sqlconnection(connectionstring); sqlconn.open(); sqlcmd = new sqlcommand("testinsertion", sqlconn); sqlcmd.commandtype = commandtype.storedprocedure; sqlcmd.parameters.add("@id",userid); sqlcmd.executenonquery(); sqlconn.close(); homecoming "true"; }
what doing wrong here??any suggestion??
edit:after commenting //contenttype: "application/json"
posting , throwing
"networkerror: 400 bad request - http://localhost:55911/service1.svc/testing"
please check http request method post
@ client (html
) , on server (wcf service
) because networkerror 405 status suggests calling code (html
) using wrong http method, wcf service
working ok.
please refer: 405 method not allowed error in wcf
updatewhat believe maintain rest of things (also content type contenttype: "application/json"
) alter parameter type string
int
in wcf service
public string testing(string userid) { sqlconn = new sqlconnection(connectionstring); sqlconn.open(); sqlcmd = new sqlcommand("testinsertion", sqlconn); sqlcmd.commandtype = commandtype.storedprocedure; sqlcmd.parameters.add("@id",userid); sqlcmd.executenonquery(); sqlconn.close(); homecoming "true"; }
c# wcf rest jquery
No comments:
Post a Comment