// In order create a DataProvider programmatically and configure it as a REST webservice, we also
// need to create a SDT collection and set it as the DataProvider output property.
SDT sdt = new SDT(kbmodel);
sdt.Name = "sdt_Countries";
sdt.Parent = Folder.GetRoot(kbmodel);
SDTLevel nivelSup = sdt.SDTStructure.Root;
nivelSup.IsCollection = true;
// SDT Items
SDTItem item1 = nivelSup.AddItem("CountryId", Artech.Genexus.Common.eDBType.NUMERIC, 4, 0);
SDTItem item2 = nivelSup.AddItem("CountryName", Artech.Genexus.Common.eDBType.VARCHAR, 30, 0);
sdt.Save();
// And next, the DataProvider:
DataProvider dp = new DataProvider(kbmodel);
dp.Name = "DPRV_Countries";
dp.Parent = Folder.GetRoot(kbmodel);
dp.SetPropertyValue(Artech.Genexus.Common.Properties.DPRV.ExposeAsWebService, true);
dp.SetPropertyValue(Artech.Genexus.Common.Properties.DPRV.WebServiceProtocol,
Artech.Genexus.Common.Properties.DPRV.WebServiceProtocol_Values.RestProtocol);
dp.SetPropertyValue(Artech.Genexus.Common.Properties.DPRV.CollectionName, "Countries");
dp.SetPropertyValue(Artech.Genexus.Common.Properties.DPRV.Output, new KBObjectReference(sdt.Key));
dp.DataProviderSource.Source =
@"sdt_Countries " +
"{ " +
" sdt_CountriesItem " +
" { " +
" CountryId = CountryId " +
" CountryName = CountryName " +
" } " +
"} ";
dp.Save();