473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

beginner: nned to change webservice return type

I have had a look around but I'm either not finding or not seeing the
answer to this, what i want to do is reurn the results as an array, or
some other worldly useful format that flash mx2004 can read. But when
I did thiss I was told datasets were the way to go, but needs an
array, prefer typed as were changing it.

Here is the current code: (shortened for readability)

[WebService(Namespace = "http://microsoft.com/webservices/", Name =
"Sample", Description = "Sample")]
public class WebService1{
public WebService1(){
}
private DataSet getDataStreams(string sqlQuery){
System.Data.OleDb.OleDbConnection oleConn1 = new
System.Data.OleDb.OleDbConnection();
oleConn1.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\db\\database.mdb";
OleDbDataAdapter da = new OleDbDataAdapter(sqlQuery,
oleConn1);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
//as you see, I set up and return the dataset, but I either
want to change the way this is built, so it just creates the array
here, or I want a way to convert this dataset, to a typed array. Even
field by field is acceptable at this point.
}
[WebMethod (Description="Gets a list as a dataset")]
public DataSet getOrderData(){
return getDataStreams("SELECT * from table1");
}
}

I don't want someone to do this for me, just point me in the right
direction, unless it's just a couple of lines, then please help. make
it a little quicker.
Any help appreciated.
Reagrds
Shaine
Nov 16 '05 #1
7 5737
Shaine,

In this case, you will have to cycle through the results yourself, and
return the array.

I think you can still use a data set, as I believe that flash will allow
you to process XML. If not, then using an array or something of that sort
is the best way to go. In this case, you might want to return a two
dimensional array (if the types are the same).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Shaine Fisher" <sh**********@madasafish.com> wrote in message
news:aa**************************@posting.google.c om...
I have had a look around but I'm either not finding or not seeing the
answer to this, what i want to do is reurn the results as an array, or
some other worldly useful format that flash mx2004 can read. But when
I did thiss I was told datasets were the way to go, but needs an
array, prefer typed as were changing it.

Here is the current code: (shortened for readability)

[WebService(Namespace = "http://microsoft.com/webservices/", Name =
"Sample", Description = "Sample")]
public class WebService1{
public WebService1(){
}
private DataSet getDataStreams(string sqlQuery){
System.Data.OleDb.OleDbConnection oleConn1 = new
System.Data.OleDb.OleDbConnection();
oleConn1.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\db\\database.mdb";
OleDbDataAdapter da = new OleDbDataAdapter(sqlQuery,
oleConn1);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
//as you see, I set up and return the dataset, but I either
want to change the way this is built, so it just creates the array
here, or I want a way to convert this dataset, to a typed array. Even
field by field is acceptable at this point.
}
[WebMethod (Description="Gets a list as a dataset")]
public DataSet getOrderData(){
return getDataStreams("SELECT * from table1");
}
}

I don't want someone to do this for me, just point me in the right
direction, unless it's just a couple of lines, then please help. make
it a little quicker.
Any help appreciated.
Reagrds
Shaine

Nov 16 '05 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:<#x**************@TK2MSFTNGP14.phx.gbl>...
Shaine,

In this case, you will have to cycle through the results yourself, and
return the array.


Sounds a bit numb, but how would I do that, the best way?
Nov 16 '05 #3
I can't follow this entire post, but I think you are asking for a way to return
a collection of custom types in a web service method... There are many
ways to do this, but I'll demonstrate the one it appears as if everyone is
talking about.

ArrayList list = new ArrayList(); // Using this becuase I don't know the count
of items here.
using(SqlConnection conn = new SqlConnection(...)) {
SqlCommand comm = new SqlCommand(..., conn);

conn.Open();
using(SqlDataReader dr = comm.ExecuteReader()) {
while(dr.Read()) {
list.Add(MyObject.Fill(dr));
}
dr.Close();
}
}
return (MyObject[]) list.ToArray(typeof(MyObject));

The above assumes a couple of things. First, MyObject has a static method named
Fill that
creates and fills an instance of MyObject based on the current state in the
SqlDataReader.
This is a fairly standard approach. Two, we are assuming that you don't know the
number of
objects in advance, and so I'm giving you the option of using an ArrayList...

For performance, you'd want to try and get the count. Every command in Sql
returns a
@@ROWCOUNT, and you can return that in an output parameter to preallocate your
array.

