WCF POST无效,给出错误400错误请求 [英] WCF POST Not working giving Error 400 Bad Request

查看:161
本文介绍了WCF POST无效,给出错误400错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友我一直面临WCF post方法的问题

Hi Friends i have been facing the issue with WCF post method

推荐答案

我的服务代码是



[OperationContract]

[WebInvoke(UriTemplate =/ SaveUserData,

方法=POST,

ResponseFormat = WebMessageFormat。 Json,

BodyStyle = WebMessageBodyStyle.WrappedRequest)]

string SaveUserData(CustomerDetails CustomerDetail);

[DataContract]

公共类CustomerDetails

{

[DataMember]

public string First_Name {get;组; }



[DataMember]

public string Last_Name {get;组; }



[DataMember]

公共字符串Mobile_No {get;组; }



[DataMember]

公共字符串Email_ID {get;组; }



[DataMember]

公共字符串地址{get;组; }



[DataMember]

public string City {get;组; }



[DataMember]

public string Pincode {get;组; }

}



试图发布记录使用





函数POSTMethodCall(){

var Customer = {CustomerDetails:{First_name:我的,Last_name:测试,

Mobile_No:1234567890,Email_ID:abc @ gmail.com,

地址:XYZ ABCD,城市:ASDFGH,Pincode :400708}};

var st = JSON.stringify(Customer);

调试器;
my code for service is

[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; }
}

trying to post the record using


function POSTMethodCall() {
var Customer = {"CustomerDetails":{ "First_name": "My", "Last_name": "Test",
"Mobile_No": "1234567890", "Email_ID": "abc@gmail.com",
"Address": "XYZ ABCD", "City": "ASDFGH", "Pincode": "400708"}};
var st = JSON.stringify(Customer);
debugger;


.ajax({

类型:POST,

url:http://www.abc.co.in/Service1.svc/SaveUserData\",,br />
数据:st,

contentType:application / json,

dataType:json,

成功: function(Data){

//使用JSON格式返回的响应播放

},

错误:function(Data){

ale rt(错误:+数据)

}

});



}
.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)
}
});

}


这篇关于WCF POST无效,给出错误400错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