What is buffering SignalR Server Sent Events on Azure Web Role? - c#

I have a Xamarin app that connects to a SignalR server hosted on Azure.
Since it's Xamarin running over mono, websockets are not available.
When my server was hosted on Azure Mobile Services, the app used SSE.
I moved the server to a web role because mobile services were too limited.
Now my app fails to connect using SSE and falls back to long polling after the 5 seconds timeout interval.
I tried creating a new Web Role and only adding SignalR. Still get the same problem.
I have identified/tried the following:
It looks like the SSE request is being buffered somewhere in Azure. If I use a proxy I can see the request but the first response byte is received only after SignalR times out and closes the connection.
There is no proxy or similar on my network - I can still connect over SSE to my old mobile services server.
I turned on tracing on the server and it looks like SignalR is doing its thing - it returns the response to the SSE connect request.
I can also see the SSE request in IIS in the AuthorizeRequest stage which means the connection is opened.
I disabled dynamic compression. Didn't help.
To summarize, looks like the SSE connection is made, remains open, but something prevents the data from SignalR from reaching the client.
I read here that this can be an issue with the Http Platform Handler. But as far as I understand, this is not relevant to web role since it's normal C# code running in IIS.

Try using HTTPS - it will prevent proxies from messing with the event stream.

Related

Possible problems with Owin SignalR hosted in IIS 10 Express or IIS 10?

this is my first questions on SO. Normaly I just wander the internet reading stuff until I can make up a solution.
So up until now we use HTTP Request and Response Model to communicate with Clients.
Using C# ASP.Net .Net Framework 4.0 hosted in IIS.
This way we are not able to forward information in real time to them from the server.
We would need to wait till the clients contact the server.
To solve this issue I think OWIN with SignalR V2 Middleware hosted in IIS would give us the ability to use Remote Procedure Calls, so whenever something happens that needs to be forwarded immediately to the Client, we can do so by calling that specific clients function or all clients.
For this of course the target Framework of the application needs to be .Net Framework 4.5 at least.
Now the problem I have is that in the Microsoft Documentation it says to use the IIS Express version, in order to enable the server to have more than 10 connections.
On the client side it would be no problem as ideally there would only be one connection at any given time.
But the Server should be able to have a whole lot more than just 10. As the Websocketconnections would stay open.
I am not an IIS expert, but why are there these limitations in the non Express version?
I would expect that one should be able to set the number of maximum connections despite the IIS version?
What are the gains of using IIS instead of self-hosting OWIN?
I would guess that I would need to implement some security features myself?
On my development PC a client Windows Service with SignalR V2 is able to communicate with an OWIN SignalR V2 hosted in IIS application.
At the moment I need to evaluate what needs to be considered to set this up on a server to ensure functionality.
I hope this all makes sense.
I am implementing Remote Procedure Calls in our Webservice, for real time communication with clients.
I read documentations about RPC, SignalR V2, OWIN and Katana.
At the moment I need to evaluate what needs to be considered to set this up on a server to ensure functionality.

Azure web app: Web sockets abort after 100 seconds

I'm writing a web socket application which I intend on hosting on the cloud using an Azure web app.
The web socket is implemented using a fairly standard piece of Owin Middleware and is fully functional for the first 100 seconds. After this time the websocket seems to enter the aborted state like clockwork.
[CLIENT][06/04/2018 11:27:21] WS client connected
[CLIENT][06/04/2018 11:29:01] WS client disconnected
Trying this on an IIS Express instance gives the same issue, although the delay seems to be 90 seconds rather than 100 (this is also consistent).
Running the same websocket as part of an Owin self-host app yields stability for over 25 minutes - so this definitely seems to be a problem caused by the hosting server.
On the azure web app hosting I've enabled web sockets, and also tried to enable the "Always On" feature in hopes that this would prevent the issue by preventing the server from going into a standby state - but this has not helped.
Are there any azure settings that I'm not aware of that could be tweaked such that these web sockets can stay open for longer periods of time?
Many thanks
Unfortunately, it seems that azure and IIS were both red herrings, the issue instead was an issue experienced with using the C# implementation of System.Net.Websockets.ClientWebSocket. The detail is brilliantly summarized at: .NET WebSockets forcibly closed despite keep-alive and activity on the connection
To others experiencing this issue, an effective (but not ideal) work around is to run the following once before creating a client web socket:
ServicePointManager.MaxServicePointIdleTime = int.MaxValue;

