Dear Guru!
Silverlight client accesses a wcf service with the task to report on the change that occurred in the mssql database.
Obviously in ServiceAsyncMethod - must be run expectation interrupt mssql (via ServiceBroker). But what to do next?
Here is a sample text of wcf:
[OperationContractAttribute(AsyncPattern = true)] public IAsyncResult BeginServiceAsyncMethod(string msg, AsyncCallback callback, object asyncState) { AddEventChanges(); emergEvent ev = new emergEvent(); return new CompletedAsyncResult<emergEvent>(ev); } public emergEvent EndServiceAsyncMethod(IAsyncResult r) { CompletedAsyncResult<emergEvent> result = r as CompletedAsyncResult<emergEvent>; result.Data.TimeDetected = DateTime.Now; return result.Data; } public void AddEventChanges() { using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand("Select id_event,name,description from dbo.events", connection)) { cmd.Notification = null; SqlDependency dependency = new SqlDependency(cmd); dependency.OnChange += new OnChangeEventHandler(WaitChange); connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { } } } } public void WaitChange(object sender, SqlNotificationEventArgs e) { string s = "Changing in database:"; s += "\nInfo - " + e.Info.ToString() + "\nSource = " + e.Source.ToString() + "\nType - " + e.Type.ToString(); MessageBox.Show(s); AddEventChanges(); }
When a change occurs the WaitChange procedure is called. How to do that at this moment EndServiceAsyncMethod would be invoked?