我是网络服务的新手,所以我可以使用一些帮助。
我有一个项目,Web服务将向我请求数据,我将回复提供数据的Web服务。我已经创建了响应Web服务,如下所示:
Person.cs
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace TestWebServices
{
public class Person
{
public string IdNo { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
[的WebMethod]
[WebMethod(Description = "Return Applicants")]
publicPerson[] retApplicants(String idno)
{
string connString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection connection = new SqlConnection(connString);
SqlCommand command = new SqlCommand("selectApplicant", connection);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add("@idno", SqlDbType.VarChar).Value = idno;
connection.Open();
SqlDataReader reader = command.ExecuteReader();
List<Person> persons = new List<Person>();
Person persReturned;
while (reader.Read())
{
persReturned = new Person();
persReturned.IDNO = reader["IdNo"].ToString();
persReturned.FirstName = reader["FirstName"].ToString();
persReturned.LastName= reader["LastName"].ToString();
persons.Add(persReturned);
}
return persons.ToArray();
}
我通过调用在我的浏览器上测试它,它工作正常。
如何让它响应来自其他网络服务的请求的idno?
提前谢谢你。
答案 0 :(得分:0)
您必须使用已创建的Web服务。可以添加创建的一个作为其他项目的参考,并通过C#代码消费并获得响应。 示例代码段。
Service1 webService = new Service1();
Console.WriteLine(webService.MyFirstWebMethod(“Bradd”, “Pitt”));
Console.ReadLine();