jQuery UI Widgets Forums Plugins Data Adapter Web Services

This topic contains 6 replies, has 2 voices, and was last updated by  Amar Kansara 7 years, 10 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Web Services Posts
  • Web Services #86095

    Amar Kansara
    Participant

    Dear Admin,

    I am facing a problem with collecting data using web service. My web service is suppose to return the data in XML format. The web service is hosted on localhost (IIS) and working perfectly fine when being accessed directly from browser, but it failing to present data on widgets controls bound to data adaptor.

    Please help

    Amar Kansara

    Web Services #86097

    Hristo
    Participant

    Hello Amar Kansara,

    We have different examples with binding to XML:
    http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxdataadapter/bindingtoxml.htm?light
    http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/bindingtoxml.htm?light
    http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxcombobox/bindingtoxml.htm?light
    (this examples could be useful)
    Please provide us simple example with that you try to do.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

    Web Services #86114

    Amar Kansara
    Participant

    Dear Hristo,

    Thank you for the reply. But this is not what I am looking for. This examples I already have consumed in several pages in my test projects. I even have successfully tried several projects by collecting data in xml format into dataAdapter and bind it with several widgets using webmethods.

    Now, I want to do the same by writing the webmethods in a webservice.

    Following is my WebService Code;

    using System;
    using System.Collections;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Linq;
    using System.Data.SqlClient;
    using System.Data;
    using System.Web.Script.Services;
    using System.Configuration;

    /// <summary>
    /// Summary description for GenDataService
    /// </summary>
    [WebService(Namespace = “http://pppl.com/webservices/”)]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class GenDataService : System.Web.Services.WebService {

    public GenDataService () {

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

    [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
    public string GetUsers()
    {
    string Sql = “Select UserName, UserID From NIFUsers”;
    SqlCommand cmd = new SqlCommand(Sql);

    DataSet ds = GetData(cmd);

    System.IO.StringWriter writer = new System.IO.StringWriter();
    ds.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false);
    return writer.ToString();
    }

    [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
    public string GetMI()
    {
    string Sql = “SELECT MenuID, Posturl FROM NIFMenuSystem”;
    SqlCommand cmd = new SqlCommand(Sql);
    // Populate the DataSet.
    DataSet ds = GetData(cmd);
    // return the Customers table as XML.
    System.IO.StringWriter writer = new System.IO.StringWriter();
    ds.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false);
    return writer.ToString();
    }

    [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
    public string getMenu()
    {
    string Sql;
    Sql = “SELECT MenuID As id, ParentID, MenuText, SubmenuWidth, Posturl From NIFMenuSystem Where MenuID <> ‘-1’ Order By MenuID”;
    SqlCommand cmd = new SqlCommand(Sql);
    // Populate the DataSet.
    DataSet data = GetData(cmd);
    // return the Customers table as XML.
    System.IO.StringWriter writer = new System.IO.StringWriter();
    data.Tables[0].WriteXml(writer, XmlWriteMode.WriteSchema, false);
    return writer.ToString();
    }

    private static DataSet GetData(SqlCommand cmd)
    {
    string strConnString = ConfigurationManager.ConnectionStrings[“PPPL”].ConnectionString;
    using (SqlConnection con = new SqlConnection(strConnString))
    {
    using (SqlDataAdapter sda = new SqlDataAdapter())
    {
    cmd.Connection = con;
    sda.SelectCommand = cmd;
    using (DataSet ds = new DataSet())
    {
    try
    {
    sda.Fill(ds);
    }
    catch (Exception ex)
    {
    RecordError(“GetData”, ex.Message);
    }
    return ds;
    }
    }
    }
    }

    private static void RecordError(string ErrLoc, string ErrMsg)
    {
    string Sql;
    string conStr = ConfigurationManager.ConnectionStrings[“PPPL”].ConnectionString;
    using (SqlConnection con = new SqlConnection(conStr))
    {
    Sql = “INSERT INTO ErrorLog VALUES(‘” + ErrLoc + “‘, ‘” + ErrMsg + “‘)”;
    using (SqlCommand InsCmd = new SqlCommand(Sql))
    {
    InsCmd.CommandType = CommandType.Text;
    InsCmd.Connection = con;
    con.Open();
    InsCmd.ExecuteNonQuery();
    }
    con.Close();
    }
    }
    }

    This webservice is hosted successfully on localhost (IIS) and working as expected.

    Following is my script.
    <script type=”text/javascript”>
    $(document).ready(function() {
    // prepare the data
    var SrcMI =
    {
    datatype: “xml”,
    datafields: [
    { name: ‘MenuID’ },
    { name: ‘Posturl’ }
    ],
    async: false,
    record: ‘Table’,
    url: ‘http://localhost/PPPLWebService/GenDataService.asmx/GetMI’
    };
    var mDA = new $.jqx.dataAdapter(SrcMI, { contentType: ‘application/json; charset=utf-8’ });
    mDA.dataBind();

    $(“#jqxDropDown”).jqxDropDownList({
    selectedIndex: 0, source: mDA, displayMember: “Posturl”, valueMember: “MenuID”, width: 100, height: 25
    });

    var sourceM =
    {
    datatype: “xml”,
    datafields: [
    { name: ‘id’ },
    { name: ‘ParentID’ },
    { name: ‘MenuText’ },
    { name: ‘SubmenuWidth’ },
    { name: ‘Posturl’ }
    ],
    id: ‘id’,
    async: false,
    record: ‘Table’,
    url: ‘http://localhost/PPPLWebService/GenDataService.asmx/getMenu’
    };

    // create MenuDA data adapter.
    var MenuDA = new $.jqx.dataAdapter(sourceM, { contentType: ‘application/json; charset=utf-8’ });
    MenuDA.dataBind();

    var records = MenuDA.getRecordsHierarchy(‘id’, ‘ParentID’, ‘items’, [{ name: ‘MenuText’, map: ‘label’}]);
    $(‘#jqxMenu’).jqxMenu({ source: records, height: 30, width: ‘650px’ });
    $(‘#jqxMenu’).jqxMenu({clickToOpen: true});
    $(‘#jqxMenu’).jqxMenu({autoOpen: true});
    $(“#jqxMenu”).on(‘itemclick’, function(event)
    {
    var item = $(“#jqxDropDown”).jqxDropDownList(‘getItemByValue’, event.args.id);
    //alert(item.label);
    if (item.label != ”)
    {
    window.open(‘<%= ResolveUrl(“‘+ item.label + ‘”) %>’, ‘_top’);
    }
    });
    });
    </script>

    My Database is in SQLServer 2005. And it was working perfectly good with earlier project.

    Web Services #86118

    Hristo
    Participant
    Web Services #86127

    Amar Kansara
    Participant

    Hello Hristo,

    I tried that too with no luck.

    I even tried to convert the webservice to output data in JSON format, but still no result.
    Thanks

    • This reply was modified 7 years, 10 months ago by  Amar Kansara.
    Web Services #86227

    Hristo
    Participant

    Hello Amar Kansara,

    Excuse me for the delay.
    I would like to ask you is there any error message in the console?
    Also could you try to set loadError callback of the DataAdapter to check for some errors messages.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

    Web Services #86318

    Amar Kansara
    Participant

    Dear Hristo,
    Sorry for the late reply.. So far I was working with earlier version of jqxWidgets. Just today I have downloaded latest version and I going to try the same with new version.

    I hope it will work. I will check set loaderror call back in new test project.

    Thank you

    Amar Kansara

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.