ASP.NET Sharepoint CSOM error: An existing connection was forcibly closed by the remote host - asp.net

I have an ASP.NET application running under .NET Framework 4.7.2.
In my application I am trying to connect to my Sharepoint site to create or rename folders.
Unfortunately I am getting below error.
I've been searching around on the internet and found a lot of articles talking about TLS but my application has TLS 1.2 by default due to the .NET Framework 4.7.2.
Does anyone would know the reason/background of the error?
(I don't have the error on my local machine (no SSL), error only occurs after deploying to my hosting environment with SSL)
This is the full error message:
Server Error in '/' Application.
An existing connection was forcibly closed by the remote host
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: An existing connection was forcibly closed by the remote host
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +106
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +130
[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +291
System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) +32
System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +156
System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +281
System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +49
System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +162
System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +542
System.Net.TlsStream.CallProcessAuthentication(Object state) +42
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +228
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +21
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +64
System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) +778
System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) +52
System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) +103
System.Net.ConnectStream.WriteHeaders(Boolean async) +388
[WebException: The underlying connection was closed: An unexpected error occurred on a send.]
System.Net.HttpWebRequest.GetResponse() +1399
Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() +37
Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate() +514
Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest() +126
Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() +44
Axius.Presentation.Website.frmAdminProjectDossierDetail.chkDossierSharepoint_CheckedChanged(Object sender, EventArgs e) in C:\inetpub\wwwroot\Axius.Presentation.Website\frmAdminProjectDossierDetail.aspx.cs:3637
System.Web.UI.WebControls.CheckBox.OnCheckedChanged(EventArgs e) +116
System.Web.UI.WebControls.CheckBox.RaisePostDataChangedEvent() +139
System.Web.UI.WebControls.CheckBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +12
System.Web.UI.Page.RaiseChangedEvents() +132
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1559
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3930.0
And this is the code:
using (ClientContext context = new ClientContext("https://mysite.sharepoint.com/"))
{
var passWord = new SecureString();
foreach (char c in "XXXXXXXXXX".ToCharArray()) passWord.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials("my#account.com", passWord);
List oList = context.Web.Lists.GetByTitle(#"Gedeelde documenten");
FolderCollection folders = oList.RootFolder.Folders;
context.Load(folders);
context.ExecuteQuery(); //this is frmAdminProjectDossierDetail.aspx.cs:3637 visible in the error
foreach (Folder folderr in folders)
{
if (folderr.Name == "01 PROJECTEN DOCS")
{
//code continues
}
}
}

There are at least two parts of a TLS connection: version and ciphersuites. You need to check the ciphers you have on your local machine:
https://learn.microsoft.com/en-us/powershell/module/tls/get-tlsciphersuite?view=windowsserver2022-ps
Then you should check the ciphers that are available on the sharepoint site:
https://www.ssllabs.com/ssltest/
At least one of the ciphers must match in order to complete the connection.

Related

Calling an endpoint using HttpClient using Https works on one machine but not another

The code below is used in a traditional asp.net web page monolith app to call a handful of microservices hosted in an amazon ec2 instance. While developing the new services, the calls were made using http. This was prior to security hardening. Now, we are calling the remote webservices using https.
Https, works on my local machine, however, when deployed to IIS on a remote DEV server, the following errors are being returned.
Dim url = "https://microservice/api/someroute"
Dim client As New HttpClient
client.DefaultRequestHeaders.Add("ClientKey", clientKey)
client.DefaultRequestHeaders.Add("Bearer", AuthenticationJwt)
client.DefaultRequestHeaders.Add("TrackingId", trackingId)
'.Result is used because the asp.net web page lifecycle is synchronous
' and in some cases, the lifecycle has completed and there is no thread to come back to
Dim response = client.GetAsync(url).Result
Changed to using HTTPS first exception:
An error occurred while sending the request. at
System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterface
SecModule, String package, CredentialUse intent, SecureCredential scc)
at
System.Net.Security.SecureChannel.AcquireCredentialsHandle(CredentialUse
credUsage, SecureCredential& secureCredential) at
System.Net.Security.SecureChannel.AcquireCredentialsHandle(CredentialUse
credUsage, X509Certificate2 selectedCert, Flags flags) at
System.Net.Security.SecureChannel.AcquireClientCredentials(Byte[]&
thumbPrint) at
System.Net.Security.SecureChannel.GenerateToken(Byte[] input, Int32
offset, Int32 count, Byte[]& output) at
System.Net.Security.SecureChannel.NextMessage(Byte[] incoming, Int32
offset, Int32 count) at
System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32
count, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst,
Byte[] buffer, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult
lazyResult) at
System.Net.TlsStream.CallProcessAuthentication(Object state) 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.BeginWrite(Byte[] buffer, Int32 offset, Int32
size, AsyncCallback asyncCallback, Object asyncState) at
System.Net.TlsStream.UnsafeBeginWrite(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback asyncCallback, Object asyncState) at
System.Net.PooledStream.UnsafeBeginWrite(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state) at
System.Net.ConnectStream.WriteHeaders(Boolean async)
Added the following code:
System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Exception changed to:
An error occurred while sending the request.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)

The client and server cannot communicate, because they do not possess a common algorithm Azure Storage

For the past month I've been running a web app in azure using ASP.NET MVC (.NET 4.6).
It's all been working fine until now however all the sudden I see the following exception being thrown constantly:
Microsoft.WindowsAzure.Storage.StorageException: The underlying
connection was closed: An unexpected error occurred on a receive. --->
System.Net.WebException: The underlying connection was closed: An
unexpected error occurred on a receive. --->
System.ComponentModel.Win32Exception: The client and server cannot
communicate, because they do not possess a common algorithm at
System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterface
SecModule, String package, CredentialUse intent, SecureCredential scc)
at
System.Net.Security.SecureChannel.AcquireCredentialsHandle(CredentialUse
credUsage, SecureCredential& secureCredential) at
System.Net.Security.SecureChannel.AcquireClientCredentials(Byte[]&
thumbPrint) at
System.Net.Security.SecureChannel.GenerateToken(Byte[] input, Int32
offset, Int32 count, Byte[]& output) at
System.Net.Security.SecureChannel.NextMessage(Byte[] incoming, Int32
offset, Int32 count) at
System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32
count, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst,
Byte[] buffer, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult
lazyResult) at
System.Net.TlsStream.CallProcessAuthentication(Object state) 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
Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand1
cmd, IRetryPolicy policy, OperationContext operationContext) in
c:\Program Files
(x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line
695 --- End of inner exception stack trace --- at
Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand1
cmd, IRetryPolicy policy, OperationContext operationContext) in
c:\Program Files
(x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line
604 at
Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.Exists(Boolean
primaryOnly, BlobRequestOptions requestOptions, OperationContext
operationContext) in c:\Program Files
(x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlobContainer.cs:line
1406 at BoligsideUtility.ImageService.GetBlockBlob(String
containerName, String blobName) in
C:\Users\NM\Dropbox\Projects\Boligside\BoligsideUtility\ImageService.cs:line
59 at BoligsideUtility.ImageService.GetImageUrl(ResImage img) in
C:\Users\NM\Dropbox\Projects\Boligside\BoligsideUtility\ImageService.cs:line
71 at Boligside.ViewModels.ResImageVm..ctor(ResImage image) in
C:\Users\NM\Dropbox\Projects\Boligside\Boligside\ViewModels\ImageViewModels.cs:line
22 at Boligside.ViewModels.ReviewVm..ctor(Review r) in
C:\Users\NM\Dropbox\Projects\Boligside\Boligside\ViewModels\ReviewVms.cs:line
74 at Boligside.ViewModels.HomeVm.<>c.<.ctor>b__21_2(Review x) in
C:\Users\NM\Dropbox\Projects\Boligside\Boligside\ViewModels\HomeViewModel.cs:line
35 at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at
Boligside.ViewModels.HomeVm..ctor(RealestateSiteDbContext context) in
C:\Users\NM\Dropbox\Projects\Boligside\Boligside\ViewModels\HomeViewModel.cs:line
35 at Boligside.Controllers.HomeController.Index() in
C:\Users\NM\Dropbox\Projects\Boligside\Boligside\Controllers\HomeController.cs:line
129 at lambda_method(Closure , ControllerBase , Object[] ) at
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase
controller, Object[] parameters) at
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext
controllerContext, IDictionary2 parameters) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
controllerContext, ActionDescriptor actionDescriptor, IDictionary2
parameters) at
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult
asyncResult, ActionInvocation innerInvokeState) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult2.CallEndDelegate(IAsyncResult
asyncResult) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End()
at
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult
asyncResult) at
System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d()
at
System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.b__3f()
at
System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.b__32(IAsyncResult asyncResult) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallEndDelegate(IAsyncResult
asyncResult) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End()
at
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult
asyncResult) at
System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.b__1c()
at
System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__1e(IAsyncResult
asyncResult)
The line where the exception happens is this one:
CloudBlobContainer container = BlobClient.GetContainerReference(containerName);
In this line I essentially call the azure blob API to get the container reference of the corresponding container name.
The strange thing is; I published my project again and the error disappeared.
However, the next day (today) the error reappeared.

