请求/响应网络服务
Request / Respond web service
我是 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(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();
}
我通过调用在我的浏览器上对其进行了测试,它工作正常。
如何让它响应来自其他 Web 服务的请求 IDNO?
提前谢谢你。
您必须使用您创建的 Web 服务。创建的一个可以添加为其他项目的参考,并且通过 C# 代码您可以使用并获得响应。
示例代码片段。
Service1 webService = new Service1();
Console.WriteLine(webService.MyFirstWebMethod(“Bradd”, “Pitt”));
Console.ReadLine();
我是 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(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();
}
我通过调用在我的浏览器上对其进行了测试,它工作正常。
如何让它响应来自其他 Web 服务的请求 IDNO?
提前谢谢你。
您必须使用您创建的 Web 服务。创建的一个可以添加为其他项目的参考,并且通过 C# 代码您可以使用并获得响应。 示例代码片段。
Service1 webService = new Service1();
Console.WriteLine(webService.MyFirstWebMethod(“Bradd”, “Pitt”));
Console.ReadLine();