Newbie Question: fill a dataset with results from web service call

T

Todd

I am trying to get a better grasp of using web services. I have had
success when I have a user type something into a text box and then
pass that text to call an external web service on another server.
This has worked for me when the result was only a single word such as
"true" or "false". Now, I would like to make a call to a service that
returns either rows of data or more than one word, such as a stock
symbol returning the price, high, low, estimates, rating, etc. How
would I make the call to the external web service and then assign the
results to a Dataset? I want to use this dataset as the datasource
for a Data Grid to display on the screen. Or perhaps there is an
easier way to do this?
 
M

Michael Pearson

The "easier" way to do this is to just avoid the webservice piece and call
the database code directly.
For a webservice, it should be as simple as making your WebMethod() return a
Dataset type.

VB.Net Example

<WebMethod()> Public Function GetListOfSomething(ByVal sParamBlah As String)
As DataSet

Dim myDataSet as New DataSet()

'Insert Code here to connect to database and populate a myDataSet

Return myDataset
End Function

Michael
 
T

Todd

Thanks Michael. I understand what you are talking about as I have
used the Command object several times to use a sql call or stored
procedure call to populate a Dataset and display the information in a
DataList or DataGrid. However, the purpose of calling the web service
is to access data that I can't get from my database. For example, if
I want to enter a stock symbol into a text box and press a submit
button, I can't pass that sysmbol to a table on my database because I
am not housing current data for stock prices. But there are several
external web services that will do this. I just need to know the
VB.Net syntax "from A to Z" on how I would return the web service
result set into a dataset to bind to a datagrid. I have added my Web
Reference for the stock price web service to my project, and I am
passing the symbol to the service. I just need help on how I would be
able to return the results to a DataGrid to display to the user.

I have had success using an e-mail validator with this syntax:
dim proxyEmail as new [Project
Name].refernce.path.to.external.web.service
Label.Text = proxyEmail.[webservice_name](textbox1.text)

this returns either "true" or "false" to a label that is displayed to
the user. Now if I want to return more data from a more complicated
web service and bind that to a Datagrid to display to a user how would
I do that? Do I use a Dataset control? An XMLDataDocument? Something
else? Syntax examples would be appreciated. Thanks!
 
D

Dino Chiesa [Microsoft]

have you looked at the DataSet.Merge() method ?
Maybe you get ds1 from webservice1, then get ds2 from webservice2, then
merge them, then display?
-D

Todd said:
Thanks Michael. I understand what you are talking about as I have
used the Command object several times to use a sql call or stored
procedure call to populate a Dataset and display the information in a
DataList or DataGrid. However, the purpose of calling the web service
is to access data that I can't get from my database. For example, if
I want to enter a stock symbol into a text box and press a submit
button, I can't pass that sysmbol to a table on my database because I
am not housing current data for stock prices. But there are several
external web services that will do this. I just need to know the
VB.Net syntax "from A to Z" on how I would return the web service
result set into a dataset to bind to a datagrid. I have added my Web
Reference for the stock price web service to my project, and I am
passing the symbol to the service. I just need help on how I would be
able to return the results to a DataGrid to display to the user.

I have had success using an e-mail validator with this syntax:
dim proxyEmail as new [Project
Name].refernce.path.to.external.web.service
Label.Text = proxyEmail.[webservice_name](textbox1.text)

this returns either "true" or "false" to a label that is displayed to
the user. Now if I want to return more data from a more complicated
web service and bind that to a Datagrid to display to a user how would
I do that? Do I use a Dataset control? An XMLDataDocument? Something
else? Syntax examples would be appreciated. Thanks!

"Michael Pearson" <[email protected]> wrote in
message news: said:
The "easier" way to do this is to just avoid the webservice piece and call
the database code directly.
For a webservice, it should be as simple as making your WebMethod() return a
Dataset type.

VB.Net Example

<WebMethod()> Public Function GetListOfSomething(ByVal sParamBlah As String)
As DataSet

Dim myDataSet as New DataSet()

'Insert Code here to connect to database and populate a myDataSet

Return myDataset
End Function

Michael
 
M

Michael Pearson

Oh, I see. You are getting like some Text or Array types back, and you want
to "build your own" dataset.

Take a look at this site:
http://www.informit.com/isapi/product_id~{6A3BC7D8-47B7-4C4B-BBDF-5B20CBC985F6}/content/index.asp

I used that to build this small sample

Dim oDataSet As New DataSet()

Dim oTable As New DataTable()

Dim oRow As DataRow

Dim oStock(1) As Object

oTable.Columns.Add("StockSymbol", GetType(String))

oTable.Columns.Add("StockPrice", GetType(String))



oStock(0) = "BLAH"

oStock(1) = "$3.50"

oTable.Rows.Add(oStock)

oStock(0) = "BLAH2"

oStock(1) = "$6.00"

oTable.Rows.Add(oStock)



oDataSet.Tables.Add(oTable)

Michael



Todd said:
Thanks Michael. I understand what you are talking about as I have
used the Command object several times to use a sql call or stored
procedure call to populate a Dataset and display the information in a
DataList or DataGrid. However, the purpose of calling the web service
is to access data that I can't get from my database. For example, if
I want to enter a stock symbol into a text box and press a submit
button, I can't pass that sysmbol to a table on my database because I
am not housing current data for stock prices. But there are several
external web services that will do this. I just need to know the
VB.Net syntax "from A to Z" on how I would return the web service
result set into a dataset to bind to a datagrid. I have added my Web
Reference for the stock price web service to my project, and I am
passing the symbol to the service. I just need help on how I would be
able to return the results to a DataGrid to display to the user.

I have had success using an e-mail validator with this syntax:
dim proxyEmail as new [Project
Name].refernce.path.to.external.web.service
Label.Text = proxyEmail.[webservice_name](textbox1.text)

this returns either "true" or "false" to a label that is displayed to
the user. Now if I want to return more data from a more complicated
web service and bind that to a Datagrid to display to a user how would
I do that? Do I use a Dataset control? An XMLDataDocument? Something
else? Syntax examples would be appreciated. Thanks!

"Michael Pearson" <[email protected]> wrote in
message news: said:
The "easier" way to do this is to just avoid the webservice piece and call
the database code directly.
For a webservice, it should be as simple as making your WebMethod() return a
Dataset type.

VB.Net Example

<WebMethod()> Public Function GetListOfSomething(ByVal sParamBlah As String)
As DataSet

Dim myDataSet as New DataSet()

'Insert Code here to connect to database and populate a myDataSet

Return myDataset
End Function

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top