I'm developing a website in C# MVC including WEB API. When an API URL in my project is called from an external system, I want to show a message (not a push message, only show a text in a div) in one of my view that the API function is executing.Is this possible?
First Of All its possible yes,
you need To use SignalR To notify the Views:
YouTube totrual Here
Github : Here
Then You use the Signal R to push a Notification when a cross origin request happen
using action filters
the signalR subscribers can be view pages using Jquery.
SignalR on Client
full exmaple :here
Yes it is posssible. One (pretty easy) way is to use the awesome SignalR or SignalR core framework. Check this for differences. Real-time web functionality enables server-side code to push content to clients instantly.
Basically you will create a Hub on the server that clients connect to. In your WebApi method, you can then call the client method. Then in the client you will use javascript to respond to the server call and then you will set the div content from this method.
See the docs.
Hope it helps!
I think Signal R is best choise too. But maybe you want to another alternative. You can look at Node Js.
Node js.org
General Tutorial
General Tutorial 2
For .NET Tutorial
I have a web application built upon Angular 5 and asp.net. My use case is that I need a demo version of this application which must have same UI interface/ Front-end logic but the data/response coming through web api's should change(Data being very confidential so this demo version is intended not to show that data).
I have lots of routes and around 40-50 api's from where data is received. Now, how can I change or jumble all of this data so that original data is not shown to user.
Till now I tried solving it using Angular interceptor, that is to intercept each response and then changing JSON values to something vague. As far as I can understand, I need a layer which can handle all responses and change those response to dummy data. Is this the right approach or we should handle it at back-end using asp.net?
I have read many articles in the web so far, about the differences between WCF and ASP.Net web API. Unfortunately I could not come up to a clear idea about what will serve my purpose. Most of the Articles I have read highlighted on the design point of view of the two web services. But I am confused what will work best for my project and why? Here is my brief description of the project.
I need to create a communication channel between two servers (both are written in C#). The servers will communicate using messages (certain type of commands). The messages sometimes can be only acknowledgements, and sometimes the messages may contain instructions to do some computation. For example, one message can be draw something, or send an SMS etc. And not necessarily the messages will involve any database transactions. But the messages can sometimes send large text files as payload (around 1-5 MB maxm). What I believe WCF is very will surely do this, but can I do the same with ASP.net web API. Because so far all the example I have seen for ASP.Net web api: they are good for RESTful services that manipulate some kind of DB store (GET, PUT, DELETE). But in my case I will need to expose service points that will
do some kind of processing such as return the value of a computation, sending and acknowledging messages, etc.
Not just manipulating a DB-store.
So, what should be the best and simplest way to do so? It is needed to be mentioned that I did not find any straight forward example of achieving this using ASP.Net web API.
The Question you have asked is an overly-broad or primarily opinion-based, and its hard to give an example for what you have asked.
Important Points:
Firstly, if you are going to create a service which would be used on different platforms, then go with WCF.
Secondly, if you are creating internet service which is going to use external resource, then go with Web API.
Web API is the best choice if you are going to create a service for low bandwidth devices or mobile devices to access client.HTTP
request/response is also more readable as compared to SOAP because it
contains header, body, etc. which makes it complex.
Just take few minutes and read the below article, until you get complete understanding of few principles.
Original Source Can be found Here, Here and Here.
To whom choose between WCF or WEB API :
Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.
Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.
Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).
Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets.
Why to choose Web API
Web API doesn't have tedious and extensive configuration like WCF REST service.
It is very simple, creating service with Web API. Where as With WCF REST, service creation is bit difficult (requires clear understanding of configurations).
Web API is only based on HTTP and HTTPS and easy to define, expose and consume in a REST-full way.
Web API is light weight architecture and good for devices which have limited bandwidth like smart phones.
My Opinion:
Simplest way to do so - Web API (Since you dont have any examples for this)
Hardest Way is (Configurations) - WCF (Better go with WCF, since you have examples)
I hope this gives you a clear idea about what to choose...
First things first, RESTful is a stateless and uniform interface norm that can be applied to web services. It doesn't have to be automatically and only plain old CRUD service backed by a DB.
In the real world, we can hardly say that all web REST API respect fully the norm, in fact they don't most of the time, especially the stateless part.
For your message based API, especially if it's bidirectional and event based, you can use websockets and consider the REST API a way to expose an uniform, stateless web interface to create those. And yes you can use websockets with ASP.NET WebApi there's plenty of tutorial out there, even for the newer ASP.NET Core.
The "between services" interactions part is no different than the usual Web browser <=> Web service, you're just using C# code instead of JS for the client.
I can hardly recommend WCF that uses SOAP since it's hardly portable considering the web standards nowadays. For instance if want to use a browser client instead of another ASP.NET service, well you'll have to do additional code client side to handle supports.
You can use WCF websockets, providing the almost all the advantages of WCF SOAP.
tl;dr :
You can mix RESTful and Websockets, it can actually be better than going full REST or full Websockets
It's personal preference to use SOAP over websockets but do comes with a potential technical debt considering what you want to do afterwards
Message API between services is no different than a message API between a service and a browser
WebAPI is not just good for RESTful webservices. You can easily send requests to a WebAPI controller and handle it the way you want : calculations, sending messages, interact with a CRM, interact with DB or anything else.
WCF was created to manage SOAP based webservices and brings extra complexity. It handles TCP, Mime...
If you just need to handle HTTP requests, the simplest way is to go with WebAPI.
I would suggest Web API if it is for RESTful services as WCF was never made to serve as Restful services although you can serve as one where as Web API was made particularly for this.
I am currently developing an IRCX AJAX Chat based system and have a few questions regarding the Server and Client implementation; Any suggestions are welcome:
Server
Should this be implemented as a Web Service, or a Windows Form application? I have experience in developing Windows Forms based servers, however I am wondering if this would be better implemented as a Web Service and if so, why?
Client
How are Web Based Clients implemented today and what is the preferred method to implement a Web Based Client?
My solution so far are
ASP.NET Web Forms with an AJAX Update Panel (This seems the most viable)
Using jQuery connecting to the web service with a JavaScript timeout
Polling
How frequently should the server be polled for new messages? 0.5 seconds seems a bit excessive and anything between 2 or 3 seconds seems sluggish.
Thanks for your input.
Have a pool of connections and maintain a sort of proxy between the server and clients that sends the data to the right client based on a session id. This would mean your chat server is protected against packet attacks and you would not have to deal with web sockets which an attacker could hijack and do what they require with it.
I know the question is old, but there's an even better approach now.
SignalR is designed for things like this (real time web functionality)
SignalR can be used to add any sort of "real-time" web functionality to your ASP.NET application. While chat is often used as an example, you can do a whole lot more. Any time a user refreshes a web page to see new data, or the page implements Ajax long polling to retrieve new data, is candidate for using SignalR.
Here's a tutorial for a basic chat application HERE.
For more information, visit the SignalR website.
I believe using ASP.NET (Sockets and an Update Panel) seems to be the best approach. Using jQuery in this context now seems a bit invalid because it would not maintain a persistent state with the Chat Server which is required for Real Time Communication.
An alternative way I found would be using a Web Sockets and Backbone.JS to deal with the data returned from the server.
http://blog.fogcreek.com/the-trello-tech-stack/
I thought I would ask about this here. Does anyone know of any work being done with regards to a 'MVP' design pattern involving push-based data transfer (not to be confused with Model-View-Presenter)?
I'd call it Model-View-Publisher, or perhaps Model-Subscriber-Publisher where a Subscriber is analogous to a View and a Publisher is analogous to a controller.
The idea is here is that instead of your typical controller that responds to client requests, you have a 'Publisher' which pushes data to client 'Subscribers' when some event occurs. The push would be via long polling / reverse ajax / comet or some other similar method.
Do any frameworks such as this exist, and if not, would it be a useful pattern? I'd be specifically interested in implementations in C# / Javascript on the client or maybe NodeJS on the back-end.
Alternatively, are there any MVC frameworks or implementations that provide controllers which push data to the client using technologies such as Comet?
I imagine support for web sockets will be coming soon. See Websockets with ASP.NET MVC / MVVM for current web socket support