Need guidance on getting data to Silverlight app via ASP.NET/WCF
First of all thank you for any help. I have looked extensively and haven't found a sure solution, so here I am...
Basically I am developing an asp.net (4.0) app. One webform represents a report and is divided into two pieces: - a div that acts like a control panel which contains textboxes, comboboxes, calendars, etc. which provide parameters for a query, and a button to get the data. - a div that holds the silverlight control host. The silverlight开发者_StackOverflow社区 app only contains a custom datagrid control.
So, as you would imagine, the user provides values for the parameters and clicks the button to get the data into the silverlight app's custom datagrid control. -I know what you're probably asking yourself, why don't I just add the controls to the silverlight app and use RIA services. Without going into too much detail, we want a newer datagrid that we can slap into some of our existing asp.net pages.
I don't know what is the best practice for something like this. I've looked extensively and there are several options I have considered and even got my feet wet experimenting (with no success).
What I think I would like to do is have a wcf service that only sends data to the silverlight client on the page. Let me be clear that I do not need a request/reply message exchange pattern because the silverlight client isn't going to be making any requests. In my "quest" to accomplish this I have found examples/tutorials on duplex messaging which I think might work well if I can set the asp page as a client to the service and the silverlight app as a client to the same service. The use clicks the button and the asp page's service reference calls the service to get the data and then in turn it sends the data to the silverlight client. One concern I have is that all of the tutorials I have found send the messages to all of the clients, so what if two people are visiting the site at the same time? Would it update both of thier sl apps? How would I target the right client?
So my question is can anyone provide any advice, links, or other resources for a solution to this scenario?
First off, I don't think you need Silverlight. There are a ton of great UI controls out there like Telerik RadGrid that you could drop into your existing app and be up and running in an hour or two.
Having said that, if you really want to make this work, what you need is pub/sub that works both in the browser and in Silverlight. Take a look at PubNub. You get 5,000 messages per day for free, and works in virtually any client (phone, Silverlight, browser, etc) with a simple API.
Basically, your Silverlight client would subscribe to a "channel" to be notified when the filter parameters change, and your form would publish messages to this channel, either through JavaScript or server side, telling subscribers (1 in your case) of changed filter values. When the Silverlight client is notified, it would make a request for data via WCF.
Bit of a hack though. I would encourage you to drop the Silverlight and use an AJAX grid. Hope this helps!
精彩评论