kestrel web api causes its client app failure of An existing connection was forcibly closed by the remote host - asp.net-core-webapi

Thanks everyone for your generosity to share your knowledge and expertise.
I have a .Net 5 Web API application for uploading large files (>6GB). If this App is running from Visual Studio 2022's debug mode, it can accept any size of files. The client App using HttpClient can upload large files.
But if I start the web App from a command line or start by "dotnet run" command, it can only accept small files (<6KB) and the Client App can upload small files. If the client App tries to upload a large file (>3GB), the client App will show the following error.
{"Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.."}
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (Error while copying content to a stream.)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at UploadFile.Program.Main(String[] args) in H:\Dev\DevProj\UploadFile\Program.cs:line 26
Inner Exception 1:
HttpRequestException: Error while copying content to a stream.
Inner Exception 2:
IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
Inner Exception 3:
SocketException: An existing connection was forcibly closed by the remote host.
Overriding address(es) 'https://localhost:8001, http://localhost:8000'. Binding to endpoints defined in UseKestrel() instead.
Any suggestion is appreciated.

I realized that Visual Studio 2022 may cause the problem. Since our Intranet environment is still using Visual Studio 2019, I have to stay with .Net 5 and VS 2019 currently. This VS 2022 is only installed on a test machine with Internet access.
After I build the web service code from VS 2019, it is working perfectly without using VS debugging.

Related

Windows Server error: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host

We have the following setup: Windows Web Server 2008 R2 with IIS 7.5 on which we are running an instance of Nopcommerce v3.8. We have a plugin that is used to send products listed in our online store to eBay.
If a product has less images(1-2) everything is fine, but if the images are more(4-8) we get the "Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host." error message.
We dont't get this issue when we test from a local installation of nopcommerce, so obviously this is a server configuration issue.
I tried changing config settings on server and in web.config as suggested in some posts(Maximum request length exceeded) but none seemed to do the job.
It will be great if someone can point me to a possible solution.
Thanks.

ASP.net can't connect to SQL Server after being deployed to hosting site

I'm developing an ASP.net web application.
My default page is a simple login screen.
I am using Visual Studio to develop the application.
It will run using Visual Studio and when the data is entered to the text boxes and the button is clicked, it sends the request to my own server running Windows Server 2012 with SQL Server 2014 installed.
I will also mention that the ASP application is being created as a secondary application for an Android application. The Android application is using the same database over Internet connection so I know that the server and SQL server both can accept read and write calls.
I have tested the ASP application using WebClient calls to php files which connect to the database (this works on Android) and also OracleClient and SQLClient calls all of which work from Visual Studio on my workstation to the server machine. These all work fine to send and receive data from the database.
The problem is once I deploy the application to my hosting site the calls no longer seem to work. The default login page opens but after attempting to login I receive errors as follows:
Exception Details: System.ComponentModel.Win32Exception: No connection could be made because the target machine actively refused it
[Win32Exception (0x80004005): No connection could be made because the target machine actively refused it]
[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.
Can anyone help me with this?
It sounds like your database is accepting connections from some clients, but not your hosting server. I would try testing a SQL connection straight from the hosting Server and see if a test connection can be successful. If you can get that to work it should work from the web server.
This article Quick ways to test OLE DB Connection String on creating a empty TestConnection.udl file will be helpful. It is easier to try different connection string settings through the Data Link Properties UI. When you save the file, you can see the connection string if you open it in a text editor (assuming it is successful).
If it's not a problem with he connection string, check that you do not have a firewall blocking connections between the Windows 2012 and SQL servers. It could be the widows firewall on either machine, or another firewall at the network level.

MSDeploy "Hangs" on MSDeployPublish

Trying to get MSDeploy working and it "hangs" on the MSDeployPublish task.
It says
"Start Web Deploy Publish the Application/package to
https://myserver:8172/msdeloy.axd?site=mysite ... Starting Web
deployment task from source: archiveDir(path to archive) to
Destination: auto()."
And it just stops. It will sit like this for 30 minutes, or more I suppose, before I kill the process.
On the server it is deploying to, in this case myserver, there is an error from MSDeploy that reads:
ERROR_SERIALIZER_ALREADY_DISPOSED - An error occurred on a callback
thread. These errors are usually benign and are handled automatically.
The details are below: System.Web.HttpException: The remote host
closed the connection. The error code is 0x800704CD. at
System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32
result, Boolean throwOnDisconnect) at
System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush() at
System.Web.HttpResponse.Flush(Boolean finalFlush) at
System.IO.BufferedStream.FlushWrite() at
System.IO.BufferedStream.Flush() at
System.Xml.XmlTextWriter.Flush() at
Microsoft.Web.Deployment.TraceEventStreamSerializer.WriteKeepAliveEvent()
No other error logs or messages that I can find.
I can hit the url to msdeploy, for example if I go to https://myserver:8172/msdeloy.axd in a browser I get the self signed certificate warning and then get prompted for credentials, so it appears MSDeploy on the server is up and running.
The server (myserver) is Windows 2008R2 with IIS7.
What really sucks, is if I REBOOT the server that I am deploying to (myserver) IT WORKS!
Any ideas on what is going on here?
Just went through the same thing. This is the response from my hosting company that resolved the issue.
"While investigating, we found that the connection attempt was hanging on our end. The Web Management Service needed to be stopped to edit settings for the management service but upon attempting to stop this service, it would not shut down so we force killed the process and after starting it back up (no changes were made to settings), Visual Studio is making connections with Web Deploy without issue."

Can't get my EC2 Windows Server 2008 (Web stack) instance to receive publishings of my website

