Yogesh Wani

Yogesh Wani

  • NA
  • 195
  • 25.9k

WCF POST Method

Sep 8 2015 2:03 AM
Hi Friends,
 Since last many days i am trying to implement WCF POST with below Code and not able to do so can you help me out?
[OperationContract]
[WebInvoke(UriTemplate="/SaveUserData",
Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string SaveUserData(CustomerDetails CustomerDetail); 
 
[DataContract]
public class CustomerDetails
{
[DataMember]
public string First_Name { get; set; }
[DataMember]
public string Last_Name { get; set; }
[DataMember]
public string Mobile_No { get; set; }
[DataMember]
public string Email_ID { get; set; }
[DataMember]
public string Address { get; set; }
[DataMember]
public string City { get; set; }
[DataMember]
public string Pincode { get; set; }
 
 function POSTMethodCall() {
var Customer = {"CustomerDetails":{ "First_name": "My", "Last_name": "Test",
"Mobile_No": "1234567890", "Email_ID": "[email protected]",
"Address": "XYZ ABCD", "City": "ASDFGH", "Pincode": "400708"}};
var st = JSON.stringify(Customer);
debugger;
$.ajax({
type: "POST",
url: "http://www.abc.co.in/Service1.svc/SaveUserData",
Data: st,
contentType: "application/json",
dataType: "json",
success: function (Data) {
// Play with response returned in JSON format
},
error: function(Data){
alert("Error:"+Data)
}
});

Answers (9)