没有Request body的方法调用成功.当我使用下面的Request body时,我得到HTTP / 1.1 400 Bad Request.你看到下面要求身体有任何明显的问题吗? 请求机构 { "_userConfigData":{"UserName":"bXZpbmphbXVyaQ==", "Fir
请求机构
{ "_userConfigData":{"UserName":"bXZpbmphbXVyaQ==", "FirstName":"User1", "LastName":"Last1", "ContactInfo":"None" }, "_configResult": "Miscellaneous" }
请求标题
User-Agent: Fiddler Content-Type: application/json Host: localhost:1706 Content-Length: 167
这是服务器端方法:
[OperationContract] [WebInvoke(UriTemplate = "UpdateUserDetails/?_clientIP={_clientIP}&AdminName={AdminName}", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] public void UpdateUserDetails(UserConfigData _userConfigData, ConfigResult _configResult, string _clientIP, string AdminName) { // }
这是我与Fiddler2一起使用的URL:
http://localhost:1706/WCF/UserConfig/UserConfigService.svc/UpdateUserDetails?_clientIP=localhost&AdminName=admin
谢谢,
我能够让你的代码工作,但我不得不做一些修改.>我不得不将查询字符串携带的数据移动到正文中,否则它不起作用.
>我不得不摆脱BodyStyle Wraped选项.
无论如何,这是更新的模型对象与您的数据:
public class UserConfigData { public string UserName { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string ContactInfo { get; set; } } public class Result { public UserConfigData UserConfigData { get; set; } public string ConfigResult { get; set; } public string ClientIp { get; set; } public string AdminName { get; set; } }
服务器端方法:
[WebInvoke(UriTemplate = "UpdateUserDetails", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] public void UpdateUserDetails(Result result) { // }
你传入的json:
{ "AdminName":"String content", "ClientIp":"String content", "ConfigResult":"String content", "UserConfigData":{ "ContactInfo":"String content", "FirstName":"String content", "LastName":"String content", "UserName":"String content" } }
更新:
提琴手请求屏幕截图:
并且请求到达服务器UpdateUserDetails()处理程序: