I want Save records in to DB So i called service from Jquery to WCF REST Service Using PUT method not working plz any help me slove th issues
JS Code
============
// Declarations
var varData;
var varContentType;
var varDataType;
var varProcessData;
//$.support.cors = true;
//$(document).ready(function () {
//
//});
function getHeaders() {
//btoa is a built in browser cmd for encode Base64
return { 'Authorization': "Basic " + btoa("test:testpw") };
}
// Ajax Call
function CallService(sucessData) {
$.ajax({
headers: getHeaders(),
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
crossDomain: true,
timeout: 200000,
success: sucessData,
error: function (xhr) {// When Service call fails
alert("Error: " + xhr.responseText);
//alert('Error occured in Service Call');
}
});
}
function SaveBookAppoinment()
{
// Form the data structure to insert
var requestAppoinmentId = "0";
var patientName = $('#txtPatientName').val();
var appoinmentReason = $('#txtReason').val();
var emailId = $("#txtEmail").val();
var mobileNo = $("#txtMobile").val();
var doctorId = $("#HTxtBookDoctorId").val();
var doctorslottime = $("#HTxtDoctorSlotTime").val();
// var slotDate = $("#HTxtslotDate").val();
var Status = "1";
// Book Tickets Table data
var TblBookAppoinments = {
//RequestAppoinmentId: requestAppoinmentId ,
PatientName: patientName,
AppoinmentReason: appoinmentReason,
EmailId: emailId,
MobileNo: mobileNo,
DoctorId: doctorId,
// AppointmentDate: slotDate,
AppointmentTime: doctorslottime
};
var AppoinmentInfo = { bookAppoinmentData: TblBookAppoinments };
varType = "PUT";
//varUrl = "http://192.18.11.10/webapi/Modules/DataInfoService.svc/BookAppoinment";
varContentType = "application/json; charset=utf-8";
varData = JSON.stringify(AppoinmentInfo);
varDataType = "json";
varProcessData = true;
CallService(SaveData);
}
// PUT response
function SaveData(response) {
var result = response.PutBookAppoinmentResult;
if (response.PutBookAppoinmentResult == "Success") {
alert('Thanks Register ,We Get back to you!!!');
window.location = '/Modules/Default1.html';
}
else
{ alert('You Appoinment Not Confirm!!!'); }
}
}
Service Application Code
====================
WebConfig code:
----------------
transferMode="Streamed"
maxReceivedMessageSize="2147483647"
openTimeout="12:00:00"
receiveTimeout="12:00:00"
closeTimeout="12:00:00"
sendTimeout="12:00:00"
maxBufferSize="2147483647">
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
ICallzillaDataInfoService Code
============
using System.Collections.Generic;
using System.ComponentModel;
using System.ServiceModel;
using System.ServiceModel.Web;
using Common;
using System.ServiceModel.Description;
using System;
using Common.Modules;
namespace CallzilaService.Modules
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ICallzillaDataInfoService" in both code and config file together.
[ServiceContract]
public interface ICallzillaDataInfoService
{
#region PUT - Insert/Update Category
[OperationContract]
[Description("Create a new Patient Details with given data")]
[WebInvoke(Method = "PUT", UriTemplate = "BookAppoinment", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
string PutBookAppoinment(PatientDetailsDataContract bookAppoinmentData);
#endregion
}
}
CallzillaDataInfoService.svc.cs Code
==========================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Common;
using ManagerLayer;
using Common.Modules;
namespace CallzilaService.Modules
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "CallzillaDataInfoService" in code, svc and config file together.
public class CallzillaDataInfoService : ICallzillaDataInfoService
{
#region PUT - Insert/Update BookAppoinment
public string PutBookAppoinment(PatientDetailsDataContract bookAppoinmentData)
{
return (new BusinessManagerCallzila()).PutBookAppoinmentData(bookAppoinmentData);
}
#endregion
}
}
Data Contract Class file code
============================
#region Create the Patient Table
[DataContract]
public class PatientDetailsDataContract
{
[DataMember]
public Int64 RequestAppoinmentId { get; set; }
[DataMember]
public String PatientName { get; set; }
[DataMember]
public String AppoinmentReason { get; set; }
[DataMember]
public String EmailId { get; set; }
[DataMember]
public String MobileNo { get; set; }
[DataMember]
public Int64 DoctorId { get; set; }
[DataMember]
public bool Status { get; set; }
[DataMember]
public DateTime AppointmentDate { get; set; }
[DataMember]
public String AppointmentTime { get; set; }
}
#endregion
Pradeep ShetPosted Jul 4, 2014, 3:30 PM
Set the below flag in webconfig file and you will able to use all HTTP verbs in your application.
Sometimes only GET & POST verbs are enabled
Hope this solves your problem