Disable Blazor Server Kestrel keep-alive client-server communication - asp.net-core

I'm about to create a .net 6 Blazor server application hosted by Kestrel (within a docker container) which uses a custom timeout handling on client side. Once the application is not used for e.g. 30 minutes a dialog is displayed and the page needs a reload for further usage (and a new server connection).
For stopping the application (connection) I call "Blazor.disconnect();" on the client side.
This works in general but I've noticed that after calling Blazor.disconnect() and displaying the information message the client and the server are still exchanging keep-alive data like this which I also want to suppress to save resources and bandwidth:
Sent a ping message to the client. [Microsoft.AspNetCore.SignalR.HubConnectionContext]
Sending payload: 3 bytes
[Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport]
Message received. Type: Binary, size: 3, EndOfMessage: True [Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport]
Is there a way to end this communication on client side (via JavaScript) or on server side without having to navigate away from the application page ?

Related

Request To WCF service is not hitting on application level from Java application

I have a SOAP WCF service hosted in IIS and it is consumed by another company SAP system and everything was working fine for couple of years until our security team implemented Header validation in request and it stopped working all of sudden since the client SAP system request doesn't contain header CallingType. So then they added CallingType and pushed request to our system and F5 server allowed access and request entered to our system where WCF hosted. But WCF did not logged request and no data we got. So i would like to know how i can troubleshoot and provide fix. My network team is telling request is validated and passed by F5 server and pushed to our server. But why WCF is not logging anything??Do i need to add any custom header in webconfig of WCF service, or our IIS is preventing something? How can i see IIS is blocking the request.

API Get request being blocked outside of network

I built a web app using React and uses Axios to make api calls.
The web application sits on our public server, while the API sits on one of our servers inside our network.
When I or any user use the application while VPN into our network the api request goes through. However, when we try outside of the network we get a timeout error.
I'm able to access the website perfectly fine outside the network with no errors. The timeout error happens when I submit the form and do the axios.get
I have wireshark running on the server where the web application is sitting and below is what errors I'm receiving with trying to make that api call.
What would be causing the TCP Retransmission to switch ports from 443 t0 53027 (which is a dynamic port that changes on every session). What's causing the timeout?

The SSL connection could not be established between WebApp and WebApi (Asp Core 3.1)

I wrote an ASP.NET Core 3.1 MVC web application. It's an front end calling a Web API back end.
The application works perfectly on development and Staging.
I can't make it work on Production: the Web API seems ok, I can call it from the browser or Postman.
But I can't reach it from my web app. This is the error from the log when it tries to make a call:
info: System.Net.Http.HttpClient.IApiClient.ClientHandler[100]
Sending HTTP request GET https://webapi.****.it/inetApi/api/links
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
--- End of inner exception stack trace ---
Staging and Production are both Windows server 2019 machines with IIS10 web server.
Staging has a single website where both the Web API and the web app run as applications:
Web-t.****.it/inetApi
Web-t.****.it/inetW
Production VM has two website, one is supposed to be for internal web apps and the other for APIs:
webapi.****.it/inetApi
intranet.****.it/inetW
We made this VM from the scratch, it's new, there aren't any other application or websites on it.
I already tried to move the Web API application into the same website of the web app to see if that could be the problem, but it doesn't.
I tried to force the web app to use TLS as security protocol using this in my startup.cs:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
But it only change the error:
info: System.Net.Http.HttpClient.IApiClient.ClientHandler[100]
Sending HTTP request GET https://webapi.****.it/inetApi/api/links
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
System.Net.Http.HttpRequestException: An error occurred while sending the request.
System.Net.Http.WinHttpException (80072EFF, 12030): Error 12030 calling WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, 'The connection with the server was terminated abnormally'.
at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()
at System.Net.Http.WinHttpHandler.StartRequestAsync(WinHttpRequestState state)
--- End of inner exception stack trace ---
So I tried to call the production Web API from the web app on staging or development, and it works.
Then I tried to use the web app on Production with the staging Web API... and it works too!
This is driving me nuts.
It's like everything in production is working individually, but not together.
I have grants to do everything I need on the VMs... but I'm a developer (and not very good at dealing with systems), and I can't ask much help to the sysadmins because they are overwhelmed in this period.
Any ideas?
According to the Transport security Best practice, as much as possible not to specify the SSL version during the establishment of SSL connection. Just let the OS decide on the SSL protocol version.
https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls
There might be something wrong with the validation process of the SSL certificate installed on the server-side. As you know, SSL communication requires the trust relationship between the client-side and the server-side, therefore I would like to know how you specify the certificate for your WebAPI project. have you established the trust relationship between the client-side and the server-side? namely, install the service certificate on the client-side. As to explain how it works properly in the development and Staging environment, Http Get request doesn't represent something, please try an Http Post request.
Besides, the SSL protocol requires the DotNet framework/OS support, try to install a high version DotNet framework.
Feel free to let me know if you get something new afterward.

