我想知道在使用 Windows Phone 7 和 asp.net web api 时如何来回发送数据?
我的 webapi 中有这个方法
public HttpResponseMessage Get(VerifyUserVm vm)
{
if (ModelState.IsValid)
{
userService.ValidateUser(vm.Email);
if (userService.ValidationDictionary.IsValid)
{
HttpResponseMessage reponse = Request.CreateResponse(HttpStatusCode.OK, userService.ValidationDictionary.ModelState["Success"]);
return reponse;
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest, userService.ValidationDictionary.ModelState);
}
}
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
}
public class VerifyUserVm
{
[Required]
public string Email { get; set; }
}
和我的 WP7 中的这段代码
private void btnSignIn_Click(object sender, RoutedEventArgs e)
{
string urlPath = String.Format(WebApiHelp.ApiUrl,"user","get");
UriBuilder uri = new UriBuilder(urlPath);
uri.Query = "email=" + txtEmail.Text;
webclient.OpenReadAsync(uri.Uri);
}
得到的网址是这样的:http://localhost:50570/api/user/get?email=c
但 Vm 始终为空。