Another option for peformance is to forget count and return a fixed size array
where you
only fill those element slots you care about. The rest can be null, and in turn
get thrown
across the SOAP layer as nil objects. This isn't a huge increase in bandwidth
usage, but
you have to always return an array that is as large as the largest possible
array you might
return, OR, return the results paged so that if you overwhelm the array, return
that array
and tell the client there is more data.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Shaine Fisher" <sh**********@hotmail.com> wrote in message
news:3b**************************@posting.google.c om...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:<#x**************@TK2MSFTNGP14.phx.gbl>...
Shaine,

In this case, you will have to cycle through the results yourself, and
return the array.


Sounds a bit numb, but how would I do that, the best way?

Nov 16 '05 #4
> I think you can still use a data set, as I believe that flash will allow
you to process XML. If not, then using an array or something of that sort
is the best way to go. In this case, you might want to return a two
dimensional array (if the types are the same).

Thanks for the reply.
Flash mx2004 cannot use a dataset as a source with the webservice
connector, but flash remoting apparantly will, but this is overboard
at the moment.
Using google/deja today so a bit slow, but is there a quick clean way
to process the dataset (100 records, 48 fields in each) to a typed
array, a link to a tutorial, or sample code would be great, I'm not
not scared of learning, just a little worried that this small job is
taking so long to complete.

So if anyone can show me this, please help
Reagards
Shaine
Nov 16 '05 #5

"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:uG**************@TK2MSFTNGP14.phx.gbl...
I can't follow this entire post, but I think you are asking for a way to
return
a collection of custom types in a web service method... There are many
ways to do this, but I'll demonstrate the one it appears as if everyone is
talking about.

ArrayList list = new ArrayList(); // Using this becuase I don't know the
count of items here.
using(SqlConnection conn = new SqlConnection(...)) {
SqlCommand comm = new SqlCommand(..., conn);

conn.Open();
using(SqlDataReader dr = comm.ExecuteReader()) {
while(dr.Read()) {
list.Add(MyObject.Fill(dr));
}
dr.Close();
}
}
return (MyObject[]) list.ToArray(typeof(MyObject));

Thanks for this, I'll work out the finer details of it for Access 2000 (i
know but what can you do) just a quick quiz though do I have to use
conn.open and conn.close for access, I have not used it in the code i
provded, but is there a reason you have of is it an sql specific thing.

This way also removes the need for the dataset, is there a way I could just
go through the dataset records and add them to an array of the dataset
length. With just an additoin to the code instead of rewriting the whoile
thing.

Thanks for your help.
Reagrds
Shaine
Nov 16 '05 #6

"Shaine Fisher" <sh**********@hotmail.com> wrote in message
news:3b**************************@posting.google.c om...
I think you can still use a data set, as I believe that flash will
allow
you to process XML.

Oops I misread that.. sorry, your right flash will allow me to use xml, I
just wanted to get a webservice running properly.
We had a great system, the webservice sent us the info, and we sent data
back and could update the database, and alter the dataset and reload it with
filtered results.

This is why I wanted to keep the dataset and process it into an array, so
all of the filtering and sorting could be done on the dataset and then it
would be converted to an array, for sending back to flash. I get the best of
all worlds. There is not filtering going on in this webservice yet, but
there is in others, and they must be converted too, but I need a solution to
this small problem so I can continue onwards with this project.
But, I have *a* solution, just not the one I wanted to hear. Although I may
not have explained things very well.

I'm going to give it one more try:
Here is the full code: BTW I am using the express tools from MS and after
i've figuired out if it's worth it, I am looking at buying vs.net, though I
may wait until the new version comes out before I do that. I am actually a
ColdFusion person normally.