ASP web reference intermittently throwing 'an existing connection was forcibly closed by the remote host' exception

I have a ASP.NET (VB.NET) web application (targeting .NET 4 Framework) which throws an exception intermittently when trying to invoke a web method via web reference. The web reference is the old school ASP.NET web services with the .asmx file extension.
The main web application and the web service are both on IIS 7.5 / Windows 2008 SP1. In IIS both apps are on the same website but in different application pools.
The exception states "An existing connection was forcibly closed by the remote host". This error is strange because it doesn't throw the exception the first several times when the web method is called. But when the error is thrown, it will then continue to be thrown on every following instance. Restarting the app pool in IIS fixes the error.
The data being transmitted is minimal so I don't think it is related the size of the data.
Recently we installed an F5 device that acts as a reverse proxy. The web service is now running behind this device. We did this in order to move the application to a DMZ (Demilitarized Zone). This could be the cause to this issue but if it is I am unsure how to properly configure it.
Here is my code:
_webService = New BWebService.BWebService()
_webService.Url = EnvironmentSettingsLocator.Settings.BWebServiceWsdl
If Not _webService.IsExistingUser(userId) Then
' Do Something
end if
Here is the exception:
The underlying connection was closed: An unexpected error occurred on a receive.
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Apex3Web.BIRVWebService.BIRVWebService.IsExistingUser(Int32 userCode) in C:\Users\Ryan.DeFour.ctr\Documents\Work\TFS Source Code 2010\APEX4CMMI\APEXDevelopment\Apex3Web\Apex3Web\Web References\BIRVWebService\Reference.vb:line 501
at Apex3Web.ManageExaminee.GridViewExaminees_RowDataBound(Object sender, GridViewRowEventArgs e) in C:\Users\Ryan.DeFour.ctr\Documents\Work\TFS Source Code 2010\APEX4CMMI\APEXDevelopment\Apex3Web\Apex3Web\Forms\Examiner\ManageExaminee.aspx.vb:line 651
at System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.GridView.DataBind()
at Apex3Web.ManageExaminee.FindCommand_Click(Object sender, EventArgs e) in C:\Users\Ryan.DeFour.ctr\Documents\Work\TFS Source Code 2010\APEX4CMMI\APEXDevelopment\Apex3Web\Apex3Web\Forms\Examiner\ManageExaminee.aspx.vb:line 539
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
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._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.TlsStream.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)
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)
The source of our issue was the newly installed F5 BigIP reverse proxy device which had SSL load balancing capabilities. The application threw exceptions during invocations to SOAP-based services (both WCF and ASMX). While speaking to an F5 representative, we were able to properly configure the device so requests would simply pass through the device instead of using the load balancing functions. This was probably not the most elegant solution, but in interest of time this is what we had to do to make it happen.

SMTP SocketException (0x2745) Error (ASP.NET)

I have a mail send script which is used to send out confirmations to users and staff when registrations occur etc. Of recent it seems we have been experiencing issues with the mail sending get very intermittent sends, and mainly erroring.
I've been working with the hoster to no avail. The exception is as follows:
[SocketException (0x2745): An established connection was aborted by the software in your host machine]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +6528783
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +130
[IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +296
System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count) +45
System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count) +106
System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) +203
System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) +16
System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) +54
System.Net.Mail.DataStopCommand.Send(SmtpConnection conn) +28
System.Net.Mail.SmtpConnection.OnClose(Object sender, EventArgs args) +8
System.Net.ClosableStream.Close() +54
System.Net.Mail.MailWriter.Close() +65
System.Net.Mail.SmtpClient.Send(MailMessage message) +1433
Now I have tried different authenticated users, different email contents and the common theme seems to be email with an attachment or emails with an HTML body seem prone to failure. My view is firmly that the mail server is the party that is disconnecting the request.
For reference I'm using asp.net 4.0 with a very standard set of code.
My hoster seems unable to locate or even resolve the issue.

An error occurred while receiving the HTTP response to <My wcf service deployed at IIS>

