Dynamics CRM Cause CommunicationException - c#

I am using MS Dynamics CRM api to get data (more then 5000 records) from it.
I am using XML based query to get data
EntityCollection resultSet = _orgServiceProxy.RetrieveMultiple(new FetchExpression(query));
sometime time it works and most of the time it throws exception, from logs, I am getting this long exception.
An error occurred while receiving the HTTP response to https://orgno.api.crm.dynamics.com/XRMServices/2011/Organization.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.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to https://orgno.api.crm.dynamics.com/XRMServices/2011/Organization.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.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._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) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- End of inner exception stack trace
I don't know why this is happening?

CRM service doesn't like at all retrieve much data in one request.
I suggested you to use a paging cookie to retrieve your records by sets. It should resolve your issue and improve the performance of your code.
You can find a nice tutorial on msdn here.
Regards,
Kévin

Related

IIS Apppool dropping connection to WCF service

I'm encountering an app pool timing out on one request and it always times out around 5 minutes. I've enabled tracing, but no Warning, Error, Critical events are being logged. There are also no events in the EventViewer. I enabled FailedReqLogging and set it to log any requests over 4 minutes 30 sec. I've found the following in the C:\inetpub\logs\FailedReqLogFiles\W3SVC2 directory:
What IIS setting do I change to accomidate this request? By the Failure Reason it's listed as TIME_TAKEN so I'm guessing the AppPool exceeded some time limit. What is that limit?
I also notice that the Final Status is listed at 200. That would mean I wouldn't see anything in the logs for Warning, Critical, or Fatal because it was logged as OK. Am I right on that assumption?
Below is a stack trace of the exception found in the client trace logs. Note there is no error shown in the servers trace log. What's odd is that there is multiple nested exceptions within, but none hold real value.
...
...
<Exception>
<ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.</Message>
<StackTrace>
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.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)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at OSI.Framework.ServiceContracts.IWCFObjectDirectorWebService.Fetch(Byte[] serializedObjectRequest)
at OSI.Framework.WCF.Director.WCFWebObjectDirectorProxy.Fetch(Byte[] serializedObjectRequest)
at OSI.Framework.WCF.Director.WCFWebObjectDirector.Fetch(Object criteria)
at ActvMonitorSystemBusiness.Views.ActvView.GetActvDetails(DateTime fromDate, DateTime thruDate, String userGrpCd, String userCatCd, String userMajorCd, String userStatusCd, Nullable`1 userMemberNbr, Nullable`1 subjNbr, String searchBy, String dispActivity, Boolean showUncategorizedActv, Object[] fetchOptions)
at ActvMonitorSystemScreen.frmActvMonitor.Populate(Object sender, EventArgs e)
at ActvMonitorSystemScreen.frmActvMonitor.InitializeExtension(Object sender, EventArgs e)
at OpenSolutions.Sys.DnaExtensions.Client.SecureCoreBaseForm.Initialize(Object sender, EventArgs e)
at OSI.Base.Windows.Forms.BaseForm.OnShown(EventArgs e)
at OSI.Core.Windows.Forms.CoreBaseForm.OnShown(EventArgs e)
at ActvMonitorSystemScreen.SecureCoreBaseFormShim.OnShown(EventArgs e)
at System.Windows.Forms.Form.CallShownEvent()
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
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.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at OSI.Runtime.Program.Main(String[] args)
</StackTrace>
<ExceptionString>System.ServiceModel.CommunicationException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> 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.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)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---</ExceptionString>
<InnerException>
<ExceptionType>System.Net.WebException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.</Message>
<StackTrace>
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
</StackTrace>
<ExceptionString>System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> 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.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)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)</ExceptionString>
<InnerException>
<ExceptionType>System.IO.IOException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.</Message>
<StackTrace>
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)
</StackTrace>
<ExceptionString>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.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)</ExceptionString>
<InnerException>
<ExceptionType>System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>An existing connection was forcibly closed by the remote host</Message>
<StackTrace>
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)
</StackTrace>
<ExceptionString>System.Net.Sockets.SocketException (0x80004005): 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)</ExceptionString>
<NativeErrorCode>2746</NativeErrorCode>
This service works for other clients just fine. It's just this client that's having an issue with requests over 5 minutes. Other clients on different web servers complete the request fine.
The five minute limit doesn't sound like any of the default timeouts
so I took a look at the Advanced settings for app pools and looked for settings that default to 5 minutes and look possibly problematic. I found a couple you might try. You might want to take this approach:
In IIS Manager, go to App Pools
Find your app pool, right click, select Advanced Settings
Scan the list of settings and look for the 5 minute settings and try selectively tuning by increasing the values (strongly suggest reading and learning what each does first)
A couple of 5 minute settings that jump out at me are Limit Interval (minutes) under CPU and Failure Interval (minutes) under Rapid-Fail Protection.
Can't guarantee this will be it but unless you are manually setting a default value to 5 minutes somewhere, this is a reasonable place to start looking for a 5 minute setting. Change one setting at a time, restart the app pool, and test. Note that if you have a problem like an infinite loop in your code, obviously no timeout value is going to help :-(
Good luck.

WebException: The underlying connection was closed: An unexpected error occurred on a send

We are developing a .Net application (compiled for .net 4.0) that communicates to a soap web service.
The application has been working fine on several machines when retreiving the http web response content. However on one of the machines (Windows Server 2008 R2) the application is not able to retreive the response. This is a code example:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://200.57.3.82:3443/AdministradorQr/WebServiceDodaPort?wsdl");
request.Method = "GET";
WebResponse response;
Stream responseStream = response.GetResponseStream();
string result = string.Empty;
using (StreamReader streamReader = new StreamReader(responseStream))
{
result = streamReader.ReadToEnd();
}
The exception we get is:
The underlying connection was closed: An unexpected error occurred on a send. 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.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.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.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.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
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()
The thing is that using the same code with a different URL we get a sucessfull response, and the problem is only happening in one machine even though there is another machinge also using Windows 2008 that works just fine.
Currently we cannot upgrade .net framework to try using solutions like use of TLS 1.2 found in some places like this one: "The underlying connection was closed: An unexpected error occurred on a send." With SSL Certificate
As I mentioned, it is very strange that the same code works just fine in other machines using the same Windows/.net version and it is also strange that for other URLs like http://www.yahoo.com works fine
Not sure if it can help you but you can try adding below line in "Global.asax -> Application_Start" function. See it it works. Basically this code will force your application to use TLS1.2 only and you do not need to upgrade your framework.
"System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;"

WCF: The socket connection was aborted. A receive timeout being exceeded by the remote host

I have been working through a head-scratcher with WCF. I have a WCF Service (hosted as a Windows Service) that is called by a console application. It works great, but recently we have run into a timeout issue at 10 minutes when we had to run a query against a legacy system.
I use log4net in both the service and the client .exe, and what is strange is that the service actually completes the job and throws no exception. It runs the query (which takes about 12 minutes, and creates a file, and logs success).
The console application, however, logs an exception, claiming that the "host" returned a timeout or an error. I presume it's a timeout and not a buffer issue, because the exception always happens exactly 10 minutes to the second after the call is initially made.
Here is the exception/stack info from my log4net:
2015-07-28 17:35:47,364 [1]
System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:29:59.9843999'. ---> System.IO.IOException: The read operation failed, see inner exception. ---> System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:29:59.9843999'. ---> 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.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
at System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.ConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security.NegotiateStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
--- End of inner exception stack trace ---
at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.SessionConnectionReader.Receive(TimeSpan timeout)
at System.ServiceModel.Channels.SynchronizedMessageSource.Receive(TimeSpan timeout)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.Receive(TimeSpan timeout)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceive(TimeSpan timeout, Message& message)
at System.ServiceModel.Dispatcher.DuplexChannelBinder.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 FileGeneratorConsole.FileGeneratorServiceReference.IFileGeneratorService.GenerateXmlFileFromSql(String sqlServer, String sqlDatabase, String sqlQuery, Int32 commandTimeout, Boolean allowEmptyResult, String outputFileName, String xslFileName, Boolean archiveExistingFile)
at FileGeneratorConsole.Program.Main(String[] args)
Now, I thought I had done my research and figured out what the issue could be. I assumed it was the sendTimeout and receiveTimeout that are part of the binding definition, so I've added that:
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IFileGeneratorService"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
receiveTimeout="00:30:00"
closeTimeout="00:30:00"
openTimeout="00:30:00"
sendTimeout="00:30:00">
</binding>
</netTcpBinding>
</bindings>
And, if you notice in the exception above, you'll see that the error says:
Local socket timeout was '00:29:59.9843999'
It used to say 00:09:59.... so it looks like that took.
I also added this to the service config file, just in case the binding needed to be on both sides, but that didn't help.
Lastly, out of desperation, I added a few other things. I tried adding timeouts to the service section:
and I tried adding
to the behavior itself.
I'm at a loss now, it always dies at 10 minutes.
Thanks in advance
It's always simpler than you think.
Sadly, what was missing all this time was the bindingConfiguration reference in the service.endpoint. All this time, the service was running assumedly using the default binding definition. I had a binding defined in my config, but had missed the part where you specify:
I had:
<endpoint address="" binding="netTcpBinding" bindingConfiguration="">
I needed:
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IFileGeneratorService">
Once that was in place, my actual service endpoint was looking at the right binding properties.

Azure cache exception when storing data