HTTP and SignalR

I am recently learning about web sockets in .Net and have just found SignalR which seems like too good to be true in terms of the abstraction of what connection to use and it seems like there are a few signalr clients in different languages which is awesome.
In my current project different resources are being exposed through a RESTful API, and from my understanding of websockets the client needs to upgrade to a web socket connection through a HTTP request/response. Does signalR handle all this handshaking going on?
If there is an initial request/response from a GET request to retrieve a certain resource but they opt to upgrade to a socket connection, does the server give them any sort of response besides the response saying it acknowledges to open up a web socket connection or is the handshake all that occurs before the information is live updated for that particular resource?
Do you think signalR is scalable as opposed to implementing this through a protocol like STOMP where there are a large number of client libraries?
You are making things too complicated. A typical example of using signalr is:
an html file using JavaScript to connect to a signalr Server when the page is loaded. we call this signalr client.
a signalr server written in c#. it can be a winform or console or service.
the signalr Server can call any dll, or webservices or webapi located in the same server, or even in different Server.
then, the client can call any function defined in the signalr server. the server can call any function defined in the client for a particular client or for groups of clients.
also, client x can call client y functions as well.
you can actually forget about Web sockets, signalr choose the most appropriate transport protocol for you. it will choose Web sockets if it is available in both the server and the client.

How do I figure out what is eating up ports in Azure MVC website?

I have an ASP.NET MVC website deployed as an Azure Website and every few days I keep getting errors like this:
System.Net.Sockets.SocketException: An operation on a socket could not
be performed because the system lacked sufficient buffer space or
because a queue was full
Once I start getting these errors the entire site goes down and it seems like all the outgoing ports have been exhausted. I have to change the capacity of the Azure website to get it to restart and clean out the ports so it will start working again.
How can I figure out what is eating up these ports? Is there tracing I can use for an Azure website? I don't have the ability to remote desktop into a machine since it is a hosted service. Some of the services that would be using outgoing ports are:
Making SQL Server calls with Entity Framework
Pulling down and caching assets from Azure Blob Storage with the Image Resizer plugin
Sending email via SMTP through SendGrid

Send commands to another network

I am trying to write a monitoring tool to monitor some information
It will gonna work on azure normally. So i gonna host the database on azure also the webservice will be hosted at azure.
On the client's i read from the config file how many time's he need to update the information to the azure database ( with the webservice on azure ).
Now i want to send also some commands to the client itself. Like start service, .... what is the best way to do that?
How can i send it from a website that is hosted on the azure platform?
I think you should consider implementing a WCF service at the client as well. The Azure side of your software could call operations from this service when it needs to instruct the client to do something.
The WCF service at the client should be something simple,hosted in a Windows Service or in your actual client (whatever it is... win forms, console, etc).
Since you have no VPN, it sounds like you may have a problem with hosting a WCF service on the client. If the client is behind a firewall, you would have to modify the firewall configuration to allow your server to connect to this service.
Last time I had to do a service like this, I used Comet. The server maintains a queue of messages to be sent to the client. Your client connects to the web service and requests any available messages. If messages are available, the server returns them. If not, the server leaves the request open for some time. As soon as a message arrives, the server sends it down the already-open connection. The client will either periodically time out/reconnect or send a keep-alive message (perhaps once per minute) in order to keep the connection alive in the intervening firewalls.

Categories