When I try to invoke my web service which is on a different server(Production) from asp.net server side web page, it gets executed without any exception sometimes and sometimes I get this exception mentioned in title. I have used wshttpbinding. I am also posting the complete stack trace. But the last inner exception says :
Unable to read data from the transport
connection: An existing connection was
forcibly closed by the remote host.
Based on my search, somewhere it says its due to wrong binding , somewhere its written IIS permissions are blocking , and also small time out limits. I have increased the time out but have not altered bindings and IIS account because I believe had that been the problem it would not have executed successfully even once. The behavior is highly sporadic with 50% success rate. And also some users have reported this issue with normal asp.net calls also where no wcf is involved.
This webservice call does not takes any parameters and does not return any data either. (FireAndForget kind of scenerio).
Exception Message:
An error occurred while receiving the
HTTP response to
https://json.clickable.com/BMS/NetSuiteCommunicationService.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.
Stack Trace:
Server stack trace: at
System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException
webException, HttpWebRequest request,
HttpAbortReason abortReason) at
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
timeout) at
System.ServiceModel.Channels.RequestChannel.Request(Message
message, TimeSpan timeout) at
System.ServiceModel.Channels.ClientReliableChannelBinder1.RequestClientReliableChannelBinder1.OnRequest(TRequestChannel
channel, Message message, TimeSpan
timeout, MaskingMode maskingMode) at
System.ServiceModel.Channels.ClientReliableChannelBinder1.Request(Message
message, TimeSpan timeout, MaskingMode
maskingMode) at
System.ServiceModel.Channels.ClientReliableChannelBinder1.Request(Message
message, TimeSpan timeout) at
System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message
message, TimeSpan timeout) at
System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message
message, TimeSpan timeout) at
System.ServiceModel.Channels.ServiceChannel.Call(String
action, Boolean oneway,
ProxyOperationRuntime operation,
Object[] ins, Object[] outs, TimeSpan
timeout) at
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime
operation) at
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message)
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
Clickable.Scheduler.BLL.NetsuiteService.INetSuiteCommunicationService.ExecuteAddAdNetworkToCustomerTask()
at
Clickable.Scheduler.BLL.Configuration.Tasks.AdNetworkToCustomerTask.Run()
at
Clickable.Scheduler.BLL.Configuration.Tasks.Task.Excecute()
Exception Message: The underlying
connection was closed: An unexpected
error occurred on a receive.
Stack Trace: at
System.Net.HttpWebRequest.GetResponse()
at
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
timeout)
Exception Message: Unable to read data
from the transport connection: An
existing connection was forcibly
closed by the remote host.
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._SslStream.StartFrameHeader(Byte[]
buffer, Int32 offset, Int32 count,
AsyncProtocolRequest asyncRequest)
at
System.Net.Security._SslStream.StartReading(Byte[]
buffer, Int32 offset, Int32 count,
AsyncProtocolRequest asyncRequest)
at
System.Net.Security._SslStream.ProcessRead(Byte[]
buffer, Int32 offset, Int32 count,
AsyncProtocolRequest asyncRequest)
at System.Net.TlsStream.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)
Exception Message: An existing
connection was forcibly closed by the
remote host
Stack Trace: at
System.Net.Sockets.NetworkStream.Read(Byte[]
buffer, Int32 offset, Int32 size)
I know this is old but for someone finding this : I had the same Exception . I figured out the error by defining a trace in web.config
<system.diagnostics>
<sources>
<source propagateActivity="true" name="System.ServiceModel" switchValue="Information, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add initializeData="C:/temp/tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="traceListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
</system.diagnostics>
I ran the website locally, fired a few failing calls and the opened the tracelog selecting the failed entry, inside that entry I saw this exception :
The entity or complex type 'Person' cannot be constructed in a LINQ to Entities query.
Constructing the person outside of the query fixed the issue so instead of :
var persons = (from p in db.Persons
select new Person
{
Id = p.Id,
Name = p.Name,
LastName = p.LastName,
Email = p.Email
}
).AsEnumerable();
return persons;
I had to do :
var persons = (from p in db.Persons
select new
{
Id = p.Id,
Name = p.Name,
LastName = p.LastName,
Email = p.Email
}
).AsEnumerable()
//construct the complex type outside of DB (to prevent the exception that model cannot be constructed in linq to entities)
.Select(item =>
new Person
{
Id = item.Id,
Name = item.Name,
LastName = item.LastName,
Email = item.Email
}).ToList();
return persons;

Resources