question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Timeout occurred while processing the request." on Method Call request

See original GitHub issue

While trying to call a method on an OPC server with a custom type I always receive a “Timeout occurred while processing the request.” error. Below is the code for the request, it follows the logic you used for the method call in the IntegrationTests class.

  protected override async Task ExecuteAsync(CancellationToken stoppingToken)
   { 

            // describe this client application.
            var clientDescription = new ApplicationDescription
            {
                ApplicationName = "Workstation.UaClient.FeatureTests",
                ApplicationUri = $"urn:{System.Net.Dns.GetHostName()}:Workstation.UaClient.FeatureTests",
                ApplicationType = ApplicationType.Client
            };

            var channel = new UaTcpSessionChannel(
              this.localDescription,
              null,
              new AnonymousIdentity(),
             "opc.tcp://192.168.0.254:4840",
              SecurityPolicyUris.None,
              loggerFactory: this.loggerFactory,
              additionalTypes: new[] { typeof(ScanSettings) });
            try
            {
                // try opening a session and reading a few nodes.
                await channel.OpenAsync();

                Console.WriteLine($"Opened session with endpoint '{channel.RemoteEndpoint.EndpointUrl}'.");
                Console.WriteLine($"SecurityPolicy: '{channel.RemoteEndpoint.SecurityPolicyUri}'.");
                Console.WriteLine($"SecurityMode: '{channel.RemoteEndpoint.SecurityMode}'.");
                Console.WriteLine($"UserIdentityToken: '{channel.UserIdentity}'.");
                var readRequest = new ReadRequest { NodesToRead = new[] { new ReadValueId { NodeId = NodeId.Parse("ns=4;i=6030"), AttributeId = AttributeIds.Value } } };
                var readResult = await channel.ReadAsync(readRequest);
                var serverStatus = readResult.Results[0].GetValueOrDefault<ServerStatusDataType>();

                var set = new ScanSettings
                {
                    Duration = 500,
                    Cycles = 10
                };
                var request = new CallRequest
                {
                    MethodsToCall = new[] {
                        new CallMethodRequest
                        {
                            ObjectId =  NodeId.Parse("ns=2;i=5001"),
                            MethodId =  NodeId.Parse("ns=4;i=7010"),
                            InputArguments = new [] { new ExtensionObject(set)}.ToVariantArray()
                        }
                    }
                };
 
                var response = await channel.CallAsync(request);
                var result = response.Results[0].OutputArguments[0].GetValueOrDefault<ScanSettings>();

                Console.WriteLine($"\nClosing session '{channel.SessionId}'.");
                await channel.CloseAsync();
            }
            catch (Exception ex)
            {
                await channel.AbortAsync();
                Console.WriteLine(ex.Message);
            }
        }


    [DataTypeId("ns=3;i=6044")]
    [BinaryEncodingId("ns=3;i=5015")]
    internal class ScanSettings : Structure
    {
        public uint Duration { get; set; }
        public int Cycles { get; set; }
        public override void Encode(IEncoder encoder)
        {
            encoder.WriteUInt32("Duration", this.Duration);
            encoder.WriteInt32("Cycles", this.Cycles);
        }

        public override void Decode(IDecoder decoder)
        {
            this.Duration = decoder.ReadUInt32("Duration");
            this.Cycles = decoder.ReadInt32("Cycles");
        }

        public override string ToString() => $"{{ Duration={this.Duration}; Cycles={this.Cycles}; }}";
    }

Any help would be awesome. Thank you

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
awcullencommented, Sep 21, 2020

Try this out. I got the idea from https://reference.opcfoundation.org/v104/Core/docs/Part6/5.2.7/


    [DataTypeId("nsu=http://opcfoundation.org/UA/AutoID/;i=3010")]
    [BinaryEncodingId("nsu=http://opcfoundation.org/UA/AutoID/;i=5015")]
    internal class ScanSettings : Structure
    {
        public Double Duration { get; set; }
        public Int32 Cycles { get; set; }
        public Boolean DataAvailable { get; set; }
        public LocationTypeEnumeration? LocationType { get; set; }

        public override void Encode(IEncoder encoder)
        {
            UInt32 optionFlags = 0;
            if (this.LocationType.HasValue)
            {
                optionFlags |= 1;
            }
            encoder.WriteUInt32("", optionFlags);
            encoder.WriteDouble("Duration", this.Duration);
            encoder.WriteInt32("Cycles", this.Cycles);
            encoder.WriteBoolean("DataAvailable", this.DataAvailable);
            if ((optionFlags & 1) != 0)
            {
                encoder.WriteInt32("LocationType", (int)this.LocationType);
            }
        }

        public override void Decode(IDecoder decoder)
        {
            UInt32 optionFlags = decoder.ReadUInt32("");
            this.Duration = decoder.ReadDouble("Duration");
            this.Cycles = decoder.ReadInt32("Cycles");
            this.DataAvailable = decoder.ReadBoolean("DataAvailable");
            if ((optionFlags & 1) != 0)
            {
                this.LocationType = (LocationTypeEnumeration)decoder.ReadInt32("LocationType");
            } 
            else
            {
                this.LocationType = null;
            }
        }

        public override string ToString() => $"{{ Duration={this.Duration}; Cycles={this.Cycles}; DataAvailable={this.DataAvailable}; LocationType={this.LocationType};}}";
    }

    public enum LocationTypeEnumeration
    {
        NMEA = 0,
        LOCAL = 1,
        WGS84 = 2,
        NAME = 3
    }
1reaction
kaasmdfscommented, Oct 2, 2020

Thanks everyone for the help, I managed to get a solution that used a version of what Andrew showed for the Unions that solved that one issue.

   [DataTypeId("ns=3;i=6034")]
    [BinaryEncodingId("ns=3;i=5013")]
    public class Location : Union
    {
        public int? SwitchField { get; set; }
        public string NMEA { get; set; }
        public LocalCoordinate Local { get; set; }
        public WGS84Coordinate WGS84 { get; set; }
        public string Name { get; set; }

        public override void Encode(IEncoder encoder)
        {
            encoder.WriteInt32("SwitchField", this.SwitchField.Value);
        }

        public override void Decode(IDecoder decoder)
        {
            this.SwitchField = decoder.ReadInt32("SwitchField");
            switch (SwitchField)
            {
                case 0:

                    break;
                case 1:
                    this.NMEA = decoder.ReadString("NMEA");
                    break;
                case 2:
                    this.Local = decoder.ReadExtensionObject<LocalCoordinate>("Local");
                    break;
                case 3:
                    this.WGS84 = decoder.ReadExtensionObject<WGS84Coordinate>("WGS84");
                    break;
                case 4:
                    this.Name = decoder.ReadString("Name");
                    break;
                default:
                    this.SwitchField = 0;
                    break;
            }

        }

     
    }

The rest of it was solved by adding a blank ReadInt32 at the beginning of the decoding, not sure why it was needed exactly, and I also had a few properties out of order from their specification. I did not realize that the property order had to be exactly as defined in the XML.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Fix the HTTP 408 Error (8 Solutions)
The 408 Request Timeout error means the request you sent to the website server took longer than the server was prepared to wait....
Read more >
Preventing H12 Errors (Request Timeouts)
H12 Request Timeout errors occur when an HTTP request takes longer than 30 seconds to complete. These errors are often caused by:.
Read more >
Why do I receive "The operation has timed out" when it is ...
1 Answer 1 ... The Timeout value you're setting is the amount of time for the GetResponse to respond. The HttpWebRequest also has...
Read more >
Connection Timeout vs. Read Timeout for Java Sockets
When ServerSocket receives a connection request, it invokes the accept() method to instantiate a new socket object. Similarly, this method ...
Read more >
Request timed out when using DataAdapter - ASP.NET
Request timed out error when you use the DataAdapter method in an ASP. ... This error occurs when the processing time exceeds 90...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found