我撞到了砖墙。请帮忙。我从来没有在svc文件中遇到任何断点,所以我不知道发生了什么。
我尝试了其他几种解决方案,但没有骰子...。
我的jsonstring是
string jsonString = "[{\"details\":\"Hello World\"}]";
其他文件.cs:
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "updateDataViaPost", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
ResponseData updateDataViaPost(RequestData rdata);
客户代码:
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var request = new StringContent(jsonString, Encoding.UTF8, "application/json");
var response = client.PostAsync(requestUrl, request).Result;
var result = response.Content.ReadAsStringAsync();
}
RequestData
public class RequestData
{
[DataMember]
public string details { get; set; }
}
现在可以在此处使用函数,但传递给它的rdata为null:
public Stream updateDataViaPost(RequestData rdata)
{
var data = rdata.details.Split('|');
......
看起来该字符串需要为字符串jsonString =“ [{” details“:” Hello World“}]”“;
答案 0 :(得分:0)
感谢大家的帮助!非常感谢。
现在为所有这些工作供将来参考:
[DataContract]
public class UpdateTableData
{
[DataMember]
public string TableName { get; set; }
[DataMember]
public string ColumnNames { get; set; }
[DataMember]
public string Values { get; set; }
[DataMember]
public string WhereColumnNames { get; set; }
[DataMember]
public string WhereValues { get; set; }
}
public string updateDataViaPost(UpdateTableData rdata)
{
..... (MY UNIQUE CODE)......
}
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "updateDataViaPost", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
//ResponseData updateDataViaPost(RequestData rdata);
string updateDataViaPost(UpdateTableData data);
string jsonString = new JavaScriptSerializer().Serialize(updateTable);
using (HttpClient client = new HttpClient())
{
//POST Request
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var request = new StringContent(jsonString, Encoding.UTF8, "application/json");
var response = client.PostAsync(URI, request).Result;
var result = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
string strresult = result;
}