Asp.Net MVC and HTML5 PUSH notification - asp.net-mvc

I would like to have server side event in a full HTML5 application.
Server side I've an asp.net MVC3 web server, which gives HTML pages and JSON results.
What is the best way to integrate some server event? Like a process which can send some text message to client?
I've made some search and found something about a Asp.Net web api, but I don't know what it is and if I can use it with MVC.

You should have a look at http://signalr.net/ library. This blog post is also very informative.

SignalR looks very interesting, but maybe more than you really need. I've often wondered why people don't use Server-Sent Events more often, I haven't had the chance, but it looks like the simplest way of implementing.
Here is an example in MVC if you want to review: http://blogs.microsoft.co.il/blogs/gilf/archive/2012/04/10/using-html5-server-sent-events-with-json-and-asp-net-mvc.aspx

Related

Analyzing the Web API Traffic

I have custom Web API been hosted and exposed. I want to know how to get details like who accessed my Web API, time of accessing,etc. In short I just want to know my Web API usage history.
Can it be possible? If so, can you please help me in this context for where to look and so?
Thanks
You can use System.Net.Http.DelegatingHandler to accomplish logging. As a start, have a look at the following blogs:
Log message Request and Response in ASP.NET WebAPI.
ASP.NET Web Api–Request/Response/Usage Logging
and this for an alternative using an ActionFilter
Implementing Audit Trails using ASP.NET MVC ActionFilters

ASP.NET MVC API or WCF API

I'm developing an ASP.NET MVC 3 application. I need this application to make use of an API I also need to implement. The API should both be available from ASP.NET MVC controller actions and Ajax. Now it is quite easy to make an API using ASP.NET MVC, but is it possible to use this from other ASP.NET MVC website actions? I guess the WCF is quite easy to use as it is just a service reference.
Other users of the API could be Windows Phone and iPhone.
Update:
Many only sees the API as a place where you consume data, but what about the part where you want to execute commands or do stuff, like add customer or change foo?
You may want to check our new WCF web API that was announced at PDC. We recently released a big upgrade. WCF Web API is designed specifically for allowing you to expose APIs to a range of clients in a pure HTTP manner. It is lightweight, offers a nice configuration story (no configuration files) and also is much easier to test.
You can download the bits at wcf.codeplex.com. It includes various samples, and there is also a set of NuGet packs for getting you started. Search for webapi.all on NuGet.
The way I like to do this is with RESTful controller actions. You can return JSON and use your calls with JavaScript on your own site. Other websites would almost certainly understand JSON and so they'd be able to consume your API pretty easily. This is much easier to write and test than a heavy WCF layer.
Check out this question for some example REST frameworks for MVC:
ASP.NET MVC REST frameworks
One of the newer ways of accomplishing data feeds is using OData. Scott Hanselman has a great introduction to it in Creating an OData API for StackOverflow including XML and JSON in 30 minutes.
It allows you to even throw LINQ queries into your URLs to retrieve exactly the data you need.
Open Data Protocol (Official site)
Open Data Protocol (MSDN, Microsoft)
WCF JSON binding was really terrible last time I used it. WCF also comes with all sorts of crazy rules about streams and how you have to use [MessageBody] attributes for everything.
It was a real PITA to me.
I knew I've answered something like this before:
What is the best way to implement a RESTful architecture in .NET today?

How can I integrate "chat" into an ASP.NET MVC site?

I'd like to integrate chat into my site and am open to a solution like this site's, but am open to others if they exist.
What chat sites do you know of that can integrate into an MVC site?
I have used both the WebSync JavaScript and Silverlight API's.
In your case you could use the JavaScript API from an MVC app.
Creating chat with WebSync is really easy and works very well. WebSync is a highly scalable HTTP Comet/Reverse Ajax server. They even offer a offer a hosted service. It has a cost if you need to support more than 10 concurrent users.
Here's one project on CodePlex you might take a look at.

How to use SOAP in asp.net mvc

A 3rd party site sends its notifications after my web application has completed some action in order to notify me of its success. Receiving a notification item requires a response back to the 3rd party server (URL) with the a containing the value "accepted".
I have never user SOAP and with the basic info found I'm a bit lost for the case of asp.net mvc. Are there any good links showing the principle of receiving and sending SOAP responses?
Tutorials / information may be presented in other languages such as java, asp.net (classic) or something. I need to get a general idea since googling on SOAP has not given me anything for the past few hours.
You need to learn a little about WCF. See the WCF Developer Center, especially the Beginners Guide.
What you want is to create a simple WCF service that corresponds to the WSDL that they will give you. You will need to implement only the operation (method) that they will call to notify you. You can host a WCF service in IIS along with the rest of your application.
The issue will be how to correlate the notifications with the page you're on in your MVC application.
I don't think this is specific to ASP.NET MVC really. If you have a WSDL for their web service, just use that to generate stub classes using either wsdl.exe or by adding a web reference to your project, then call the web service from your controller.
If I remember correctly SOAP is basically xml requests and responses.
You might want to look into WSDL (Web Service Definition Language) to avoid having to deal with raw data, and you would likely find a great deal of tutorials on wsdl as well.

How to allow authorization to an rss feed using ASP.NET MVC?

Our shop is in the process of converting our internal project management application from ASP.NET Web Forms to ASP.NET MVC.
I would like to provide an RSS feed for our customers of their current open issues ... but I would like to do so with some type of authorization, e.g. login and a password.
Is this possible using ASP.NET MVC or should this be done through some other service like WCF? Sample code would be much appreciated.
I'm not sure of the best way, but can think of a few, none are super great though.
Use IIS WindowsAuthentication with basic security and implement the validation method and then mark the RSS action with an authorize filter. If they are using an RSS feeder that doesn't allow http authentication, you should still be able to do http://username:password#mysite.com/controller/action/rss.
Generate a token for each customer and place it in part of the url: http://mysite.com/controller/action/rss/{token}. This isn't that great.
Put the username/password as part of the route: http://mysite.com/controller/action/rss/{username}/{password} ... this is pretty horrible though.
All of them kinda suck because the password (or token) is url visible. Maybe that is considered okay if it is https instead of http though. I think the first option + https is pretty common though?
If private feeds are part of the RSS spec, you should look there for the mechanics of RSS auth.
I've thought about this before for a project and came to the conclusion that secure RSS will never work because not enough clients (e.g. google reader) support it.
Sorry, don't have a complete answer, but thought this might help anyway.

Resources