【发布时间】:2012-03-08 08:19:15
【问题描述】:
我在 VS2010 中使用 C#,我需要一些有关 Web 应用程序的帮助。我对网络服务没有太多经验。我获得了一个 Web 服务的 URL,其中包含构建应用程序登录部分所需的方法。没有文档。我有登录片工作。然后我就卡住了。成功登录后,我需要调用另一个方法,该方法返回经过身份验证的用户可以访问的应用程序列表(或对象?)。例如,它为我自己返回的项目是 157 应用程序的(名称、描述、位置)。我只是想看看 157 个应用程序中是否存在 1 个。
我已经 3 天没有运气了。我已经能够将结果转储到 ArrayList 并将该列表作为 GridView 的源,但我不知道如何迭代结果。在这个阶段我没有包含任何代码,因为我认为我的方法不正确,想知道你们会怎么做?将结果对象转换为 xml 可能吗?感谢您的反馈和建议。
更新:
protected void Button_Click(object sender, EventArgs e)
{
ServiceReference1.Identity usr = new ServiceReference1.Identity();
loginService.AuthenticationService auth = new loginService.AuthenticationService();
loginService.AuthenticationService auth = new loginService.AuthenticationService();
auth.Login(TextBox1.Text, TextBox2.Text, "10.*.*.*");
List<object> roles = new List<object>(auth.GetIdentityRoles(TextBox1.Text));
IEnumerable myEnum = roles;
IEnumerator myEnumerator = myEnum.GetEnumerator(); //Getting the Enumerator
myEnumerator.Reset(); //Position at the Beginning
while (myEnumerator.MoveNext()) //Till not finished do print
{
Response.Write(myEnumerator.Current.ToString());
}
}
现在,如果我在调试时将鼠标悬停在第 6 行的“角色”上,我可以看到我想要搜索的字段。我想知道“Name”是否包含“Administrator”,但我所有的示例只在第 13 行返回“loginService.Role”。它只写了 loginService.Roles 20 次。我需要降到一个新的水平。今天是星期五,今天是我的生日,请帮帮我,哈哈。
[+] roles = Count = 20
[+] {loginService.Role}
Name = "Administrator"
nameField = "Administrator"
【问题讨论】:
-
尝试使用 foreach 关键字遍历 ArrayList 以检查其中的内容?
-
即使您的方法不正确,这里的人也可以调整您的工作方法,或者至少指出您的方法不起作用的原因。
-
另外,请改掉使用
ArrayList的习惯。如果您需要任意类型的列表,请使用List<object>。 -
我今天将使用 List
标签: c# asp.net visual-studio-2010 web-services