1

I am using a C# Web API to integrate between power automate and AX 2012 . I get this temporary error every 1st time of flow run in a while.

    {
  "className": "xxx",
  "methodName": "xxx",
  "status": "Error",
  "userName": "xxx",
  "aifURL": "xxx",
  "data": null,
  "error": {
    "ClassName": "System.ServiceModel.CommunicationException",
    "Message": "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:09:59.9843888'.",
    "Data": {},
    "InnerException": {
      "ClassName": "System.IO.IOException",
      "Message": "The read operation failed, see inner exception.",
      "Data": {},
      "InnerException": {
        "ClassName": "System.ServiceModel.CommunicationException",
        "Message": "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:09:59.9843888'.",
        "Data": {},
        "InnerException": {
          "NativeErrorCode": 10054,
          "ClassName": "System.Net.Sockets.SocketException",
          "Message": "An existing connection was forcibly closed by the remote host",
          "Data": {},
          "InnerException": null,
          "HelpURL": null,
          "StackTraceString": "   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)\r\n   at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)",
          "RemoteStackTraceString": null,
          "RemoteStackIndex": 0,
          "ExceptionMethod": "8\nReceive\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.Sockets.Socket\nInt32 Receive(Byte[], Int32, Int32, System.Net.Sockets.SocketFlags)",
          "HResult": -2147467259,
          "Source": "System",
          "WatsonBuckets": null
        },
        "HelpURL": null,
        "StackTraceString": "   at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)\r\n   at System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)\r\n   at System.ServiceModel.Channels.ConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count)\r\n   at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)\r\n   at System.Net.Security.NegotiateStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.NegotiateStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)",
        "RemoteStackTraceString": null,
        "RemoteStackIndex": 0,
        "ExceptionMethod": "8\nReadCore\nSystem.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.ServiceModel.Channels.SocketConnection\nInt32 ReadCore(Byte[], Int32, Int32, System.TimeSpan, Boolean)",
        "HResult": -2146233087,
        "Source": "System.ServiceModel",
        "WatsonBuckets": null
      },
      "HelpURL": null,
      "StackTraceString": "   at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.NegotiateStream.Read(Byte[] buffer, Int32 offset, Int32 count)\r\n   at System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)",
      "RemoteStackTraceString": null,
      "RemoteStackIndex": 0,
      "ExceptionMethod": "8\nProcessRead\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.Security.NegotiateStream\nInt32 ProcessRead(Byte[], Int32, Int32, System.Net.AsyncProtocolRequest)",
      "HResult": -2146232800,
      "Source": "System",
      "WatsonBuckets": null
    },
    "HelpURL": null,
    "StackTraceString": "   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n   at SXA_FlowIntegrationWebAPI.AX2012.SXAFlowIntegrationService.callMethod(SXAFlowIntegrationServiceCallMethodRequest request)\r\n   at SXA_FlowIntegrationWebAPI.AX2012.SXAFlowIntegrationServiceClient.callMethod(CallContext CallContext, String _className, String _methodName, String _data)\r\n   at SXA_FlowIntegrationWebAPI.Controllers.MainController.CallMethod(ClassMethodCallRequest request)",
    "RemoteStackTraceString": "\r\nServer stack trace: \r\n   at System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)\r\n   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)\r\n   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)\r\n   at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)\r\n   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)\r\n   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)\r\n   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)\r\n   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)\r\n   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)\r\n   at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)\r\n   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)\r\n   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)\r\n   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)\r\n\r\nException rethrown at [0]: \r\n",
    "RemoteStackIndex": 1,
    "ExceptionMethod": "8\nHandleReturnMessage\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Runtime.Remoting.Proxies.RealProxy\nVoid HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)",
    "HResult": -2146233087,
    "Source": "mscorlib",
    "WatsonBuckets": null
  }
}

Below is the C# code for the controller

