locked
SqlDependency from ASP.NET to Xamarin RRS feed

  • Question

  • User312213045 posted

    I have in the hub SignalR a method with SQLDependecy . Can I get this return in the Xamarin ? For example in the client side ASP.NET I get by JavaScript below . I need this dependecy in android , if somebody worked with SignalR hellp me please to find solution. Is not usualy hub connection , I not found to read for SQLDependecy in the hub for android .

    public static void Show()
        {
            IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
            context.Clients.All.displayStatus();
        }
    
    public static IEnumerable<Products> GetData()
    {
    
        using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBase"].ConnectionString))
        {
            connection.Open();
            using (SqlCommand command = new SqlCommand(@"SELECT [Guests] FROM  [1]", connection))
            {
                // Make sure the command object does not already have
                // a notification object associated with it.
                command.Notification = null;
                SqlDependency.Start(ConfigurationManager.ConnectionStrings["DataBase"].ConnectionString);
                SqlDependency dependency = new SqlDependency(command);
                dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
    
                if (connection.State == ConnectionState.Closed)
                    connection.Open();
    
                using (var reader = command.ExecuteReader())
                    return reader.Cast<IDataRecord>()
                        .Select(x => new Products()
                        {
                            Guests = x.GetString(0),
                        }).ToList();
    
    
            }
        }
    }
    private static void dependency_OnChange(object sender, SqlNotificationEventArgs e)
    {
        Show();
    }

      $(function () {
    
          // Proxy created on the fly
          var job = $.connection.myHub;
    
          // Declare a function on the job hub so the server can invoke it
          job.client.displayStatus = function () {
              getData();
          };
    
          // Start the connection
          $.connection.hub.start();
          getData();
      });
    
      function getData() {
          var $tbl = $('#tbl');
          $.ajax({
              url: 'index.aspx/GetData',
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              type: "POST",
              success: function (data) {
                  debugger;
                  if (data.d.length > 0) {
                      var newdata = data.d;
                      $tbl.empty();
                      $tbl.append(' <tr><th>ID</th><th>Name</th><th>Last Executed Date</th><th>Status</th></tr>');
                      var rows = [];
                      for (var i = 0; i < newdata.length; i++) {
                          rows.push(' <tr><td>' + newdata[i].Guests + '</td></tr>');
                      }
                      $tbl.append(rows.join(''));
                  }
              }
          });
      }
    Monday, October 23, 2017 6:27 PM

All replies

  • User753101303 posted

    Hi,

    My understanding is that you are looking at a client side library you could use in Xamarin ? A Xamarin forum might be better. If I remember you have a .NET client side Library that you could use from .NET (and that likely support Xamarin as well ?)

    Wednesday, October 25, 2017 12:11 PM
  • User312213045 posted

    Hello PatriceSc !

     Yes thank you ! I looking for client side for Xamarin . I registered in many forums and no body help , but fo example we can make very easy and JavaScript client side and Xamarin client side for chat in SignalR , but with SqlDependecy I can not find . Only for JavaScript .

    Wednesday, October 25, 2017 12:46 PM
  • Thursday, October 26, 2017 1:59 AM
  • User312213045 posted

    Hello Billy Liu !

    No , I know about this . This SqlDependency for Xamarin , but I need client side for Xamarin wich get data from SqlDependecy which work in ASP.Net . It must work for example like showed JavaScript .

    Thursday, October 26, 2017 6:04 AM
  • User753101303 posted

    The SqlDependency should be on the server side and the resulting information would be transmitted using SignalR ?

    I see https://github.com/SignalR/SignalR/tree/dev/src/Microsoft.AspNet.SignalR.Client.Portable which I believe should support using SignalR from Xamarin. I would have to try.

    Thursday, October 26, 2017 7:52 AM
  • User312213045 posted

    PatriceSC yes , thank you ! I will try .

    Thursday, October 26, 2017 8:05 AM
  • User1120430333 posted

    [WebMethod]
    [ScriptMethod(UseHttpGet = true)]

    public static IEnumerable<Products> GetData()
    {

    }

    This is assuming you are using an aspx.cs codebehide , and it's GET not a POST.

    Thursday, October 26, 2017 10:29 PM
  • User312213045 posted

    DA924 ok thank you !

    Friday, October 27, 2017 6:09 AM