1

When I try to return the student using this method it doesn't show anything or any error, if I however don't put anything in the password box I get a 404 error so I know its working so my authenticate method isn't working, I basically want to authenticate the user and return something from the student collection, like the FirstName?

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;
}
4

1 回答 1

1

You'll want to create a special return type that includes the boolean you're currently returning, as well as the Student:

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

Then return an object of this type from your WCF method:

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};
}
于 2012-04-23T02:47:29.357 回答