locked
Connect Xamarin to server SignalR and get data SqlDependecy RRS feed

  • Question

  • Hello everybody ! I have SQLdependency and I connect him client by Javascript

    		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();
    
    
    				}
    			}
    		}
    		  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(''));
    					  }
    				  }
    			  });
    		  }


    How can I connect to the index.aspx/GetData by Xamarin ?

    Saturday, October 21, 2017 6:05 PM

All replies

  • [WebMethod]
    [ScriptMethod(UseHttpGet = true)]
    
    public static IEnumerable<Products> GetData()
    {
    }
    

    It's a GET not a POST.

    ASP.NET issues like SignalR and ASPX  can be addressed at the ASP.NET forums.

    http://forums.asp.net/

    Saturday, October 21, 2017 8:16 PM
  • DA924x thank you !

    Monday, October 23, 2017 6:23 PM
  • Hi Andrei Damaschin,

    If your question has been solved, please mark the solution as answer to close the thread. This will make answer searching easier in the forum and be beneficial to community members as well.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 7, 2017 10:11 AM