MVC show notification to user when event happens on server - asp.net-mvc

i've got a situtation where we have a web site (mvc project), and a wcf service, when service gets message i need to show a notification to user who's on the web site with this message contents.
would be glad if you can show me the place where to start!
Thank You !

You probably need some javascript on your page that polls the server at a certain interval to check if there is something to show to the user.
Here is a nice article on how to create a WCF service and call it from the browser using JQuery

I think you need to place javascript timer on your page which will do ajax for example: "/Messages/GetLastUnreadMessage".

You'll need to have a bit of javascript that makes an AJAX call back to your site from the client page on a regular basis that checks to see if there are new messages, and displays them if there are.
There's no way for your web server to 'notify' an already rendered client page in the other direction (providing I understand your requirement correctly).

Related

HTTP Redirect on a browser without showing intermediate window

I have two servers someserver.com and anotherserver.com
What I need is when a user clicks on someserver.com he or she will be redirected to anotherserver.com
Currently when I do a redirect programatically on the server (ASP.NET MVC IIS)
what a user see is: 1) someserver.com is loaded 2)anotherserver.com is loaded.
What i want is when a user clicks on someserver.com he sees only anotherserver.com in his browser.
Does http protocol allow it?
Thanks!
There are a bunch of approaches to this but the simplest one of you own the domain is to just use domain forwarding st the dns level. Then it won't involve your web server at all. Otherwise, the browser will always have to load the first site, if only briefly, before loading the second one. You can optimize this by just sending a redirect, which should be barely noticeable. Another option would be client-side JavaScript, but if you know on the client that you want to go to the new URL, you could just use a standard hyperlink to it at that point (so I assume this is not an option).

MVC.NET: How to update UI on event trigger in backend ?

I want to update the browser UI on the event at controller level, such as some service is updating the database and if database gets updates then, user should get notified about it.
I don't want that browser should keep pinging to server after some seconds.
If you can share some link of working example it'll be helpful.
I read about SignalR but not sure how to use it.
Thanks
options:
1. you can write a javascript script to roll polling a mvc action.
2. you can use SignalR ,to send a message from backend with websocket http://www.asp.net/signalr

What is the best way to send progress information from WCF to the browser?

I have an MVC application using Razor, html5 and a WCF service. The problem is one WCF service takes a long time to run which means that the user has no indication what the service is doing. I would like to send progress information to the HTML5 client and would like some suggestions over what the best approach would be. All help will be gratefully received…
You could even use SignalR for the Reverse Ajax purpose. If you want to shy away from these heavy framework, and probably want to go with setInterval you can check out this article This article is by Dino Espito, in which talks about how to use setInterval to make repetitive call to server to get the progress. Another one by Dino Espito in which he uses SignalR libarary to make a context sensitive progress bar
For Full Collection of his article on Context Sensitive Progress Bar See here
You have to go for Comet implementation. In the case of Comet or Reverse Ajax the client will send a long duration ajax call to the server and wait for a response. So in your case first the HTML5 client will send a request to the server and wait for the progress information once the WCF service returns some info back the client has to make the again make the long duration call till the process is completed.
There are open-sources available that helps to simplify your work like nComet or PokeIn.
There is also an article available in code project that talks about this approach.

Invoke controller action from a web service

I have an ASP.NET MVC application presenting some data and I want it to
open a new tab, or
redirect to a new view
when a web service gives me a signal. This WS is supposed to handle some external data and requests and when some specific action is called, I want it to be able to give my web application some kind of signal.
I was thinking about using Html.Action to an asynch controller but then I don't know how to provide the signal from the WS to the controller (or all instances of them).
Hopefully, it is understandable. Do you have an idea what needs to be done?
Thanks in advance.
So basically your problem comes down to the fact that server state is changed (through WS) and we want to make something happen at the client side where the your web app is being viewed.
Frankly it's not straightforward. Internet works on the Client -> Server architecture. User sends a request to the server, server responds. What you are trying to do is reverse of it. You want to send a request from server to user. HTTP protocol doesn't work like that.
Right now, to do something similar following two strategies are used:
Websockets : try searching them on google. You create a socket between the client and server and once server gets updated by the WS, it sends a request to the client through the socket. You can ask it to navigate to a different view or open a new window. The downside with it is that its not supported by the majority of the browsers. Might take a year or so to be. Not really recommend now.
Polling : You can make Ajax requests from your browser to server in certain intervals (you know like every 5 seconds) and see if the server state has changed or now. If yes, then do your stuff. That's the most common technique. Twitter.com uses it. There is also another version of it called Comet or Long Polling but I won't confuse you with that.
The important thing to note here is that whatever you want to do (open tab, change view etc) you have to do it through Javascript at the client side.
hope that helps

How to pass data from a web page to an application?

Trying to figure out a way where I can pass some data/fields from a web page back into my application. This needs to works on Windows/Linux/Mac so I can't use a DLL or ActiveX. Any ideas?
Here's the flow:
1. Application gathers some data and then sends it to a web page using POST that is either imbedded in the app or pops up a new IE window.
2. The web page does some services and then needs to relay the results back to the application.
The only way to do this that I can think of is writing the results locally from the page in a cookie or something like that and have the application monitor for a specific file in that folder.
Alternatively, make a web service that the application hits after passing control to the page and when the page is done the web service will return the data. This sounds like it might have some performance drawbacks.
Can anyone suggest any better solutions for this?
Thanks
My suggestion:
Break the processing logic out of the Web Page into a seperate assembly. You can then create a Web Service that handles all of the processing without needing to pass control over to a page.
Your application can then call the Web Service directly and then serialize the results and work with the data quite easily.
Update
Since the page is supplied by a third party, you obviously can't break anything out. The next best thing would be to handle the entire web request internal to your application (rather than popping a new Window).
With this method, you can get the raw HTTP response (and page markup) and work with it directly. You can then parse the Response stream and gather the required data from it.
During performing an HTTP request you should be able to retrieve the text returned by the page. For instance, if your HTTP POST was to hit a Java servlet, the doPost() method would be fired and you would then perform your actions, you could then use the PrintWriter object from the Response object (PrintWriter out = response.getWriter();) and write text back to the calling application. I'm not sure this helps?
The fact that
web page is hosted by a third party
and they need to be doing the
processing on their servers.
is important to this question.
I like your idea of having the app call a webservice after it passes the data to the third-paty web page. You can always call the webservice asynchronously if you're worried about blocking your application while waiting for results from this webservice.
Another option is that your application implements an XML-RPC server that can be called from the web page using PHP, Python or whatever you use to build the website
A REST server will do the job also...

Resources