TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sathish kumar
NA
14
2.5k
WCF REST Service Not working Put method in Server
Jul 1 2014 7:29 AM
I have 2 application one Webapplication another one service application both hosted in same server.
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:
----------------
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="CallzillaDataInfoServiceBehavior" name="CallzilaService.Modules.CallzillaDataInfoService">
<endpoint binding="webHttpBinding" bindingConfiguration="WebHttpBinding" contract="CallzilaService.Modules.ICallzillaDataInfoService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="CallzillaDataInfoServiceBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="CallzillaDataInfoServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug httpHelpPageEnabled="true" httpsHelpPageEnabled="false" includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<!--<serviceAuthorization serviceAuthorizationManagerType="CallzilaService.MyServiceAuthorizationManager, CallzilaService" />-->
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding" crossDomainScriptAccessEnabled="true">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="None" />
</security>
</binding>
<binding
name="StreamBinding"
transferMode="Streamed"
maxReceivedMessageSize="2147483647"
openTimeout="12:00:00"
receiveTimeout="12:00:00"
closeTimeout="12:00:00"
sendTimeout="12:00:00"
maxBufferSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None" />
</binding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<!-- Add Code fore CORS -->
<!-- this have no affect for crossDomainScriptAccessEnabled (jsonp) because custom endpoints use binding instead -->
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" crossDomainScriptAccessEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2097150" useFullyQualifiedRedirectUrl="true"/>
<!--<httpModules>
<add name="ServicesModule" type="CallzilaService.Modules.CallzillaDataInfoService, CallzilaService.Modules"/>
</httpModules>-->
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<add name="ServicesModule" type="CallzilaService.Modules.CallzillaDataInfoService,CallzilaService.Modules"/>
</modules>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
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
Reply
Answers (
1
)
Query to show a dynamic column in crystal report
WCF REST Put Method not working Server