<%@ WebService Language="C#" Class="WebService1" %>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;
[WebService(Namespace = "http://microsoft.com/webservices/", Name = "None",
Description = "None")]
public class WebService1{
public WebService1(){
}
private DataSet getDataStreams(string sqlQuery)
{
System.Data.OleDb.OleDbConnection oleConn1 = new
System.Data.OleDb.OleDbConnection();
oleConn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\\database.mdb";
OleDbDataAdapter da = new OleDbDataAdapter(sqlQuery, oleConn1);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
[WebMethod (Description="...method1")]
public DataSet getOrderData(){
return getDataStreams("SELECT field1, field2, ... , field48 from
table1");
}
[WebMethod (Description="...method2")]
public DataSet getSOrderData(string passedvar){
return getDataStreams("SELECT field1, field2, ... , field48 from
table1 WHERE table1.var1='" + passedvar + "'");
}
[WebMethod (Description="...method3")]
public DataSet getMemberData(int passedvar2)
{
return getDataStreams("SELECT field1, field2, ... , field48 from
table1 WHERE table1.var1=" + passedvar2);
}
}
So that's it.... We have 3 methods for getting data from the database, each
one uses the same code to return a dataset. I would like to take that
dataset and turn it into something else, in this case it has to be an array,
so I can load it into the webservice connector in flash mx2004.
I cannot find code, or tutorials anywhere on how to take this dataset and
iterate through it passing the values to an array, hopefully strict typing
them on the way.

Please look at this code, and see if you can understand what I am trying to
do, I have had some great feedback, but I hope this explanation is slightly
clearer
Nov 16 '05 #7
Here is an update, I have got it to work in a fashion, it now returns a
readable array, that flash can use, don't quite understand how I got there,
just need 1 final push in the right direction, here is the new code section.

private ArrayList getDataStreams(string sqlQuery){

string mySelectQuery = sqlQuery;

OleDbConnection myConnection = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=D:\\Webspace\\customkit.net\\db\\CMX_Produc ts.mdb");

OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

ArrayList list = new ArrayList();

myConnection.Open();

OleDbDataReader myReader;

myReader = myCommand.ExecuteReader();

while (myReader.Read()){

list.Add(myReader.GetString(1));

}

myReader.Close();

myConnection.Close();

return list;

}

It returns this:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfAnyType xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://microsoft.com/webservices/">
<anyType xsi:type="xsd:string">1093963601</anyType>
<anyType xsi:type="xsd:string">1094027865</anyType>
<anyType xsi:type="xsd:string">-1178915986</anyType>
<anyType xsi:type="xsd:string">-1252773054</anyType>
<anyType xsi:type="xsd:string">1306755996</anyType>
<anyType xsi:type="xsd:string">135569893</anyType>
<anyType xsi:type="xsd:string">-1371539650</anyType>
<anyType xsi:type="xsd:string">-1371598016</anyType>
<anyType xsi:type="xsd:string">1384385168</anyType>
<anyType xsi:type="xsd:string">1404502826</anyType>
<anyType xsi:type="xsd:string">1469145929</anyType>
<anyType xsi:type="xsd:string">-1525322222</anyType>
<anyType xsi:type="xsd:string">1638466920</anyType>
<anyType xsi:type="xsd:string">-1669117341</anyType>
<anyType xsi:type="xsd:string">-1815307276</anyType>
<anyType xsi:type="xsd:string">-1824567740</anyType>
<anyType xsi:type="xsd:string">-1915951204</anyType>
<anyType xsi:type="xsd:string">-1940238693</anyType>
<anyType xsi:type="xsd:string">-197375379</anyType>
<anyType xsi:type="xsd:string">-265779925</anyType>
<anyType xsi:type="xsd:string">-305102370</anyType>
<anyType xsi:type="xsd:string">-369312721</anyType>
<anyType xsi:type="xsd:string">-597564863</anyType>
<anyType xsi:type="xsd:string">687999446</anyType>
<anyType xsi:type="xsd:string">703940518</anyType>
<anyType xsi:type="xsd:string">74151511</anyType>
<anyType xsi:type="xsd:string">-776864097</anyType>
<anyType xsi:type="xsd:string">853551591</anyType>
<anyType xsi:type="xsd:string">-9315851</anyType>
</ArrayOfAnyType>

Not exactly what I wanted, but nearer than we were yesterday. where it says
array of any type, dont understand that, xsd:string is what I asked for so
thats ok, would prefer that the anyType part was actually the name of the
column, can I do that. Obviously this the the list.Add(myReader.GetString()
part, but would like a little help here, as you can see making progress.

Thanks for all your time, sorry to be such a nuisense.

Regards
Shaine
Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: TempMan | last post by:
I want this text field to always display a number variable. The variable "num" is defined in the head, how can I get a text box to display this varibale?? <input name="Balance" type="text"...
5
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
1
by: Thomas D. | last post by:
Hello all, I'm using the IXmlSerializable interface for a project and encounter some problems when testing my webservice in a client application. I know this interface is undocumented and not...
1
by: hl | last post by:
Hi, I'm a beginner and need a little help with getting data back from a web service. I am using VB.Net and have added a web reference to a Wsdl that was provided to me. My reference.vb file...
7
by: Nalaka | last post by:
Hi, I created a sinple web service that returns a dataSet. Then I created a client program that uses this web service (that returns the Dataset). My question is, how did the client figure...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
1
by: jens Jensen | last post by:
Hello , i'm calling a webservice generated with oracle webservice java tools. I'm not able to add a web reference to a .net client the usual way with visual studio 2005. I was therefore...
2
by: Jannicke | last post by:
Hi. I have a project that contains a webservice. To test my webservice I have another class in the same project. In the project I have added a webreference to my webservice. In my class file i call...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.