I installed a fresh AMI for EC2 (http://aws.amazon.com/amis/Microsoft/5147732567196848) and have installed Web deploy 2.1 on it.
The web deploy 2.1 service is running for real as
netstat -an
Shows 8172 is being listened on by the Web Deployment Agent Service.
But, when I try to deploy to this site using Project->right-click->Publish (via web deploy) I receive the following error message
------ Build started: Project: Cir.Web, Configuration: Debug Any CPU ------
Cir.Web -> C:\Projects\CrazyInsaneRobot\Source\Cir.Web\bin\Cir.Web.dll
------ Publish started: Project: Cir.Web, Configuration: Debug Any CPU ------
Transformed Web.config using Web.Debug.config into obj\Debug\TransformWebConfig\transformed\Web.config.
Auto ConnectionString Transformed Views\Web.config into obj\Debug\CSAutoParameterize\transformed\Views\Web.config.
Auto ConnectionString Transformed obj\Debug\TransformWebConfig\transformed\Web.config into obj\Debug\CSAutoParameterize\transformed\Web.config.
Copying all files to temporary location below for package/publish:
obj\Debug\Package\PackageTmp.
Start Web Deploy Publish the Application/package to https://ec2-175-41-170-198.ap-southeast-1.compute.amazonaws.com:8172/msdeploy.axd?site=Default%20Web%20Site ...
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3847,5): Warning : Retrying the sync because a socket error (10054) occurred.
Retrying operation 'Serialization' on object sitemanifest (sourcePath). Attempt 1 of 10.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3847,5): Warning : Retrying the sync because a socket error (10054) occurred.
Retrying operation 'Serialization' on object sitemanifest (sourcePath). Attempt 2 of
...
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3847,5): Warning : Retrying the sync because a socket error (10054) occurred.
Retrying operation 'Serialization' on object sitemanifest (sourcePath). Attempt 10 of 10.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3847,5): Error : Web deployment task failed.(Could not complete the request to remote agent URL 'https://ec2-175-41-170-198.ap-southeast-1.compute.amazonaws.com:8172/msdeploy.axd?site=Default Web Site'.)
This error indicates that you cannot connect to the server. Make sure the service URL is correct, firewall and network settings on this computer and on the server computer are configured properly, and the appropriate services have been started on the server.
Error details:
Could not complete the request to remote agent URL 'https://ec2-175-41-170-198.ap-southeast-1.compute.amazonaws.com:8172/msdeploy.axd?site=Default Web Site'.
The underlying connection was closed: An unexpected error occurred on a send.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
Publish failed to deploy.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
My firewall on the EC2 instance has been turned off. And my AWS firewall settings are
which are the recommended settings.
Other notes/thoughts:
My Web Deploy Error log in the windows error log is completely empty
I've used web deploy before using a different AMI in the past and succeeded without problems.
If anyone has any suggestions about how to debug this, I would be so ever grateful!
I contact Microsoft directly about this problem and they had an immediate answer for me.
From MS guy:
It looks like your Web Management Service not contactable. I have seen this before when the certificate for the service is invalid. Can you run the attached script on your server?
Start a PowerShell prompt elevated
Run set-executionpolicy unrestricted –force
Run .\00_Certificate.ps1
Net stop wmsvc
Net start wmsvc
Does this fix the problem?
The script he is referring to is available here
This error can also occur when you specify the end point in the wrong format.
For example when selecting to publish an application Visual Studio gives examples of the end point format such as https://RemoteServer:8172/MsDeploy.axd
Turns out it actually wanted this without the http prefix e.g.
0.0.0.0:8172/MsDeploy.axd
If you get an error about certificates after this you just need to check the box allow untrusted certificates in the publish screen.
Agrahahah!
I had this same problem with Web Deploy when it was installed by the Web Platform Installer. After manually uninstalling and reinstalling Web Deploy directly (NOT using Web PI) it worked fine...
Some very helpful answers for an error message with many causes. I had this error and it turned out that the "IIS Web site/application" name used for the destination server was wrong.
So, causes for this could include:
Bad username or password
Incorrect web site name for destination (In Visual Studio, this is set on the Package/Publish Web tab of a web project's properties)
SSL cert for web management (for example if your server was sysprepped after IIS was installed)
I get the same error when i tried to deploy a website.
In the EventViewer (Windows Logs/System) i had an error log, that the log file of the Web Management Service could not be created ("Unable to create log file D:\Logfiles\WMSVC\W3SVC1\u_ex131126.log. Make sure that the logging directory is correct and this computer has write access to that directory.".
I just removed the readonly flag of the log folder and all worked fine again.

Local ASP.Net connection issues

I have been trying to set-up my recently reimaged workstation for working with one of our ASP.Net applications that consists of a ASP.Net website and some C# Web Services. I can successfully start debug instances of each the services and web site. However as soon as the site attempts to connect to and use one of the web services I get the following exception.
No connection could be made because
the target machine actively refused it
127.0.0.1:80
Description: An unhandled exception occurred during
the execution of the current web
request. Please review the stack trace
for more information about the error
and where it originated in the code.
Exception Details:
System.Net.Sockets.SocketException: No
connection could be made because the
target machine actively refused it
127.0.0.1:80
So it looks like my PC is refusing the connection to itself. My first thought was to to check the windows firewall is disabled and it is disabled (the service is not running). I do not think IT has any other firewall software running on this PC, so I am a bit stumped as to what else could be causing the connection to be refused.
Silly question, but do you actually have IIS installed on your machine? When you run debug instances of your applications, it's running outside of IIS. If you're running debug instances of both your site and your service, your service probably isn't running on port 80.
Double check your IIS installation...and then set up your service running on port 80 properly.

Resources