WCF client service communication

I have a very basic question about wcf service with basicHttpbinding:
When client calls a wcf service(basichttpbinding) synchronously how the request and response is received between two? Does a socket connection established between 2 and port on server tied up till response is received on client? How the response is sent back to the waiting client? IF port on server is unusable for long running operation then will it hinder service ability to accept request from other client? Also, how communication happens in can of asynchronous call to wcf service? I read that channel and hence port/socket should remain open at both ends.
With basichttpbinding, it's much the same as normal http communication between a browser and a web server. If you hit a link on a web page, a request from the browser is sent to the appropriate web server, which processes the request and returns the content, as a response, to the waiting browser.
It's the same with WCF basicHTTPBinding. The WCF client sends a post or get request to the designated web service (http: //webservice:port/ServiceObj/MethodName) and waits for a response. When the web service finishes gathering the data, the data is sent back to the client in the response on the open connection, which is then closed by the host. There's no persistant connection. Thus, basichttpbinding is stateless. Once the web service sends the response, connection is recycled and the service is ready to go for the next request.
If the client is finished with its communication, it can close its connection explicitly; that's best. But if it doesn't close its connection, it won't make any difference to the host.

WCF Duplex Interaction with Web Server

Here is my scenario, and it is causing us a considerable amount of grief at the moment:
We have a vendor web service which provides base level telephony functionality. This service has a SOAP api, which we are leveraging to build up a custom UI that is integrated into our in house web apps. The api functions on 2 levels. You make standard client calls into the service to initiate actions, such as Login, Place Call, Hang Up, etc. On a different thread, the service sends events back to the client to alert the user of things that are occurring on the system (agent successfully logged in, call was disconnected, etc).
I implemented a WCF service to sit between the web server and the vendor service. This WCF service operates in duplex mode, establishing a 2 way connection with the web server. The web server makes outbound calls to the WCF service, which routes them to the vendor's web service. Events are received back to the WCF service, which passes them onto the web server via a callback channel on the WCF client. As events are received on the web server, they are placed into a hash table with the user's name as the key, and a .NET queue as the value to hold the event. Each event is enqueued to the agent who owns it.
On a 2 second interval, the web page polls the web server via an ajax request to get new events for the logged in user. It hits the hash table for the user key, dequeues any events that are present, and serializes them back up to the web page. From there, they are processed in order and appropriate messages are displayed to the user.
This implementation performs well in a single user scenario. The second I put more than 1 user on the system, I start getting frequent timeouts with the following CommunicationException:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
We are running Windows Server 2008 R2 both servers. Both the web app and WCF service are running on .NET 3.5. The WCF service is running under the net.tcp protocol in duplex mode. The web app is ASP.NET MVC 2.
Has anyone dealt with anything like this scenario? Is there a more efficient way (or a widely accepted pattern) to implement this?
EDIT: One thing I forgot to mention - my thought is that the increased traffic (adding additional users) with only 1 dedicated callback channel is causing locking, which then triggers the timeout. There can be up to 10 consecutive callbacks from the service within any 5 second interval.