Subscribing to an asynchronous web-service event in both winform and aspx page (C#)?

Wouldn't it be much simpler to achieve what you are trying to do using WebBrowser. ObjectForScripting to keep them in synch? When you select the item in your client app, have it fire a javascript event in the webbrowser control to select it there as well...

Up vote 0 down vote favorite share g+ share fb share tw.

I have a WebBrowser control on a winform. The WebBrowser control shows an aspx page that has a GridView. The Winform has a grid on it as well.

Both the grid on the winform and the gridview on the aspx page pull data from the same table in the same database. The idea is when I select a row on the windows side, it should be selcted on the aspx page without the user pressing the F5/Refresh key. And when a row is selected on the aspx page it is selected on the winforms grid.

I have figured I would have to use a webservice with an event that both the aspx page and the winform subscribe to. I assume this is the best way to solve the problem unless there is another way. Problem is, I am very new asp and c# and as such events and websrvices are also very unfamiliar territory.

How do I write such an event in the webservice? How do I subscribe to it on the aspx page? How do I subscribe to it on the Winform?

Please help Thanks c# events asynchronous service link|improve this question asked Mar 28 '11 at 14:26leon x31.

All web services are synchronous. I.e. They always return a response with your requested information (or an error).

However, you can call them asynchronously which is a bit different. – jgauffin Mar 28 '11 at 14:44 The idea is to get the aspx page get a notification when something happens on the web service without refreshing the entire page. Is this actually possible?

– leon x Mar 30 '11 at 13:32.

Wouldn't it be much simpler to achieve what you are trying to do using WebBrowser. ObjectForScripting to keep them in synch? When you select the item in your client app, have it fire a javascript event in the webbrowser control to select it there as well... A basic summary of the approach here is that the container app (the WinForms one) is able to access the content of the WebBrowser control in order to fire a JS event on the embedded page.

Using the same methods, the JS in the WebBrowser control is also able to communicate back to the client app, so you don't need to go to the trouble of trying to write a service to enable that communication channel.

Note that this approach assumes you have access to the HTML to add the required methods, but it sounds like that is the case anyway. – ZombieSheep Mar 30 '11 at 13:52 Thank you very much ZombieSheep. This was much easier and worked perfectly.

Much appreciated. – leon x Mar 31 '11 at 9:54 It appears that server side controls within an ajax UpdatePanel do not invoke the desired communication. I have placed a DropDownList with AutoPostback set to true on the aspx page and I have this line of code in the SelectedIndexChanged event.

Page.ClientScript. RegisterStartupScript(this.GetType(), "ClientScript", "function(arg1)", true); When the control is outside the UpdatePanel, it runs, when it is inside, it does not. Any thoughts?

Thanks. – leon x Mar 31 '11 at 10:46 Its ok. I got the solution: dotnetspider.com/resources/… – leon x Apr 1 '11 at 9:15.

Alternative 1: You can use ajax to poll the webservice. Let the webservice respond with either a "nothing new" message or with the wanted information. Check out the ajax methods in jQuery for simple handling.

Alternative 2: Implement a COMET similar approach. Google "asp.net comet". Basically you create a long-living request (through ajax) where the webserver do not respond until either something new have happened or when the request is about to time out.

I appreciate the reply. Given the application I want to build, your approach is more than I actually require. The idea is to reuse a control made for in asp.net within windows without rewriting the code for the control.

I had actually tried the ajax route, with a timer and the web service would indicate if nothing had happened. I was however concerned that if there are many clients, the web service will be burdened unnecessarily. Thanks – leon x Mar 31 '11 at 10:05.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions