• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Array within Web Service

Writing a basic web service and it works fine for a single row result, but if I wanted multiple results to be outputted, how do I change the response into an array? Or is that not how I would return multiple responses?


<%@ WebService Language="C#" Class="webServices" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;

[WebService(Namespace = "http://dev.domain.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class webServices  : System.Web.Services.WebService {
    public struct logResponse
    {
        public string Valid;
        public string Response;
    }
        
    [WebMethod]
    public logResponse lookupCustomer(string username, string password, string customernumber, string customername, string zipcode, string phonenumber, string emailaddress, string ordernumber, string invoicenumber) {
        logResponse cdResult;		
	string cString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["db"].ConnectionString;
        SqlConnection conn = new SqlConnection(cString);
        SqlCommand comm = new SqlCommand();
        SqlDataReader dr;
        int company = 0;
        cdResult.Valid = "";
        cdResult.Response = "";
        try
        {
            conn.Open();
            comm.CommandType = System.Data.CommandType.StoredProcedure;
            comm.CommandText = "lookupCustomer";
            comm.Connection = conn;
            comm.Parameters.AddWithValue("@username", username);
            comm.Parameters.AddWithValue("@password", password);
            comm.Parameters.AddWithValue("@customernumber", customernumber);
            comm.Parameters.AddWithValue("@customername", customername);
            comm.Parameters.AddWithValue("@zipcode", zipcode);
            comm.Parameters.AddWithValue("@phonenumber", phonenumber);
            comm.Parameters.AddWithValue("@emailaddress", emailaddress);
            comm.Parameters.AddWithValue("@ordernumber", ordernumber);
            comm.Parameters.AddWithValue("@invoicenumber", invoicenumber);
            dr = comm.ExecuteReader(System.Data.CommandBehavior.Default);
            comm.Parameters.Clear();
            
            while (dr.Read()) {
            	cdResult.Response = (string)dr["cm_name"];
            }
            
            return cdResult;
        }
        finally {
        }
    }
}

Open in new window

0
ScubeduFan
Asked:
ScubeduFan
  • 5
  • 4
4 Solutions
 
Dale BurrellCommented:
public LogResponse[] LookupCustomer()
{
  List<LogResponse> TempResults = new List<LogResponse>();
  ....
  TempResults.Add(new LogResponse(NewValid, NewResponse));
  ....
  return TempResults.ToArray();
}
0
 
ScubeduFanAuthor Commented:
Dale ... I get the error ...

The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)

on the line ....

List<logResponse> TempResults = new List<logResponse>();


Thanks for your help on this
0
 
Dale BurrellCommented:
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ScubeduFanAuthor Commented:
Next error ....

The type 'webServices.logResponse' has no constructors defined
0
 
Dale BurrellCommented:
   public struct logResponse
    {
        public string Valid;
        public string Response;

        public logResponse (string Valid, Response)
        {
          this.Valid = Valid;
          this.Response = Response;
        }
    }
       
0
 
ScubeduFanAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for ScubeduFan's comment http:/Q_27327019.html#36596794

for the following reason:

Thank You!
0
 
ScubeduFanAuthor Commented:
Points not given
0
 
Dale BurrellCommented:
Um... I think I answered the question? One normally awards the points in this situation.
0
 
ScubeduFanAuthor Commented:
Thanks for proving me assistance on this.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now