Need guidance on getting data to Silverlight app via ASP.NET/WCF - asp.net

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 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!

Related

ASP.NET C# SignalR - two different client roles

I am currently working on an ASP.NET MVC (with SignalR) project using C# on server side and JavaScript on client side. I want to make one client the master client who can manage the screens of the other clients, i.e. deciding which topic is to be voted for, follow the polling on his screen, be able to open and close the voting procedure etc. All the other clients do only have ONE screen, i.e. the one with the agenda point title and three voting buttons and a submit button.
The problem I encounter here is that I will then have two different clients with their own distinct screens.
What can I do using SignalR to create these two different clients, let's say an admin and councillers?
Thanks a lot !
Eric

Best architecture for an emergency alert system

I'm developing a software system which receives information (which is saved to a database) and when any information is received (new insert in a specific table) an alert should be seen in the screen in the information center, so proper action can be taken.
I'm writing an application with ASPNET MVC, SQL Server 2008 Express, SQL Agent free for that version of SQL Server, Entity Framework 4, Visual Studio 2010, etc.
Right now, I've set the database and a SQL job that monitors the table each minute, if there is a new records an email is sent to same addresses. My problem is...What then? Which would be the best architecture to follow?
A couple of option I thought about are:
1) In the job connect to a web service and that web service an the web service can open a popup
2) The web page could be pooling the database table to know if there are new records
Is there any way to make push to the web page instead of the page pooling the database server?
I know maybe windows application would fit better here, but right now I must stick with ASPNET MVC as I already started and don't want to create another application.
Thanks! Daniel
Is there any way to make push to the web page instead of the page pooling the database server?
HTML5 WebSockets. Draft, pretty new, specification is still subject to change, to all browsers implement it. You will need a WebSocket Server. If you go that route make sure you read this guy's blog. He is behind Laharsub which is a must try server.
I'm pretty sure you are able to use Silverlight to push data down to the client. Here is a pretty good overview that I read a while back. HTML5 might be a better way to go. But with such limited support it's almost not worth it at this point. Granted the Silverlight application might be out of reach to, but it's still a possibility.
I would suggest that you look into (complex) event processing, or stream processing -- at least to get the feeling for architecture of these systems.
The idea is to capture a stream of events before they reach database, route them (process) within the event processor and put them in the DB from there -- treating the DB as only one of event destinations (subscribers).
Take a look at Streambase, ruleCore, and many others.
These were all developed for the type of scenario you described.
Try to see the problem from the other angle. Develop a web client that reads the database every minute and compare to last pull ...

asp.net sending data

How do you send data from an ASP.NET web application to a windows form application?? How do you establish the connection? I looked up webrequest/webresponse/post but i think thats only if you want to communicate between 2 asp.net web applications.
You might use a socket.
It would help if you're more specific about exactly what you're trying to accomplish. Do you need live communication, or would connecting to a shared database do what you need? Is the web application on the same computer as the server or a different one from the forms application?
Update:
If you're trying to pass messages to the Windows Form without using or implementing any sort of protocol, you might look into how to use LISTEN/NOTIFY on PostgreSQL. You could then just add data to a table, then have the forms application consume the data. This would have the added benefit that your forms app wouldn't have to miss any data if it was not on.
My opinion to you is to implement a webservice. I made a project for mobile devices using webservices, the mobiles had an application made in winforms that call a webmethod that made an action which was registered in the system. A web page showed the data and the events of every mobile device.
If you need an explantation of webservices you can go here.
The strategy in your case would be to implement the Observer Pattern or to raise an event to make the application or winform to be noticed about a change or action in the web page.

Audit and log, all or selective, user input on ASP.NET web application. How would you?

I'm building UI logging into a long-existing ASP.NET enterprise application. I have my own ideas of how to progress from here and am continuing to research & design. But I'd love to hear some details from the SO community.
Here are the details, assumptions and questions as of right now, subject to evolve within the enterprise as well as whatever input comes in here on SO:
Would prefer to have a consistent DB connection since there will be a lot of activity
Will probably use the ThreadPool, but will this conflict too much with ASP.NET vying for threads?
Possibly use in-memory queue (Queue) for logging batches of inputs periodically? (one per domain)
Will need to be configurable. IE: Could log all page events during their normal postback calls, or hook individual control actions or events to being logged whether there's a postback or not. IE: User collapses a panel.
All "high-visibility" UI events that'll already be posting back as well as other events that won't necessarilly post back right away. Have a client batch of events and send occasionally?
How do we minimize the impact on existing code?
Have "fly on the wall" AJAX functionality that posts back accordingly? It'll basically be watching all that's been configured to be logged.
Logging must be ordered for reporting a user's step-by-step progress from point A to B in a workflow.
How about a WCF service that does the actual logging, paired with a PostSharp attribute. In your PostSharp attribute you can call asynchronously to you WCF service while your application hums along. I've implemented something like this in past projects and it works great with little if no slowing down.
http://www.postsharp.org/
Why not use log4net? You could capture a userid, sessionid, and any additional information you need to track step-by-step progress. You could configure the levels so that you could reduce the logging if it impacted performance. I wouldn't consider re-inventing the wheel by writing your own framework when there are several viable existing logging frameworks.

Communication between pages

I want to enable an user to be able to communicate with other users through a site. I know that ASP.net is stateless, but what can I use for this synced communication? Java servlets?
I don't think you need to set up Java just to use a servlet for this. I would use AJAX and the database. I don't know ASP.NET but I PHP is similar in this case, being also basically "stateless". If you want to display some kind of asynchronous communication between two different users, say, from two different sessions, without a lot of refreshing (like chat), you can have the AJAX page constantly poll the database for new messages, and display them when they come in. You can also use AJAX to insert the new messages, giving the user read/write access to this messages data structure. Since the "other" user is doing the same thing, user A should see new messages pop up when user B types them in.
Is that what you mean?
You probably don't want to use sessions for things like chat messages but you probably could use some type of implementation of queueing using MSMQ.
The approach to chat could be done in many different ways, this is just a suggesting off the top of my head.
Could do a messaging solution in Java Servlets using the application context. Objects stored as attributes in the application context are visible from anywhere in your webapp.
Update: Chat like functionality... I guess that would be AJAX polling your message structure stored in the app context unless you want to use something like applets.
Don't know if it's any good, but there's a chat servlet here that might be useful to use or learn from if you decide to go the Java route...
ASP.NET is "stateless" but it maintains state using Sessions. You can use them by default just using the Session[] keyword.
Look at ASP.NET Session State for some details from Microsoft.

Resources