Solved

Array within Web Service

Posted on 2011-09-25
9
281 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
  • 5
  • 4
9 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:ScubeduFan
Comment Utility
Next error ....

The type 'webServices.logResponse' has no constructors defined
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 500 total points
Comment Utility
   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
Comment Utility
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
Comment Utility
Points not given
0
 
LVL 21

Expert Comment

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

Author Closing Comment

by:ScubeduFan
Comment Utility
Thanks for proving me assistance on this.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now