我在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"。它只是写了20次loginService.Roles。我需要进入下一个层次。今天是星期五,而且是我的生日,请帮帮我吧lol。
[+] roles = Count = 20
[+] {loginService.Role}
Name = "Administrator"
nameField = "Administrator"
首先,你是否通过先设置服务引用来创建一个合适的客户端代理类?
使用Visual Studio添加服务引用,在项目的Solution Explorer中右击References节点,选择 "Add Service Reference"。你要输入的网址如下。
http:/domain.comServicename.asmx?WSDL。
服务返回的WSDL文档被Visual Studio用来创建代理类,然后你可以检查这个类来查看所有的方法、它们的签名和类型。
几乎所有的Web服务都被配置为返回这个WSDL XML文档。