Dataset/datatable from web services

Dataset/datatable from web services

  
Hello!

I have a webservice with some methods that rerturn datasets or datatables. How can I show this data in a table records widget?

Thanks in advance.
I tried to define the datatable data in a structure, and then store the web service method result in a record list of that structure, but it wont work..
Hi Marthijn

One way to achieve your purpose would be to create an extension that defines a structure to suit your needs.
This extension would have an action that returns a RecordList of your Structure. The action would access the web service and make the conversion from the dataset to the RecordList.

Say the web service is named Service and the method is named GetDataSet. GetDataSet returns a DataSet, in which each row contains the CompanyName and ContactName from a Customer table (for example the Sql Server's northwind sample db). At the end of this post you have a possible Web Service implementation code.

You could follow these steps:
1. Start Integration Studio and create a new extension (.Net only). Name it GetDatasetRL and save the extension.
2. Add a new Structure named Customer
3. Add 2 attributes to Customer, named CompanyName and ContactName (of type Text)
4. Add a new action, named GetMyCustomers with an output parameter named RL of Record Definition Customer
5. Select menu entry File / Edit Source Code .NET (or press the corresponding toolbar button). Visual Studio is launched.
6.Inside Visual Studio, add a Web Reference to the web service. For example, to "http://localhost/TestWs1/Service.asmx?wsdl". In the Web Reference name, enter MyWs.
7. Open file GetDatasetRL.cs and change the MssGetMyCustomers( ) code:

public void MssGetMyCustomers(out OutSystems.NssGetDatasetRL.RLCustomerRecordList ssRL) {
ssRL = new RLCustomerRecordList(null);
MyWs.Service ws = new MyWs.Service();
System.Data.DataSet ds = ws.GetDataSet();

foreach (System.Data.DataRow dr in ds.Tables[0].Rows) {
RCCustomerRecord rec = new RCCustomerRecord();
rec.ssSTCustomer.ssCompanyName = dr[0].ToString();
rec.ssSTCustomer.ssContactName = dr[1].ToString();
ssRL.Append(rec);
} // MssGetMyCustomers
}

8. Inside Visual Studio build the project, to assure there are no errors
9. Exit Visual Studio
10. Back to Integration Studio, select File / 1-Click Publish (or press the corresponding toolbar button): log to Service Center with a user with the needed permissions (eg: localhost, admin/admin)
11. Exit from Integration Studio and go back to Service Studio
12. In Service Studio, select File / Add/Remove References...
13. Add a reference to your extension's Action.

Now you can use its output parameter, which is a Recordlist with the web service's data.
Regards,
António Melo


Web Service sample:

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

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService {
public Service () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public System.Data.DataSet GetDataSet() {
SqlConnection cn = new SqlConnection("server=localhost;uid=sa;pwd=sa;database=northwind");
SqlCommand cmd = new SqlCommand("select CompanyName, ContactName from Customers", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
ds.DataSetName = "myDataSetName";
da.Fill(ds, "Customer");
da.Dispose();
cn.Close();
return ds;
}
}
Thank you very much!!
Hi,

Can you please let me know, how to pass a parameter to this method?


System.Data.DataSet ds = ws.GetDataSet(param1, param2);

both param1 and param2 are date parameters.

*******************************************************


 public void MssGetMyCustomers(out OutSystems.NssGetDatasetRL.RLCustomerRecordList ssRL) {

            ssRL = new RLCustomerRecordList(null);

            MyWs.Service ws = new MyWs.Service();

            System.Data.DataSet ds = ws.GetDataSet();


            foreach (System.Data.DataRow dr in ds.Tables[0].Rows) {

                RCCustomerRecord rec = new RCCustomerRecord();

                rec.ssSTCustomer.ssCompanyName = dr[0].ToString();

                rec.ssSTCustomer.ssContactName = dr[1].ToString();

                ssRL.Append(rec);

            } // MssGetMyCustomers

        }

Hi Jith, and welcome to the OutSystems community forums.

I'll have to apologize, but I'm not sure what your question exactly is, and what exactly you are trying to achieve.

The code you pasted was the code that António Melo used specifically to answer Marthijn's question, and it's really meant only to be used for that purpose. Why would you be using it?

I would assume that the "GetDataSet" method you're referring to really isn't the one that António is using, and referring to.

If your question is indeed related to OutSystems and you're having trouble using some specific method, I encourage you to create a new topic in our forums, since that is the best way for others to notice your question and helping you out, and give us some more context on exactly what your problem is - and if possible, attach an eSpace or extension so we can better take a look at it :)

Let us know more about it.

Regards,

Paulo Tavares
Hi, I have the same problem, i want to send a DataTable from a WebService and in the outsystems when I implement the webservice he said that the return is a Type Text.

How can i said is a DataTable? 
I also have same problem. Is there any way to fix this issue without create an extension??