public class MainController : ApiController
    {
        [ActionName("Method")]
        [HttpPost]
        [Authorize]
        public IHttpActionResult CallMethod(ClassMethodCallRequest request)
        {
            dynamic retValue;
            bool success = false;
            AX2012.SXAFlowIntegrationServiceClient client = null;        

            try
            {
                client = new AX2012.SXAFlowIntegrationServiceClient();

                var callContext = new AX2012.CallContext();
                callContext.Company = request.companyId;
                callContext.LogonAsUser = User.Identity.Name;

                client.InnerChannel.OperationTimeout = new TimeSpan(0, 10, 00);
                client.Endpoint.Address = new System.ServiceModel.EndpointAddress(request.aifURL);

                retValue = client.callMethod(callContext, request.className, request.methodName, request.dataJsonStr);
                client.Close();
                success = true;

            }
            catch (Exception e)
            {
                return Json(new ClassMethodCallResponse
                {
                    status = "Error",
                    userName = User.Identity.Name,
                    className = request.className,
                    methodName = request.methodName,
                    aifURL = request.aifURL,
                    error = e
                });
            }
            finally
            {
                if (!success)
                {
                    client.Abort();
                }
            }
            
            return Json(new ClassMethodCallResponse
            {
                status = "Success",
                userName = User.Identity.Name,
                className = request.className,
                methodName = request.methodName,
                aifURL = request.aifURL,
                data = retValue,
            });
        }

    }

This issue forces to resubmit a long process. The error is not popped for 2nd time onwards run but again if I run the flow after a while, the error is thrown again.

Is the error related to timeout? I am not getting the root cause for this error.

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • From the exception message part `Local socket timeout was '00:09:59.9843888'` and your `OperationTimeout = new TimeSpan(0, 10, 0)`, I assume the operation takes more than 10min. The second call afterwards works because the callee may have some data already loaded in to memory/cached somewhere. – G Wimpassinger Dec 23 '20 at 16:54
  • No.. The operation actually takes only few seconds. One process takes longer time for which I increased the time out. But usually the 1st process is of only few seconds. – Dhruvil Sheth Dec 23 '20 at 16:58
  • @DhruvilSheth What you're saying doesn't appear to comport with the error message though? So either you or the message is wrong, wouldn't you think? Do some debugging statements in your code to output what step in the process it's at and/or check the AX exception table via `SystemAdministration\Periodic\Services and Application Integration Framework\Exceptions`. It looks like either a communication or timeout issue. Possibly there's a user-interaction step (i.e. popup box "Are you sure?") that you're not seeing that may be locking the whole process. – Alex Kwitny Dec 28 '20 at 17:01
  • @AlexKwitny We are seeing what looks like the same error message, mentioning a timeout of 5 minutes (coinciding with the `SendTimeout` of our service), but the error comes only 1 or 2 seconds after making the call. So the error message is not very helpful. – Evgeniy Berezovsky Mar 09 '21 at 00:14
  • @DhruvilSheth Could you resolve this? We have been getting the same error a couple of times today for a net.tcp service, and I assume it depends on the data that was sent, despite the error message. Have a look at this answer https://stackoverflow.com/a/17983639 for more ideas - unfortunately it did not help in our case. – Evgeniy Berezovsky Mar 09 '21 at 00:16
  • @GWimpassinger I would say the operation was aborted after OperationTimeout - 00:09:59.9843888, in other words, some 15 milliseconds. I can replicate this when setting MaxBufferSize to a very low value. Above error will come immediately, and with a value some milliseconds less than (in my case) SendTimeout. – Evgeniy Berezovsky Mar 09 '21 at 00:27
  • @EvgeniyBerezovsky 15 milliseconds? The timeout is `client.InnerChannel.OperationTimeout = new TimeSpan(0, 10, 00);` which I think is 10 minutes. – Alex Kwitny Mar 09 '21 at 19:49
  • @AlexKwitny Take a look at the timestamp in the OP's error message: `00:09:59.9843888`. That plus 15 milliseconds equals the 10 minute OperationTimeout. – Evgeniy Berezovsky Mar 10 '21 at 07:03
  • I resolved it by using try in while loop by setting retry count of 1. I usually got this error every 1st time in a while.. Maybe when process is ran for 1st time in 10-15-20 mins ( don't know exact time) then this issue occured. So I used retry to try again if the system throws socket error – Dhruvil Sheth Mar 11 '21 at 08:19

0 Answers0