Access database data using a Web Service in Silverlight Application

saadashari
 
on Oct 13, 2014 01:35 AM
3579 Views

I have written the followind web service:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]

   [System.Web.Script.Services.ScriptService]
    public class OlapConnect : System.Web.Services.WebService
    {

        [WebMethod]
        public DataSet olapConnection()
        {

            SqlConnection conn = new SqlConnection(Utilities.GetConnectionString("DebugConnectionString"));
            SqlCommand cmd = new SqlCommand();

            SqlDataAdapter adapter = new SqlDataAdapter();

            DataSet dsInfo = new DataSet();

            string query = "SELECT  * FROM employeeDetails";

            try
            {

                cmd.CommandText = query;
                cmd.CommandType = CommandType.Text;
                cmd.Connection = conn;
                Utilities.HandleConnectionState(conn);
                adapter.SelectCommand = cmd;
                adapter.Fill(dsInfo);
                return dsInfo;
            }
            catch (Exception ex)
            {
                System.Web.HttpContext.Current.Response.Write(ex.Message);
                return null;
            }
            finally
            {
               Utilities.HandleConnectionState(conn);
            }

After this, I have added this web service as a service reference in the Silverlight project [available in the same solution].

I have a pre-written code in Main.xaml.cs that calls values from a saved XML file, however, I want to use the above web service to get details from the database. The code in Main.xaml.cs is as follows, which needs to be changed. TIA

 

public MainPage()
        {
            InitializeComponent();

            // load data from embedded zip resource
            var ds = new DataSet();
            var dt = new DataTable();

            var asm = Assembly.GetExecutingAssembly();
            using (var s = asm.GetManifestResourceStream("OlapQuickStart.nwind.zip"))
            {
                var zip = new C1ZipFile(s);
                using (var zr = zip.Entries[0].OpenReader())
                {
                    // load data
                    ds.ReadXml(zr);
                }
            }



            _c1OlapPage.Loaded += (s, ea) =>
            {
                // bind olap page to data
                _c1OlapPage.DataSource = ds.Tables[0].DefaultView;

                // show sales by country and category
                var olap = _c1OlapPage.OlapPanel.OlapEngine;
                olap.DataSource = ds.Tables[0].DefaultView;
                olap.BeginUpdate();
                olap.RowFields.Add("Country");
                olap.ColumnFields.Add("Category");
                olap.ValueFields.Add("Sales");
                olap.Fields["Sales"].Format = "n0";
                olap.EndUpdate();
            };
        }

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Azim
 
on Oct 13, 2014 03:45 AM