简体   繁体   English

请求/响应网络服务

[英]Request / Respond web service

I'm new to web services so I could use a little help. 我是Web服务的新手,因此可以使用一些帮助。

I have a project that a web service will request data from me and I will respond with a web service giving the data. 我有一个项目,Web服务将向我请求数据,然后我将通过提供数据的Web服务进行响应。 I've created the response web service as you can see below: 我已经创建了响应Web服务,如下所示:

Person.cs 人.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]

[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();  
}  

I tested it on my browser by invoking and it works fine. 我通过调用在浏览器上对其进行了测试,并且效果很好。

How can I make it respond to the requested idno from the other web service? 如何使它响应来自其他Web服务的请求的idno?

Thank you in advance. 先感谢您。

You have to consume your created Web service. 您必须使用创建的Web服务。 Created one can be added as reference for other project's and through C# code you can consume and get the response. 创建的代码可以添加为其他项目的参考,通过C#代码,您可以使用并获取响应。 Sample Code Snippet. 示例代码段。

        Service1 webService = new Service1();

        Console.WriteLine(webService.MyFirstWebMethod(“Bradd”, “Pitt”));

        Console.ReadLine();

For more details refer http://www.csharptutorial.in/37/csharp-net-how-to-consume-a-web-service-in-csharp-net-visual-studio-2010 有关更多详细信息,请参见http://www.csharptutorial.in/37/csharp-net-how-to-consume-a-web-service-in-csharp-net-visual-studio-2010

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM