Intermittent "error occurred while making the HTTP request" - httpclient

error occurred while making the HTTP request
I have a c# client that calls a remote endpoint using a HttpClient. The client is hosted on a Windows Server.
The client will run fine for a long time and then I encounter a "error occurred while making the HTTP request".
We do use Trend Micro AntiVirus.
I run this client about every 5 minutes. It works very well when it starts but when the error happens it keeps happening. To resolve it I shut the service down, wait awhile and then restart it.
Here is my code snippet:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
System.Net.ServicePointManager.MaxServicePointIdleTime = 10000;
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(URL);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.ConnectionClose = true;
HttpResponseMessage response = await client.PostAsync(URL, content);
}
Here is the error:
Exception: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
Any help would be appreciated.
Thanks!

Related

Error sending message to Mule API from BizTalk

I am trying to post a message to Mule service, which is expected to respond with Success or Error Response. When I post a request directly to the Mule API using Postman, it gives a response as 200 with some HTML content. When I am pushing the same request with similar headers from BizTalk send port, I get the following error:
An error occurred while processing the message, refer to the details section for more information Message ID: {56AF4477-590F-415E-9D70-536692FE637C} Instance ID: {20EEC344-3B1A-474E-ACEB-160CBF616775} Error Description: System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to https://. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> 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: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.Security._SslStream.EndRead(IAsyncResult asyncResult) at System.Net.TlsStream.EndRead(IAsyncResult asyncResult) at System.Net.Connection.ReadCallback(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) --- End of inner exception stack trace --- Server stack trace: at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndRequest(IAsyncResult result) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at System.ServiceModel.Channels.IRequestChannel.EndRequest(IAsyncResult result) at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient2.RequestCallback(IAsyncResult result)
This call from the BizTalk interface to Mule API was working fine until yesterday.
I have tried using Fiddler to see the HTTP traffic from the BizTalk server. It shows the handshake with the Mule service, but no further information on headers or the request body.
Please help.
UPDATE
When I posted the request directly to the Mule Api from another machine, it gave a proper response. This seems like a network issue, some rules may have been modified to allow traffic from specific servers. Waiting for the network team to confirm.

What can be done to get SecurityProtocol working, I'm getting "The SSL connection could not be established"?

I'm building an ASP.NET Core 3.0 web application, that gets deployed using Octopus. This is all working just fine. We're going live soon, so I've been hardening the servers, by removing insecure protocols etc. using IISCrypto. Only one left is Tls 1.2.
Now all of a sudden I can't do a HttpWebRequest to my deployed web application from a .NET Core command line tool I have written for commissioning the application. I'm getting this error in the logs:
System.Net.WebException: The SSL connection could not be established, see inner exception. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
---> 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.
So I tried using some of the suggestions found on SO:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
But this doesn't change anything. It's like this line gets ignored.
The code that fails:
HttpWebRequest http = (HttpWebRequest)WebRequest.Create(new Uri(url));
http.Accept = "application/json";
http.ContentType = "application/json";
http.Method = method;
if (String.IsNullOrWhiteSpace(token) == false) {
http.Headers.Add("Authorization", $"Bearer {token}");
}
if (String.IsNullOrWhiteSpace(data) == false) {
UTF8Encoding encoding = new UTF8Encoding();
Byte[] bytes = encoding.GetBytes(data);
Stream newStream = http.GetRequestStream();
newStream.Write(bytes, 0, bytes.Length);
newStream.Close();
}
try {
WebResponse response = http.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
return sr.ReadToEnd();
}
catch (Exception ex) {
logger.Error(ex, $"{method} on {relativeUrl} failed");
Console.WriteLine(ex.Message);
}
Just to try something else, I did a small test from Powershell, and I ended up getting a similar error message. Then I added the security protocol line to the script, and it works:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -UseBasicParsing https://mysite/app/authenticate -ContentType "application/json" -Method POST -Body (#{"emailAddress"="somemail#address"; "password"="somepassword"}|ConvertTo-Json)
Any ideas as to why this isn't working with .NET Core ?
This actually turned out to be "wrong server" issue. For some reason my request ended up on the wrong server, and this apparently is the reply/error you get, when you request something on a server that does not have the requested site hosted.

