# OPC UA Method call hangs

**URL:** <https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [March 30, 2023, 2:52pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836 "2023-03-30T14:52:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [March 30, 2023, 2:52pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/1 "2023-03-30T14:52:42Z")

</div>

Hi all,  
I'm trying to call an OPC Method with the `system.opcua.callMethod`. My network configuration is as follows:

- PC1 with Ignition Designer and OPC UA Expert Client
- PC2 with Ignition Gateway
- PC3 with the OPC UA Server

I can call the OPC UA Method on PC3 from _OPC UA Expert Client_ on PC1, whereas the Ignition Python function where I've programmed the `callMethod` cannot. The Python function is called by a `ValueChanged` event on an Ignition Gateway Tag, so that `callMethod` runs on the Gateway as required by the function scope spec:

```auto
def getZ020WS(jsonInput):
	logger.info('>>>>>>> %s' % jsonInput)
	res=system.opcua.callMethod(
			 connectionName="OpcRouter"
			,objectId= "ns=2;s=MyResources"
			,methodId= "ns=2;s=MyResources.getZ020WS"
			,inputs=[jsonInput])
	logger.info('>>>>>>> CALL END %s' % res)

```

Reading through the wrapper.log I don't find any exception logged. Moreover the first log entry before the `callMethod` is there, whereas the second one where I try to log the `callMethod` result is not.  
If I run the same function on a PC which is running all the system components (Ignition, OPC Server, Desginer, OPC UA Client), it works perfectly.  
Any suggestion? I don't think it's a matter of firewalls, becuase _OPC UA Expert Client_ manages to do the call.

Thanks in davance, regards

Ignition version: 8.1.25 (b2023021409)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2023, 2:56pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/2 "2023-03-30T14:56:14Z")

</div>

How long does it hang? Can you get a thread dump while it's hung? Can you get a Wireshark capture, made on either PC2 or PC3, with security for the connection turned off?

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [March 30, 2023, 3:26pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/3 "2023-03-30T15:26:08Z")

</div>

> [@Kevin.Herron](#):
>
> How long does it hang?

Hi Kevin, thanks for your reply. It hangs indefinitely, i.e. I never see the `>>>>>> CALL END` log entry.  
One more note: If I try to write a value from the tag browser directly into a tag in the OPC UA Address space, that's no problem: the tag new value is written correctly and I see the new value in the _OPC UA Expert Client_.  
I've given a try also to next code, which I took from Ignition help:

```auto
result = system.opcua.callMethod(
        "Ignition OPC UA Server",
        "ns=0;i=2253",
        "ns=0;i=11492",
        [1]
    )

```

but behavior is just the same: the code never arrives at the `>>>>> CALL END` log entry. I'm sure I'm doing something wrong, but I don't know where.  
I will speak with the customer to see if I may capture Ethernet traffic with Wireshark and I will be back to you.  
Thanks, regards

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2023, 3:29pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/4 "2023-03-30T15:29:09Z")

</div>

`callMethod` will throw an Exception if the call times out (or in some other error scenarios), which it should after ~60sec or whatever the request timeout on the connection is configured for. You won't see your final logging statement when this happens.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2023, 3:30pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/5 "2023-03-30T15:30:36Z")

</div>

You might also get a little more info in the logs by setting the logger `opcua.gateway.scripting.CallMethod` to DEBUG level.

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [March 30, 2023, 4:29pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/6 "2023-03-30T16:29:10Z")

</div>

I @Kevin.Herron , just set the logger to `DEBUG` but got no further information. I've installed _MS Network Monitor_ and saw that when _OPC UA Expert_ calls the method, the monitor shows meaningful records (attached)  
[OPCUaExpertTraffic.cap](https://forum.inductiveautomation.com/uploads/short-url/qt387vnPGL0IRQrcCuEWka4zHQT.cap) (7.1 KB)  
Whereas nothing interesting appears when the call should come from Ignition, as if the call does not get out of Ignition. Maybe I'm wrong in the _OPC UA Server_ connection configuration - e.g. I had to uncheck the _Certificate Validation Enabled_ property to get the connection UP and running.  
If you have further ideas, I thank you.  
Regards

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2023, 4:31pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/7 "2023-03-30T16:31:07Z")

</div>

Are you sure you've got the correct connection name? Is the status of that connection good/connected?

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [March 30, 2023, 4:36pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/8 "2023-03-30T16:36:09Z")

</div>

> [@Kevin.Herron](#):
>
> correct connection name?

I think so:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/d/3ddb2e7bf6105875da30c9f5c5a011f0444af113.png)  
On the left you see the name of the _OPC Connection_ as shown in the gateweay configuration and on the right my function call. The OPC Connection shows up as _Connected_, provided that I uncheck the _Certificate Validation_ option.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2023, 4:37pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/9 "2023-03-30T16:37:16Z")

</div>

I don't know, there's something suspect going on if you can't even get any log entries from that logger.

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [March 30, 2023, 4:39pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/10 "2023-03-30T16:39:27Z")

</div>

You are right, but why this piece of code does nothing either:

```auto
result = system.opcua.callMethod(
        "Ignition OPC UA Server",
        "ns=0;i=2253",
        "ns=0;i=11492",
        [1]
    )

```

Not sure, but I think it should work as is, with no further configuration, shouldn't it?

---

<div class="post-metadata">

**Author:** ![avaughn](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/avaughn/32/38972_2.png) [@avaughn](https://forum.inductiveautomation.com/u/avaughn)\
**Post date:** [March 30, 2023, 4:41pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/11 "2023-03-30T16:41:37Z")

</div>

Do you have a logger object created with `system.util.getLogger()` before you try to use `logger.info()` on line 7?

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [March 30, 2023, 4:42pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/12 "2023-03-30T16:42:25Z")

</div>

> [@avaughn](#):
>
> Do you have a logger object

Yes of course, and I see it works in the wrapper.log

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2023, 4:42pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/13 "2023-03-30T16:42:47Z")

</div>

I put this into a tag event script:

```auto
	print "calling method..."
	
	result = system.opcua.callMethod(
        "Ignition OPC UA Server",
        "ns=0;i=2253",
        "ns=0;i=11492",
        [1]
    )
    
	print result

```

and in my (wrapper) logs I get:

```auto
calling method...
((2150105088L, u'Bad_SubscriptionIdInvalid', u'The subscription id is not valid.'), [], [])

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2023, 4:43pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/14 "2023-03-30T16:43:55Z")

</div>

You seem to be writing code in a project script module - is that project set as the Gateway Scripting Project?

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [March 30, 2023, 4:46pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/15 "2023-03-30T16:46:22Z")

</div>

... just what I'd like to see. As I told you, I put a test PC together, where Ignition and the OPC UA Server were on the same PC: my code worked like a charm and I got the answer you pointed to and the answer from my `getZ020WS` OPC UA Method too. On the contrary the customer's distributed configuration does not work

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [March 30, 2023, 4:47pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/16 "2023-03-30T16:47:29Z")

</div>

> [@Kevin.Herron](#):
>
> is that project set as the Gateway Scripting Project

Yes, other wise I would get no log at all, neither the very first entry `>>>>>>> ....`

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2023, 4:49pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/17 "2023-03-30T16:49:11Z")

</div>

Try wrapping the whole thing in [try/catch](https://forum.inductiveautomation.com/t/catch-ioexception/18612/3) and logging any exceptions that get caught.

Also get a thread dump from the gateway after you've made the call, we'll be able to see if it's actually hanging or not.

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [March 30, 2023, 4:52pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/18 "2023-03-30T16:52:47Z")

</div>

> [@Kevin.Herron](#):
>
> Try wrapping the whole thing in [try/catch](https://forum.inductiveautomation.com/t/catch-ioexception/18612/3)

Tried already: the `catch` branch with a `print e.getCause()` doesn't seem to be executed at all.

> Also get a thread dump from the gateway

Could you guide me to get the thread dump? Thanks

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2023, 4:55pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/19 "2023-03-30T16:55:17Z")

</div>

They can be downloaded from the threads diagnostics page in the gateway.

[https://docs.inductiveautomation.com/display/DOC81/Diagnostics+-+Threads#DiagnosticsThreads-IndividualThreads](https://docs.inductiveautomation.com/display/DOC81/Diagnostics+-+Threads#DiagnosticsThreads-IndividualThreads)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2023, 5:01pm UTC](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836/20 "2023-03-30T17:01:15Z")

</div>

Oh, another thing I should have caught earlier... `callMethod` doesn't take keyword-args like you're trying to call it with. You should be seeing a big ol' error in the logs about this...

[Next page](https://forum.inductiveautomation.com/t/opc-ua-method-call-hangs/71836.md?page=2)