currently I'm using Azure cache in my WCF application, and I got this exception when putting data into cache:
Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode< ERRCA0017 >:SubStatus< ES0006 >:There is a temporary failure. Please retry later. (One or more specified cache servers are unavailable, which could be caused by busy network or servers. For on-premises cache clusters, also verify the following conditions. Ensure that security permission has been granted for this client account, and check that the AppFabric Caching Service is allowed through the firewall on all cache hosts. Also the MaxBufferSize on the server must be greater than or equal to the serialized object size sent from the client.)
And here's the inner exception:
System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:30'. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.ServiceModel.Channels.SocketConnection.Write(Byte[] buffer, Int32 offset, Int32 size, Boolean immediate, TimeSpan timeout)
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.SocketConnection.Write(Byte[] buffer, Int32 offset, Int32 size, Boolean immediate, TimeSpan timeout)
at System.ServiceModel.Channels.SocketConnection.Write(Byte[] buffer, Int32 offset, Int32 size, Boolean immediate, TimeSpan timeout, BufferManager bufferManager)
at System.ServiceModel.Channels.BufferedConnection.WriteNow(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, BufferManager bufferManager)
at System.ServiceModel.Channels.BufferedConnection.Write(Byte[] buffer, Int32 offset, Int32 size, Boolean immediate, TimeSpan timeout, BufferManager bufferManager)
at System.ServiceModel.Channels.FramingDuplexSessionChannel.OnSend(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.OutputChannel.Send(Message message, TimeSpan timeout)
at Microsoft.ApplicationServer.Caching.CacheResolverChannel.Send(Message message, TimeSpan timeout)
at Microsoft.ApplicationServer.Caching.WcfClientChannel.SendOnChannel(EndpointID endpoint, TimeSpan& timeout, WaitCallback callback, Object state, Boolean async, IDuplexSessionChannel channel, Message message)
--- End of inner exception stack trace ---
at Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody)
at Microsoft.ApplicationServer.Caching.DataCache.ExecuteAPI(RequestBody reqMsg, IMonitoringListener listener)
at Microsoft.ApplicationServer.Caching.DataCache.InternalPut(String key, Object value, DataCacheItemVersion oldVersion, TimeSpan timeout, DataCacheTag[] tags, String region, IMonitoringListener listener)
at Microsoft.ApplicationServer.Caching.DataCache.<>c_DisplayClass19.b_18()
at Microsoft.ApplicationServer.Caching.MonitoringListenerFactory.EmptyListener.Microsoft.ApplicationServer.Caching.IMonitoringListener.Listen[TResult](Func`1 innerDelegate)
at Microsoft.ApplicationServer.Caching.DataCache.Put(String key, Object value)
The problem is this message is very general, doesn't give much details
I already tried to increase requestTimeout in dataCacheClient to 2 minutes. This doesn't solve the problem, so it should not because of connection to cache timeout
I know it's not because of amount of data too big also, because the same amount of data on production server doesn't have problem (this happens on testing server). I connect from local computer to testing database and also don't have problem
Anyone has any ideas how to solve this problem? Thanks
Below is my current configuration for Azure cache
<dataCacheClient name="default" requestTimeout="30000" isCompressionEnabled="true" >
<localCache isEnabled="true" sync="TimeoutBased" objectCount="4194304" ttlValue="80000" />
</dataCacheClient>
Please set ReceiveTimeout Property between 40-50 seconds in your code to avoid socket timeouts.
Have a retry logic in your code to retry the operation if the error suggests so.
And if this issue persists over longer period of time then take a look at the cache instance performance counters to see if you are nearing 100% limit or maxing out capacity in some sense in which case you should reassess your capacity, refer Capacity Planning Considerations for In-Role Cache (Windows Azure Cache)

System.IO.IOException: The handshake failed due to an unexpected > packet format?

Does anyone know what this means?
System.Net.WebException: The
underlying connection was closed: An
unexpected error occurred on a send.
---> System.IO.IOException: The handshake failed due to an unexpected
packet format. at
System.Net.Security.SslState.StartReadFrame(Byte[]
buffer, Int32 readBytes,
AsyncProtocolRequest asyncRequest) 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.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.runTryCode(Object
userData) at
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode
code, CleanupCode backoutCode, Object
userData) at
System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback
callback, Object state) 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
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
timeout) at
EDIT:
This is the method I was calling:
_productsService = new ProductsPortTypeClient();
_productsService.GetResortProducts(GetProductsCredentials(),
GetResortProductParams());
It looks like a problem with SSL authentication, it fails at handshake phase, maybe two implementations are not compatible, you may check the WSDL format of the response, figure out what format should be used for communication and check if the one sent by you complies with it (you may use any kind of a network monitor software, eg. Microsoft Network Monitor)
I just wanted to make an answer based on one of the comments because it can cause this error to happen.
In some cases, if you have a BaseURL while calling a API, then the problem could happen if you mixed up http and https. This happened in my case while calling a Google API. This is a simple fix in some cases and can happen to anyone.
Hope this help's someone out.
In my case it was Skype blocking 443 port. Go to Skype tools-advanced-connections and disable "Use port 80 & 443 for connections..."
summary: wrong port was used.
My service was running in development on port :58328 but next time I debugged it was running on port :44315, and this caused the issue.
So changing the port on the client side to 44315 helped to resolve the issue!

Categories

Resources