Using Json Script Call a Web service
In aspx design page the following code should be written for calling a WCF Service
var varType;
var varUrl;
var varData;
var varContentType;
var varDataType;
var varProcessData;
//Generic function to call AXMX/WCF Service
function CallService() {
$.ajax({
type: varType, //GET or POST or PUT or DELETE verb
url: varUrl, // Location of the service
data: varData, //Data sent to server
contentType: varContentType, // content type sent to server
dataType: varDataType, //Expected data format from server
processdata: varProcessData, //True or False
success: function (msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
function ServiceSucceeded(result) {//When service call is sucessful
// alert("Service Result: " + JSON.stringify(result.d));// For Service Result type JSON
document.getElementById('<%=LblMessage.ClientID%>').innerHTML = JSON.stringify(result.d);//To show the out put result in a Lebel
}
function ServiceFailed(result) {
//alert('Service call failed: ' + result.status + '' + result.statusText);
document.getElementById('<%=Label.ClientID%>').innerHTML = result.status + '' + result.statusText;//To show the out put result in a Label
varType = null; varUrl = null; varData = null; varContentType = null; varDataType = null; varProcessData = null;
}
function WebServiceCall(imagedata, FIRData, strSize, FingerID_text) {
varType = "POST";
varUrl = "Service/00.svc/FunctionNmae"; //(ServerPath/WCF Service name/Function Name)
varData = '{"StrImage":"' + encode64(imagedata) + '","StrFIR":"' + encode64(FIRData) + '","StrSize":"' + strSize + '","FingerID_text":"' + FingerID_text + '"}'; //Parameter Passing to the Service Method
varContentType = "application/json; charset=utf-8";
varDataType = "json";
varProcessData = true;
CallService();
}
var varUrl;
var varData;
var varContentType;
var varDataType;
var varProcessData;
//Generic function to call AXMX/WCF Service
function CallService() {
$.ajax({
type: varType, //GET or POST or PUT or DELETE verb
url: varUrl, // Location of the service
data: varData, //Data sent to server
contentType: varContentType, // content type sent to server
dataType: varDataType, //Expected data format from server
processdata: varProcessData, //True or False
success: function (msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
function ServiceSucceeded(result) {//When service call is sucessful
// alert("Service Result: " + JSON.stringify(result.d));// For Service Result type JSON
document.getElementById('<%=LblMessage.ClientID%>').innerHTML = JSON.stringify(result.d);//To show the out put result in a Lebel
}
function ServiceFailed(result) {
//alert('Service call failed: ' + result.status + '' + result.statusText);
document.getElementById('<%=Label.ClientID%>').innerHTML = result.status + '' + result.statusText;//To show the out put result in a Label
varType = null; varUrl = null; varData = null; varContentType = null; varDataType = null; varProcessData = null;
}
function WebServiceCall(imagedata, FIRData, strSize, FingerID_text) {
varType = "POST";
varUrl = "Service/00.svc/FunctionNmae"; //(ServerPath/WCF Service name/Function Name)
varData = '{"StrImage":"' + encode64(imagedata) + '","StrFIR":"' + encode64(FIRData) + '","StrSize":"' + strSize + '","FingerID_text":"' + FingerID_text + '"}'; //Parameter Passing to the Service Method
varContentType = "application/json; charset=utf-8";
varDataType = "json";
varProcessData = true;
CallService();
}