Comet hints using .Net - javascript

I have a web site showing some data. It is constructed of:
- A web app, showing data.(ASP.Net app, but I don't use server side features in showing data; It's pure HTML and JavaScript)
- A Service providing data in Json format.(WCF)
the client requests data and receives and shows them.
Now I want to change the process in order to works in push base strategy.
I googled and I found out that that Comet is a good choice, but I don't found practical samples in my case.
Some samples had client with php (server-side) and so on.
Now I want some hints on using comet in a way that client is pure JavaScript and HTML and server is WCF (server pushes Json to JavaScript )

look at nComet it is an asp.net implementation of comet, not sure if it is wcf yet, but i would have thought much of the code would be reusable.
Or better pokein

Related

Is there any way to send http requests from JS by pushing button, to a C++

I am currently designing a GUI for a piece of hardware. We want the GUI to be able to be accessed over a browser. The browser would be displaying a map generated from C++ code, but I also need to send some params to the code that generates the map from buttons on the JS front end? Is there anyway to accomplish this. I have done a little research so far and know about web sockets and AJAX, but I am not entirely sure it is what I am looking for. In an ideal world I would be able to just send UDP packets, but my research tells me that is not possible, not is TCP. Is this correct?
Thank's in advance for any help!
Your C++ code could setup a server that listens for requests. You could use libhttpserver, for example. Then, in your JavaScript code, you can use XMLHttpRequest or the Fetch API (for newer browsers) to make an HTTP request to the server, which would then return a new static page (with the generated map embedded into the page).

REST Client: java backend consumer vs java script consumer

I want to generate webApp in java and just use some REST service. I think there are two approach for this:
1- Client side consumer: With an simple app that contain some java script file which call service and then generate UI from result.
2- Server side consumer: In backend first call service(with spring RestTemplate) then generate appropriate UI and send HTML ui to client.
Which approach is recommended?
I know this question is very general but I want to know advantage and disadvantage of those.
Client side consumer approach is the better one as tomorrow if you have one more client application who requires the same data but will be displaying it in a different way then client side consumer approach will benefit you. For eg: suppose the consumer today is a web page then you can get the data from backend and display it on your webpage, but tomorrow if your business grows and you plan for a mobile app then in that case your same rest api will come in handy for you.

How to Stream data from WebAPI method to a JavaScript client

I have a service method written in ASP.Net WebAPI :http://diningphilospher.azurewebsites.net/api/dining?i=12
and JavaScript client gets the response and visualizes it here
But the nature of Dining Philosophers problem is I never know when the Dead-lock or starvation will happen. So Instead of having a request/response I would like to stream the data through service method and client side JavaScript read the data I assume JSON asynchronously. Currently several post directs me towards changing the default buffer limit in WebAPI so you get a streaming like behavior.
what other(easy or efficient) ways exist to achieve this above behavior.
You can return PushStreamContent from ASP.NET Web API and use Server Sent Events (SSE) JavaScript API on the client side. Check out Push Content section in Henrik's blog. Also, see Strathweb. One thing I'm not sure about the latter implementation is the use of ConcurrentQueue. Henrik's implementation uses ConcurrentDictionary and that allows you to remove the StreamWriter object from the dictionary corresponding to the clients who drop out, which will be difficult to implement using ConcurrentQueue, in my opinion.
Also, Strathweb implementation uses KO. If you don't like to use KO, you don't have to. SSE JavaScript APIs have nothing to do with KO.
BTW, SSE is not supported in IE 9 or lesser.
Another thing to consider is the scale out option. Load balancing will be problematic, in the sense there is a chance that the load will not be uniformly distributed, since clients are tied to the server (or web role) they hit first.

Call a SOAP Service using JavaScript

As the title suggests, I'm trying to figure out how to call a soap service using JavaScript. The SOAP Service is being run on Tomcat on my local machine. Along with accessing the SOAP service, I can also download/access/read the WSDL very easily.
I've been hitting my head against the wall for days now with this problem. While researching, I'm come across short examples, but none are comprehensive and detail how to accomplish this from start to end. That, or I've found a solution but it only works for IE or Mozilla.
Any ideas how to call a SOAP web service using Javascript (on major browsers)? Thanks!
(PS: I'm also using jquery. So if you want to accomplish this using some slick jquery tool, please feel free to suggest it)
SOAP is just XML so it should be possible to do this, however I'm not aware of any existing SOAP Clients written in JS
A more common method would probably be:
JavaScript initiates an XHR object which calls to a server-side AJAX helper using either GET/POST parameters, or a JSON encoded object
AJAX helper makes the call to either a Database or Web Service, as appropriate, and outputs required data object(s) as either JSON or XML
JavaScript parses response body (JSON or XML) and takes required action using specified data.
This has a couple of advantages over trying to call WebServices directly from JavaScript:
SOAP XML can be quite complex, which means more data to transfer to and from the client, which may be a slow connection. JSON in particular, but also an XML schema that just has the required data would be a much more economical on data usage
If the WebService requires any kind of authentication the authentication details will be exposed to all visitors.
Web Services are generally used for to standardise communications between separate systems, rather than for communication between the front and back end components of the same Application/Site.

Connecting C++ backend to Javascript

I was hoping to make a website that displays a google map with points based of information returned by a C++ function. I know you can use Java Server Pages to call java methods on the server with javascript. Would there be a way to connect C++ code on the server with javascript in order to produce the same result as java server pages?
Since JavaScript runs at a completely different environment which is separated from the webserver by a HTTP connection, your best bet is to fire a HTTP request to the server side on a specific URL which has the particular C++ code attached.
You can fire asynchronous HTTP requests in JavaScript using XMLHttpRequest, the core technique behind "Ajax". The w3schools provides a concise introduction to Ajax. To make it all less verbose and bloated, you may consider to grab the jQuery library which has under each an $.ajax function for this purpose.
That said, Java Server Pages is absolutely not to be compared with JavaScript. JSP is a Java based server side view technology which provides a template to write HTML/CSS/JS in and offers capabilities to control the page flow dynamically and interact with backend Java code using taglibs and expression language. It runs all on the server machine, produces a HTML page and sends it over HTTP to the client side. The C++/C#/NET counterpart of JSP is ASP.

Categories