如果我删除此value = new { token = 1 }
或转换为value = ""
webmethod工作正常,则反复返回后会触发方法。
为什么会发生这种情况?
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "login/{username}/{password}")]
public Result Login(string username, string password)
{
somecode..
if (user != null && user.Password == password)
{
return new Result { statusCode = "200", message = "Success", value = new { token = 1 } };
}
else
{
return new Result { statusCode = "401", message = "Fail", value = "" };
}
}
public class Result
{
public string statusCode { get; set; }
public string message { get; set; }
public object value { get; set; }
}
这也没有用;
return new Result { statusCode = "200", message = "Success", value = new Token { token = "some string" } }
答案 0 :(得分:0)
尝试这样
public Result Login(string username, string password)
{
int token=1;
Result response = new Result();
if (user != null && user.Password == password)
{
response.message = "Success";
response.statusCode = "200";
response.value = token;
}
else
{
response.message = "Fail";
response.statusCode = "401";
response.value = null;
}
return response;
}
public class Result
{
public string statusCode { get; set; }
public string message { get; set; }
public object value { get; set; }
}