Reputation: 51
the Following Code is My WCFRestful unfortunately when I want to Call my Service From JavaScript the id parameter does not bind to my id parameter in Delete Function
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "POST")]
void Delete(int id);
}
public class Service : IService
{
public void Delete(int id)
{
//I do Some Work
}
}
JavaScript call of my service :
$(function () {
function successDel(data) {
alert('done');
}
callService("MyserviceAddress/Delete", "POST", JSON.stringify({"id":"11"}), successDel, function errordel(xhr, status, error) {
alert(error);
}, "application/json; charset=utf-8", "json");
})
function callService(url, type, data, successFunc, errorFunc, contentType, dataType) {
$.ajax({
url: url,
type: type,
cache: false,
proccessData: false,
contentType: contentType,
dataType:dataType,
data: data,
success: successFunc,
error: errorFunc
})
}
do you have any suggestion to resolve this problem?
Any helps would be appreciated in advance.
Upvotes: 0
Views: 19
Reputation: 51
this problem Solved by change this line
[WebInvoke(Method = "POST")]
to
[WebInvoke(Method = "POST",BodyStyle=WebMessageBodyStyle.WrappedRequest)]
Upvotes: 1