Solved

Array within Web Service

Posted on 2011-09-25
9
287 Views
Last Modified: 2012-06-27
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
Comment
Question by:ScubeduFan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 500 total points
ID: 36596767
public LogResponse[] LookupCustomer()
{
  List<LogResponse> TempResults = new List<LogResponse>();
  ....
  TempResults.Add(new LogResponse(NewValid, NewResponse));
  ....
  return TempResults.ToArray();
}
0
 

Assisted Solution

by:ScubeduFan
ScubeduFan earned 0 total points
ID: 36596794
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
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 500 total points
ID: 36596828
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:ScubeduFan
ID: 36596840
Next error ....

The type 'webServices.logResponse' has no constructors defined
0
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 500 total points
ID: 36596846
   public struct logResponse
    {
        public string Valid;
        public string Response;

        public logResponse (string Valid, Response)
        {
          this.Valid = Valid;
          this.Response = Response;
        }
    }
       
0
 

Author Comment

by:ScubeduFan
ID: 36596878
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
 

Author Comment

by:ScubeduFan
ID: 36596879
Points not given
0
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 36596880
Um... I think I answered the question? One normally awards the points in this situation.
0
 

Author Closing Comment

by:ScubeduFan
ID: 36890355
Thanks for proving me assistance on this.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question