Forums, Documentation & Knowledge Base - ComponentSpace

ComponentSpace.SAM2 - SendRequestReceiveResponse() - The underlying connection was closed


https://componentspace.com/forums/Topic11497.aspx

By Yokesh - 3/18/2021

We are currently in process of migrating our application to cloud environment.

In the application, we are using ComponentSpace dll to verify Artifact returned from CorpPass site. The method SendRequestReceiveResponse() used to process the request and the passing parameters are WebRequest and XMLElement. Refer below.

public static XmlElement SendRequestReceiveResponse(WebRequest webRequest, XmlElement artifactResolve);

So for it is working as expected since we using the direct CorpPass URL to generate web request and passing to the above method. In cloud environment, we should not use the CorpPass URL directly. Instead, we host the CorpPass URL in azure server and calling the URL at backend using WEB API.

When we pass the WEB API URL to the SendRequestReceiveResponse() which is inside ComponentSpace dll, it is throwing the following error.

ComponentSpace.SAML2.Exceptions.SAMLBindingException: Failed to send/receive SAML request/response over SOAP. ---> 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 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.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.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
 at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
 at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
 at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
 at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
 at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
 at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
 at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
 at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
 at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
 at System.Net.ConnectStream.WriteHeaders(Boolean async)
 --- End of inner exception stack trace ---
 at System.Net.HttpWebRequest.GetResponse()
 at ComponentSpace.SAML2.Bindings.SOAPBinding.SendRequestReceiveResponse(WebRequest webRequest, XmlElement samlMessage)
 --- End of inner exception stack trace ---
 at ComponentSpace.SAML2.Bindings.SOAPBinding.SendRequestReceiveResponse(WebRequest webRequest, XmlElement samlMessage)
 at ComponentSpace.SAML2.Profiles.ArtifactResolution.ArtifactResolver.SendRequestReceiveResponse(WebRequest webRequest, XmlElement artifactResolve)
 at QMS.CorpPass.Service.CorpPassService.ReceiveSAMLResponse(String SAMLArt, String relayState)

By ComponentSpace - 3/18/2021

For some reason, the other end is closing the connection ("An existing connection was forcibly closed by the remote host").

This issue isn't at the SAML protocol level. Instead, a transport connection cannot be made to the remote host.

It's difficult to determine the reason without detailed information from the remote host.

It's possible this is failing during the SSL handshake phase but someone needs to check the remote host logs to determine exactly why they're closing the connection