How to access WCF service in sharepoint using ECMA Script
I had created WCF service and deployed it to IIS, Now i want to access this service in my Visual webpart using ECMA script. Any suggestion would be appreciated.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Prasham SabadraPosted Mar 23, 2015, 6:15 AM
following is sample code.
$.ajax({
url: "URL OF WCF SERVICE",
type: "POST",
data: Data,
async: true,
success: gotResult,
contentType: "application/json; charset=utf-8",
dataType: "json",
processdata: true,
error: function ServiceFailed(result) {
alert(errorMsg.innerHTML);
}
});
function gotResult(content, txtFunc, xhr) {
if (content) {
//Content processing
}
}
}
Here,
Data : Inputs if WCF service requires
gotResult: Function. get called if WCF service is successfully get called. Result comes in "Content" field.
I hope this will help you. Please let me know in case more details are required.