How to Angular.js controller from C# - c#

I have Windows service written in C# that basically acts as a timer to fire an event. When the service fires I need to call a Angular.js controller passing variable(s) and receive a PDF file back as the response. I'm new to Angular so any help would be appreciated.

Angular lives on the client side in the web browser (well, typically anyway) so if you want to communicate to it from your C# service you need to find a way to send and receive information between your server (running the service) and the client browser.
How you can go about this depends on your project's needs, but for timed events you're probably best off using websockets to perform this communication. If you're working in C# you might want to check out SignalR for your backend.

Related

ASP.NET Core REST API call throught WebSockets

Recently I talked with some developers, and they said that they call one endpoint from their front-end (web app) and that endpoint is a web socket. All their REST calls go through this connection. This solution was in Java. So I started wondering how they do that. How they dispatch the endpoint, what is the payload, etc. but in Asp.NET Core.
I am wondering is it possible and how.
I see this is very interesting topic. I found this useful- https://developer.okta.com/blog/2019/11/21/csharp-websockets-tutorial
You can do this in dotnet core using SignalR: https://learn.microsoft.com/en-us/aspnet/core/signalr/introduction?view=aspnetcore-5.0
I think you're mixing two different technologies.
A REST endpoint belongs to WebServices and is an url, pointing to one or more methods in your code that can accept parameters and return results in XML/JSON format.
You can then fetch this url from your front-end and read the response.
An example of REST webservice is Google Maps API.
A Websocket, instead, is a continuous connection and works as a plain socket but between a webpage running on a client and another server application on another machine (i.e. the server).
It's used when you need an open tunnel with continuous exchange of data: chats, video and audio streaming, multiplayer games and more.
You cannot make a REST call to a websocket endpoint and if you want to use websockets you must write a server in C# (i use .net core). A console application.
I'm unsure what you are looking for exactly. If you want to start with websockets, this is where i started from:
Writing websocket server
Writing a websocket server in C#
For webservices:
Writing a web service in ASP.NET

communication between the website and C# winforms application

We have a Website (hosted somewhere) and C# Application (which is installed on my PC). I need to accomplish the following:
Customers fill up the form on the website, i.e. the task is "created"
C# Application immediately receives this data from the website and process it
The result is sent back to the server, i.e. "task accomplished" message
The website updates status regarding this task
How do you build this kind of link between the website and an app?
In the past I've used TCPListener to communicate between two C# apps. I'm also familiar with the UDPlistener and such.. Will this knowledge be of some use? The website is going to be build on the PHP.
Some tips and advises are appreciated. Thanks.
Your website should not be dependant on an application running on your home or office PC, so the site should publish some kind of service or feed. You can make this a webservice, which is quite easy in PHP.
You then consume this service from your C# application. Make it request the new tasks regularly, by polling the service. When you've received new tasks you process them in your application, and when you've done what you want to do you update the tasks on your server using another webservice call.
All this can be done using some sort of queue in the database that backs your website.
Make the C# application a web service may be a windows host depending on your requirement
you can the webservice from php as shown here Using PHP to call a WCF web service with multiple bindings
If you have the control over your web host and your client, you could try setting up a WCF service with duplex contracts which allows the server to callback your client. Your PHP site can call the WCF service and it can in turn notify the client. Else you will have to go with the polling method where the Desktop client has to poll the web service to get the list of pending tasks.

Using WCF Contracts to operate WPF Client

I'm trying to give functionality to the user where they can remotely control the client on their system from a mobile device or laptop.
What I have created is a WCF Console application which holds the contracts etc. and starts the server.
Now here's the thing, if I create a HTML page I can't do anything with it to make it communicate with the server and then the client as I'll need the HTML page to make call a method on my WPF client to initiate an action.
Has anyone had any experience with this, I think almost there with my solution it's just this wall that I've hit.
Thanks
If your looking for a way to call WCF server functions from a webpage then use Ajax enabled WCF service. Read here: http://www.codeproject.com/Articles/33234/A-beginner-s-guide-for-consuming-a-WCF-service-in

Handling events in a Windows application

I have a mobile applciation thats interacts with a server. The mobile application should be allowed to do a http posting to the server.
The server should be able to handle the event and display out using a custom windows .net application on the server almost immediately based on event.
So what are the right ways to do it?
Is there any event handling that works on c#.net that can be applied on the above scenario?
So far i only thought of msmq event handling. The mobile app does a http post on the server, the server creates a msmq on the server side and the windows applications listens for the new msmq message.
If you must use HTTP post then you could write your own web server in C# and add handling for specific requests from your mobile device.
This project outlines how to create a web server in C#. Inside of the StartListen() function you can check for your target message instead of "GET". Alternatively you could use the functionality from this open source project: http://webserver.codeplex.com/ and hook the appropriate HTTPListener functionality.
The real thing to understand here is that the "web server" is really just a thread that is listening for a specific data stream on a socket. You could easily adapt simple socket send / receive code like this to implement your functionality.

is it possible to make an Asp.net IRC client?

I want to build a web-based irc client with JQuery. I know I need to open a socket to the irc server. What I'm wondering is, is it possible to open a socket purely from server-side C# code? Or would the nature of a web application prevent this and I would have to write a service to run on the host machine?
Thanks for any help :)
Yes, you should be able to make a socket connection from server-side ASP.NET code. On the other hand, given that you'd presumably want a persistent connection to the IRC server (rather than a new one on every request), you may want to write a separate service anyway - you don't want ASP.NET recycling to kick in and wipe all your context, for example.
Your ASP.NET code could then talk to your service to find out what had happened since the last request for that user, etc.
One simple approach would be to setup a singleton WCF service which acts as the bridge to IRC. jQuery AJAX calls against that service could then post messages that were input by the user, as well as retrieve messages sent by other users.
I have implement the chat with ASP.Net by using the SingnalR for duplex communication.
What I really done consist on the following steps.
1) ChatHub.cs
I have write down all the logic to connect with the IRC server and connect to the channels, receive different messages and notification from the IRC server. I then send these notifications to my ChatHub client by calling the javascript call backs from the ChatHub.cs
2) Client.aspx
Simple HTML page and it is using jquery to register the callbacks from the ChatHub.cs
3) IRCDotNet.dll
I have used this library to communicate with the IRC Server.
Hope, It will help somebody. Here is the link to download the IRCDotNet.dll
http://ircdotnet.codeplex.com/releases/view/50639

Categories

Resources