【问题标题】:Nothing returned after authentication?认证后什么都没有返回?
【发布时间】:2012-04-23 00:20:09
【问题描述】:

当我尝试使用此方法返回学生时,它不会显示任何内容或任何错误,但如果我没有在密码框中输入任何内容,我会收到 404 错误,所以我知道它正在工作,所以我的身份验证方法是'不工作,我基本上想验证用户并从学生集合中返回一些东西,比如名字?

private void button20_Click(object sender, EventArgs e)
{
    string uri = string.Format("http://localhost:8000/Service/AuthenticateStudent/{0}/{1}", textBox28.Text, textBox29.Text);
    XDocument xDoc = XDocument.Load(uri);
    var Tag12 = xDoc.Descendants("Student")
        .Select(n => new
        {
            FirstName = n.Element("FirstName").Value,
        })
        .ToList();


    dataGridView12.DataSource = Tag12;
}

【问题讨论】:

  • 您是否在客户端中添加了对 WCf 的 Web 引用??

标签: c# wcf linq web-services authentication


【解决方案1】:

您需要创建一个特殊的返回类型,其中包括您当前返回的布尔值以及 Student:

public class AuthenticationResult
{
    public bool IsValid {get;set;}
    public Student ValidatedStudent {get;set;}
}

然后从您的 WCF 方法返回此类型的对象:

public AuthenticationResult AuthenticateStudent(string studentID, string password)
{
    var result = students.FirstOrDefault(n => n.StudentID == studentID);
    bool flag = false;
    if (result != null) {...}

    ...
    return new AuthenticationResult {IsValid = flag, ValidatedStudent = result};
}

【讨论】:

  • +1 谢谢,那么我的实际身份验证方法呢?我仍然坚持使用flag = UserPassword.ToList().SequenceEqual(StudentFound.Salt);,它应该是来自我的数据合同学生的 studentfound.Password 但如果我将其设置为我会收到错误整行说你不能将列表转换为iqueryable<char>
  • @KirstyWhite:您在这篇文章中提出了多个问题。尝试通过密码检查缩小问题范围,并将其作为一个单独的问题提出。
  • 好的 Stripling 我会尝试,只是很难解释
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多