Error during WebSocket handshake: Unexpected response code: 404 Sails.js

i'm currently using sails.js and i deploy it in a2hosting shared hosting with turbo plan , i'm trying to connect to the sails socket in (ionic /angular) app i used the nodejs script for sails.io.js and socket.io.js from this documentation from here
and this is my configuration in my ionic app
this.io = sailsIOClient(socketIOClient);
this.io.sails.url = 'https://example.com/api';
this.io.sails.path = '/api';
this.io.sails.environment = 'production';
this.io.sails.useCORSRouteToGetCookie = false;
and every time trying to connect this errors appear
websocket.js:110 WebSocket connection to 'wss://example.com/api/?__sails_io_sdk_version=1.2.1&__sails_io_sdk_platform=node&__sails_io_sdk_language=javascript&EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 404
any one can help me please ?

CRM 4 email router error

I heed some help. We have na email router for CRM 4 for sending emails. All was fine till this week. It started to send this error and doing nothing.
Error message:
An error occurred while opening mailbox crmsupport#domainname.ua. Microsoft.Crm.Tools.Email.Providers.EmailException: The remote Microsoft Exchange e-mail server returned the error "(404) Not Found". This user or queue does not have a mailbox. Create a mailbox and try again. ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.Crm.Tools.Email.Providers.HttpDavRequest.SubmitXmlCommand(HttpWebRequest httpWebRequest, String body)
at Microsoft.Crm.Tools.Email.Providers.HttpDavRequest.RetrieveInboxUri()
at Microsoft.Crm.Tools.Email.Providers.ExchangeWebDavConnector.OpenMailbox()
at Microsoft.Crm.Tools.Email.Providers.ExchangePollingMailboxProvider.InitExchangeConnector()
--- End of inner exception stack trace ---
at Microsoft.Crm.Tools.Email.Providers.ExchangePollingMailboxProvider.WrapException(Exception e)
at Microsoft.Crm.Tools.Email.Providers.ExchangePollingMailboxProvider.InitExchangeConnector()
at Microsoft.Crm.Tools.Email.Providers.ExchangePollingMailboxProvider.OpenMailbox()
at Microsoft.Crm.Tools.Email.Providers.CrmPollingMailboxProvider.Run()\r\nSystem.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.Crm.Tools.Email.Providers.HttpDavRequest.SubmitXmlCommand(HttpWebRequest httpWebRequest, String body)
at Microsoft.Crm.Tools.Email.Providers.HttpDavRequest.RetrieveInboxUri()
at Microsoft.Crm.Tools.Email.Providers.ExchangeWebDavConnector.OpenMailbox()
at Microsoft.Crm.Tools.Email.Providers.ExchangePollingMailboxProvider.InitExchangeConnector()
Thank you!!!

Error when calling PSI web service: HTTP request is unauthorized with client authentication scheme 'Anonymous'

Could someone please help me? I am trying to create a project in project server programatically (PSI webservice) but am failing to do so because of the error below. Does anyone know what might be the issue? I am also getting this error when attempting to update the web service in VS2008.
Here is the error and it happens when I call QueueCreateProject (see code below):
System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
Here is the code:
objProject = new pstest.ProjectWS.ProjectSoapClient();
dsProjectDataSet = new pstest.ProjectWS.ProjectDataSet();
ProjectWS.ProjectDataSet.ProjectRow projectRow = dsProjectDataSet.Project.NewProjectRow();
Guid _projectGUID = Guid.NewGuid(); // new GUID for each project
projectRow.PROJ_UID = _projectGUID;
projectRow.PROJ_NAME = "My new Project";
projectRow.PROJ_INFO_START_DATE = System.DateTime.Now;
projectRow.PROJ_TYPE = 0; //0 is for project and 1 is for template
dsProjectDataSet.Project.AddProjectRow(projectRow);
//create a project using project.asmx
objProject.QueueCreateProject(Guid.NewGuid(), dsProjectDataSet,false);
Most likely your app.config is misconfigured. Depending on your security configuration, you probably need to change part of it:
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
Take a look at this thread for more information.