我正在尝试通过Post Async方法传递类对象
public async void SAveDetails(clsPickList obj)
{
using (HttpClient client = new HttpClient())
{
HttpContent content = new StringContent(JsonConvert.SerializeObject(obj));
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var result = await client.PostAsync("http://-Port-/-svc file name-/InsertUserDetails", content) ;
result.EnsureSuccessStatusCode();
if (result.Content != null)
{
var responseContent = await result.Content.ReadAsStringAsync();
}
}
}
到
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "InsertUserDetails")]
string InsertUserDetails(Model.clsPickList obj);
并按如下所示插入对象值
public string InsertUserDetails(Model.clsPickList obj)
{
cmd.Parameters.AddWithValue("@UserName", obj.UserName);
cmd.Parameters.AddWithValue("@Password", obj.Password);
}
但是当我通过WP8访问链接时,它返回404错误。 由于我是WCF的新手,所以我非常感谢任何人的帮助。
先谢谢了。