No connection could be made because the target machine actively refused it - asp.net

I'm trying to do a web request from a webpage and I'm having problem on production server.
The web application is a intranet web site with this configuration on web.config:
<authentication mode="Windows" />
I use it to get the domain user authentication.
Now I'm trying to load a web page to parse some information, I used the code below, the error appears on the second line:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
The error message is:
No connection could be made because the target machine actively refused it 64.233.163.104:80.
Stack Trace:
[SocketException (0x274d): No connection could be made because the target machine actively refused it 64.233.163.104:80]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +269
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +649
[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.GetResponse() +1126
Fumagalli.Insight.Admin.Teste.Page_Load(Object sender, EventArgs e) +606
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
This error don't occur with all URLs that I have tryed, I can get the response from www.yahoo.com but not from www.google.com for example.
On my PC (Windows 7) everything allways works, I can get response from any URL using the same authentication mode (with domain controller), the problem only occur on the production server (Windows Server 2008).
Anyone has a ideia?

I had a problem like this, it turned out that we are behind a proxy, that could be the issue, I know its a long shot, but it just might work
I copied the proxy data from my browser, just replace the proxy string with your proxy (don't forget the port).
WebProxy webproxy = new WebProxy("http://192.168.4.8:8080");
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
request.Proxy = webproxy;

The server may actively refuse a connection for other reasons than authentication. Most of these other reasons have to do with the form of the request and the port on which it is received. A mismatch, or a closed port, will result in a refused connection. In this case, however, an HttpRequest made on Google's front door should get you a response. I would guess that Google may inspect the WebAgent header information included in your HttpRequest; your application looks like a .NET application and presents itself to Google as such. I imagine Google has taken steps to reduce DOS attacks from simple .NET applications like yours infinitely looping over a GetResponse() call. You may need to impersonate another browser, like IE 8, by specifying a custom WebAgent header string.

Related

.Net core web api not support with the HTTPS

I have created web api using .NetCore. After that I have change it to Windows background Service. Now my api is working as a background service.But its only listen to the HTTP request. When I used HTTPS its not listen to the request.
Currently its support only this url http://localhost:8080/Customer. But I need to use it like this https://localhost:8080/Customer.
Someone can please tell me how we can start new service listen to the https request. When I tried to use HTTPS I got this error message.
Application: MHScaleInboundWebAPI.exe
CoreCLR Version: 5.0.1021.41214
.NET Version: 5.0.10
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at MHScaleInboundWebAPI.Program.Main(String[] args) in C:\Projects\IRM\mhscaleinboundwebapi\Program.cs:line 10

gRPC client receives Http2StreamException from gRPC running on Kestrel server

I have gRPC server on Kestrel and test client on WinForms. Both netcore 3.1. On separate request all Ok.
When I start multiple parallel requests I see error below:
Status(StatusCode="Unavailable", Detail="Error reading next message. IOException: The request was aborted. Http2StreamException: The HTTP/2 server reset the stream. HTTP/2 error code 'INTERNAL_ERROR' (0x2).", DebugException="System.IO.IOException: The request was aborted.
---> System.Net.Http.Http2StreamException: The HTTP/2 server reset the stream. HTTP/2 error code 'INTERNAL_ERROR' (0x2).
--- End of inner exception stack trace ---
at System.Net.Http.Http2Connection.Http2Stream.CheckResponseBodyState()
at System.Net.Http.Http2Connection.Http2Stream.TryReadFromBuffer(Span`1 buffer)
at System.Net.Http.Http2Connection.Http2Stream.ReadDataAsync(Memory`1 buffer, HttpResponseMessage responseMessage, CancellationToken cancellationToken)
at Grpc.Net.Client.StreamExtensions.ReadMessageAsync[TResponse](Stream responseStream, GrpcCall call, Func`2 deserializer, String grpcEncoding, Boolean singleMessage, CancellationToken cancellationToken)
at Grpc.Net.Client.Internal.HttpContentClientStreamReader`2.MoveNextCore(CancellationToken cancellationToken)")
I need suggestions.

A message sent to adapter "WCF-WebHttp" on send port "" with URI "https://na59.salesforce.com/services/Soap/c/43.0/00Df4000001dsdy" is suspended

I need help on SalesForce integration with biztalk 2016 environment.
I'm using "WCF-WebHttp" adapter to send request to SalesForce with custom behavior as below and getting below suspended message to FORCE.com.
So, Do i need to add security protocol on my WCF behavior like TLS 1.1, 1.2 to call salesforce API through BizTalk ?
EventViewer Error message
A message sent to adapter "WCF-WebHttp" on send port "DeveloperForce.SendCreateAccount.REST" with URI "https://na59.salesforce.com/services/Soap/c/43.0/00Df4000001dsdy" is suspended.
Error details: System.ServiceModel.Security.SecurityNegotiationException: Could not establish secure channel for SSL/TLS with authority 'na59.salesforce.com'. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.ServiceModel.Channels.HttpChannelFactory`1.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.WcfClient`2.RequestCallback(IAsyncResult result)
MessageId: {345BABC2-0BE9-42F2-8D47-D123A402B3CD}
InstanceID: {FEDE9235-18DB-4E3F-969E-6648A869F45A}
Send Port Screen shot:
Sales force requires TLS1.1/1.2 for communication. If you don’t have BizTalk 2016 latest CU5 then you need to set the security protocol either in custom service behavior ( a bit more work) or in a custom pipeline component. All you need is to set System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls11 or Tls12
Or as per CU5 TLS1.2 support is added.
This sounds like a trust issue. Maybe the certification chain cannot be resolved / isn't trusted. Check this using certmgr.msc.
Make sure "DigiCert Global Root CA" is in the Trusted Root Certification Authorities store
Verify that "DigiCert SHA2 Secure Server CA" is in the Intermediate Certification Authories store.
have you installed SalesForce certificate? on your Biztalk machine using the biztalk service account?

Docker for windows seems to timeout when connecting to external HTTP server

I am running a .NET framework application on top of microsoft/windowsservercore. My application communicates, via HTTP, with an external server. Quick requests work well, but when the external server takes more time to reply, I get the following error:
System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to http://server/myservice.svc. 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.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
When I run my application from the host machine, instead of Docker, everyting goes well.
It looks like somehow Docker times out and closes the HTTP connection to my server. Anyone faced this? How can I work around it?

Double-hop issue with WCF Service and Sharepoint Service both hosted on same iis server

I am getting the below exception when a WCF service is trying to access a sharepoint site for content.
Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
[WebException: The remote server returned an error: (401) Unauthorized.]
System.Net.HttpWebRequest.GetResponse() +6592536
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +55
[MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10733331
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336
My IIS server version is IIS 8.0.
Our Sharepoint Server/Site is on the same domain as my client computer.
Please have a look at the loopback check: http://support.microsoft.com/kb/926642/en-us

Resources