Dealy

Dealy

  • NA
  • 213
  • 0

Request/Respond web service

Jun 29 2016 4:06 AM
Hello,
 
I'm new to web services so I could use a little help.
 
I have a project that a web service will request data from me and I will respond with a web service giving the data. I've created the response web service as you can see below: 
 
Person.cs 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5.   
  6. namespace TestWebServices  
  7. {  
  8.     public class Person  
  9.     {  
  10.         public string IdNo { getset; }  
  11.         public string FirstName { getset; }  
  12.         public string LastName { getset; }  
  13.     }  
  14. }  
[WebMethod]
  1. [WebMethod(Description = "Return Applicants")]  
  2. publicPerson[] retApplicants(String idno)  
  3. {    
  4.     string connString =  ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
        SqlConnection connection = new SqlConnection(connString);
     
  5.   
  6.     SqlCommand command = new SqlCommand("selectApplicant", connection);  
  7.     command.CommandType = System.Data.CommandType.StoredProcedure;  
  8.     command.Parameters.Add("@idno", SqlDbType.VarChar).Value = idno;  
  9.     connection.Open();  
  10.     SqlDataReader reader = command.ExecuteReader();  
  11.   
  12.     List<Person> persons = new List<Person>();  
  13.     Person persReturned;  
  14.   
  15.     while (reader.Read())  
  16.     {  
  17.         persReturned = new Person();  
  18.         persReturned.IDNO = reader["IdNo"].ToString();  
  19.         persReturned.FirstName = reader["FirstName"].ToString();  
  20.         persReturned.LastName= reader["LastName"].ToString();  
  21.         persons.Add(persReturned);  
  22.     }  
  23.   
  24.     return persons.ToArray();  
  25. }  
 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?
 
Thank you in advance. 
 
 

Answers (2)