Convert REST API to websocket client - c#

I have existing C# web api, I want to convert it into websocket base API.
Where user can subscribe to the end point and then I can post data to user from some other service.
How can I implement this? Any guidlines will be great help.
I have tried doing it with websocket handler but it just send data by making call inside the controller method. I want to be able to push data from other service once the user subscribed to the websocket API end point.

ok, I created websoket hub and then added authorization on it where needed. Works fine as per what I wanted.
still if anyone has better solution, please suggest.

Related

Get notification in view when a web API called from an external system in c# MVC

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

Sending data to Azure Events Hub from an external API REST

Like this topic : https://stackoverflow.com/questions/32843290/implementing-iot-powerbi-table-schema/32844087#32844087, I would like to retrieve data from an API REST to create a dashboard which will refresh in real time the data taken from the API.
In order to do that, I have to go through Azure Events Hubs to get the data taken from the API. I have troubles dealing with how to retrieve the data from the API to put it in the entry point of Azure Events Hub. I know I have to write a program (preferably by using Visual Studio) and make this program retrieve the data from the API and put it in the Event Hub but I have difficulties to see how I should begin. What kind of program and what I would need.
I tried to find some tutorial/codes about this but couldn't find anything about retrieving from external API.
From what I can understand, I need to write a program that connects to the Events Hub (not difficult), retrieve the data of the API, store it in a variable created and send it to Events Hub. I would like a bit help on how to start, where to start, what classes for example I would need etc...
I am not an expert on API at all, but I have some knowledge. For information this is the website from which I am trying to retrieve data from : https://data.sncf.com/api/en. The use of the API allows us to retrieve information in a json format if I am correct and I will have to save this data to store it in a variable ?
Thank you.
Per my understanding, I assumed that you could try to follow the steps below to achieve your purpose.
1.Use Azure WebJobs to call your API periodically, then send the data retrieved from the API to Azure EventHub;
You could follow this tutorial for getting started with WebJob by using VS. Also, you could follow this thread for making calls to a REST API via C#. For a simple way, you could leverage EventHub bindings supported by azure-webjobs-sdk to send messages to an event hub after you retrieved data from REST API.
2.For your client-side, you could follow the official tutorial to receive messages from EventHub via EventProcessorHost.

Receiving webhook from GitHub from C# Console App

I'd like to capture webhooks from GitHub (for various events, like commits, etc), from my C# console application. I figured I could "listen" to an endpoint and webhooks would be thrown there, but it seems that perhaps github is actually sending webhooks to endpoints that you need to setup and listen from.
If the latter is this case, then I suppose I'll need to setup a web server to capture the webhooks. If the former is the case, then I'm not finding in the docs how I can listen for webhooks from GitHub?
Your question isn't very clear, but I think you're on the right track vis-a-vis implementing a web server. So, my answer to your question is: you need to implement a web server to receive the webhook requests.
Edit
At the bottom of this document, you will find instructions on how to implement a very simple web server (in Ruby) to receive GitLab webhook requests. I know this isn't a turnkey solution for you, but hopefully it will help get you going.

How to implement a Webhook listener using c#?

I want to implement a web listener to grab the posted array data from the webhook url.
I have came across two ways to do this.
1. using IHttpHandler to handle the http request.
2. using wcf rest webservice to grab the request.
I also found that this can be done using a HttpListener but was unable to find a proper sample implementation.
Can anyone suggest the best way to do the above task and provide some references where I use to start the implementation.
Thank you.
A webhook URL is not different than any other incoming HTTP request that you receive. You can use whatever mechanism you want for that.
If you are already using ASP.NET MVC then this is the best choice. If not you have the choice between adding MVC to the project or adding an HTTP handler.
HTTP handlers are a bit rough and inconvenient to use. I'd opt for MVC if there is no specific reason for not doing that.
HttpListener does not apply at all here. You don't need to open a port (and in the context of ASP.NET you can't do that reliably anyway because multiple instances of your app might run at the same time during recycles).

Custom validation using web service in silverlight

I am trying to validate a textbox input (in Silverlight) using validation annotations with custom validator which is supposed to validate input on a server side. My problem is that web service call is asynchronous, so I can't return a validation result since validation method is sync on the client side.
Can anyone help me with that?
You should look into INotifyDataErrorInfo. This allows asynchronous validation.
Here are some links that may be helpful:
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-binding-with-inotifydataerrorinfo.aspx
http://weblogs.asp.net/fredriknormen/archive/2009/11/22/silverlight-4-and-asynchronous-validation-with-inotifydataerrorinfo.aspx
Whether the web service is implemented asynchronously should not have any effect on the client as far as I know. For the client it will call the web service and wait for a response. If the response does not come on time, there will be a time out. It should not matter whether the web service executes asynchronously.

Categories

Resources