Dear Gurus!
I try to add silverlight enabled wcf service to my silverlight application in which I use wcf ria services. When I start service my wcf ria services stop working (sometimes it worked, sometimes - not). In my wcf service I use Service Broker For notification of changes in MSSQL database. Here is silverlight enabled wcf service:
[ServiceContract(Namespace = "")] [SilverlightFaultBehavior] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class eventService { [OperationContract] public void StartTrackingChanges() { string connectionString = @"Server=serverName; Initial Catalog=road; User ID =dependency_client; Password =111111; Trusted_Connection =False; Integrated Security=True; "; SqlDependency.Stop(connectionString); SqlDependency.Start(connectionString); } [OperationContractAttribute(AsyncPattern = true)] public IAsyncResult BeginServiceAsyncMethod(string msg, AsyncCallback callback, object asyncState) { return new CompletedAsyncResult<emergEvent>(callback, asyncState); } public emergEvent EndServiceAsyncMethod(IAsyncResult r) { CompletedAsyncResult<emergEvent> result = r as CompletedAsyncResult<emergEvent>; emergEvent ev = new emergEvent(); ev.TimeDetected = DateTime.Now; return ev; } class CompletedAsyncResult<T> : AsyncResult { T data; //bool complete = false; private const string connectionString = @"Server=serverName; Initial Catalog=road; User ID =dependency_client; Password =111111; Trusted_Connection =False; Integrated Security=True; "; public CompletedAsyncResult(AsyncCallback callback, object state) : base(callback, state) { AddEventChanges(); } 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(); try { using (SqlDataReader reader = cmd.ExecuteReader()) { } } catch (Exception) { SqlDependency.Stop(connectionString); SqlDependency.Start(connectionString); using (SqlDataReader reader = cmd.ExecuteReader()) { } } } } } public void WaitChange(object sender, SqlNotificationEventArgs e) { base.Complete(false); } }
So I run the service on the client:
proxy = new eventServiceClient(); proxy.ServiceAsyncMethodCompleted += new EventHandler<ServiceAsyncMethodCompletedEventArgs>(proxy_GetUserCompleted); proxy.StartTrackingChangesAsync(); // start service broker proxy.ServiceAsyncMethodAsync(""); // start waiting for changes
What could be the reason?